├── telegraph-meta ├── src │ └── main │ │ └── java │ │ └── org │ │ └── telegram │ │ └── telegraph │ │ ├── TelegraphConstants.java │ │ ├── api │ │ ├── objects │ │ │ ├── AccountField.java │ │ │ ├── Node.java │ │ │ ├── PageViews.java │ │ │ ├── NodeText.java │ │ │ ├── PageList.java │ │ │ ├── TelegraphResponse.java │ │ │ ├── NodeElement.java │ │ │ ├── Account.java │ │ │ └── Page.java │ │ ├── Validable.java │ │ ├── TelegraphObject.java │ │ ├── TelegraphMethod.java │ │ └── methods │ │ │ ├── RevokeAccessToken.java │ │ │ ├── GetPage.java │ │ │ ├── GetAccountInfo.java │ │ │ ├── GetPageList.java │ │ │ ├── CreateAccount.java │ │ │ ├── EditAccountInfo.java │ │ │ ├── GetViews.java │ │ │ ├── CreatePage.java │ │ │ └── EditPage.java │ │ ├── executors │ │ ├── TelegraphExecutorFactory.java │ │ └── TelegraphExecutor.java │ │ ├── jsonutilities │ │ ├── NodeTextSerializer.java │ │ └── NodeDeserializer.java │ │ ├── exceptions │ │ ├── TelegraphException.java │ │ ├── TelegraphRequestException.java │ │ └── TelegraphValidationException.java │ │ ├── TelegraphContext.java │ │ └── TelegraphLogger.java ├── telegraph-meta.iml └── pom.xml ├── telegraph ├── src │ └── main │ │ └── java │ │ └── org │ │ └── telegram │ │ └── telegraph │ │ ├── TelegraphContextInitializer.java │ │ ├── ExecutorOptions.java │ │ └── executors │ │ ├── DefaultTelegraphExecutorFactory.java │ │ └── DefaultTelegraphExecutor.java ├── telegraph.iml └── pom.xml ├── Telegraph.iml ├── .travis.yml ├── telegraph-sample ├── telegraph-sample.iml ├── src │ └── main │ │ └── java │ │ └── org │ │ └── telegram │ │ └── telegraph │ │ └── sample │ │ └── Main.java └── pom.xml ├── pom.xml ├── LICENSE ├── .gitignore ├── README.md └── Telegraph.ipr /telegraph-meta/src/main/java/org/telegram/telegraph/TelegraphConstants.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph; 2 | 3 | /** 4 | * Created by rubenlagus on 15/12/2016. 5 | */ 6 | public final class TelegraphConstants { 7 | public static final String BASE_URL = "https://api.telegra.ph/"; 8 | } 9 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/objects/AccountField.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.objects; 2 | 3 | /** 4 | * @author Ruben Bermudez 5 | * @version 1.0 6 | */ 7 | public final class AccountField { 8 | public static String SHORT_NAME = "short_name"; 9 | public static String AUTHOR_NAME = "author_name"; 10 | public static String AUTHOR_URL = "author_url"; 11 | public static String AUTH_URL = "auth_url"; 12 | public static String PAGE_COUNT = "page_count"; 13 | } 14 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/Validable.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api; 2 | 3 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 4 | 5 | /** 6 | * @author Ruben Bermudez 7 | * @version 1.0 8 | */ 9 | public interface Validable { 10 | /** 11 | * Validates that mandatory fields are filled and optional objects 12 | * @throws TelegraphValidationException If any mandatory field is invalid 13 | */ 14 | void validate() throws TelegraphValidationException; 15 | } 16 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/TelegraphObject.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Ruben Bermudez 10 | * @version 1.0 11 | * An object from the Telegraph API received from Telegraph Servers 12 | */ 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | public interface TelegraphObject extends Serializable { 16 | } 17 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/executors/TelegraphExecutorFactory.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.executors; 2 | 3 | /** 4 | * @author Ruben Bermudez 5 | * @version 1.0 6 | * Implement this factory and register it in TelegraphContext to perform a way of getting an executor that 7 | * will allow executing a telegraph method. 8 | */ 9 | public interface TelegraphExecutorFactory { 10 | /** 11 | * Return an implementation of TelegraphExecutor 12 | * @return TelegraphExecutor to execute methods 13 | */ 14 | TelegraphExecutor getExecutor(); 15 | } 16 | -------------------------------------------------------------------------------- /telegraph/src/main/java/org/telegram/telegraph/TelegraphContextInitializer.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph; 2 | 3 | import org.telegram.telegraph.executors.DefaultTelegraphExecutorFactory; 4 | import org.telegram.telegraph.executors.TelegraphExecutorFactory; 5 | 6 | /** 7 | * @author Ruben Bermudez 8 | * @version 1.0 9 | */ 10 | public final class TelegraphContextInitializer { 11 | private TelegraphContextInitializer() { 12 | } 13 | 14 | public static void init() { 15 | TelegraphContext.register(TelegraphExecutorFactory.class, DefaultTelegraphExecutorFactory.class); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/objects/Node.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.objects; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import org.telegram.telegraph.api.TelegraphObject; 5 | import org.telegram.telegraph.jsonutilities.NodeDeserializer; 6 | 7 | /** 8 | * @author Ruben Bermudez 9 | * @version 1.0 10 | * This abstract object represents a DOM Node. It can be a String which represents a DOM text node or a NodeElement object. 11 | */ 12 | @JsonDeserialize(using = NodeDeserializer.class) 13 | public abstract class Node implements TelegraphObject { 14 | } 15 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/jsonutilities/NodeTextSerializer.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.jsonutilities; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.databind.SerializerProvider; 5 | import com.fasterxml.jackson.databind.ser.std.StdSerializer; 6 | import org.telegram.telegraph.api.objects.NodeText; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author Ruben Bermudez 12 | * @version 1.0 13 | */ 14 | public class NodeTextSerializer extends StdSerializer { 15 | public NodeTextSerializer() { 16 | super(NodeText.class); 17 | } 18 | 19 | @Override 20 | public void serialize(NodeText value, JsonGenerator gen, SerializerProvider provider) throws IOException { 21 | gen.writeString(value.getContent()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/objects/PageViews.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.objects; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import org.telegram.telegraph.api.TelegraphObject; 5 | 6 | /** 7 | * @author Ruben Bermudez 8 | * @version 1.0 9 | */ 10 | public class PageViews implements TelegraphObject { 11 | private static final String VIEWS_FIELD = "views"; 12 | 13 | @JsonProperty(VIEWS_FIELD) 14 | private Integer views; ///< Number of page views for the target page. 15 | 16 | public PageViews() { 17 | } 18 | 19 | public Integer getViews() { 20 | return views; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "PageViews{" + 26 | "views=" + views + 27 | '}'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /telegraph/src/main/java/org/telegram/telegraph/ExecutorOptions.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph; 2 | 3 | import com.google.inject.Inject; 4 | import org.apache.http.client.config.RequestConfig; 5 | 6 | /** 7 | * @author Ruben Bermudez 8 | * @version 1.0 9 | */ 10 | public class ExecutorOptions { 11 | private RequestConfig requestConfig; 12 | 13 | @Inject 14 | public ExecutorOptions() { 15 | } 16 | 17 | public RequestConfig getRequestConfig() { 18 | return requestConfig; 19 | } 20 | 21 | /** 22 | * @implSpec Default implementation assumes no proxy is needed and sets a 75secs timeout 23 | * @param requestConfig Request config to be used in all Http requests 24 | */ 25 | public void setRequestConfig(RequestConfig requestConfig) { 26 | this.requestConfig = requestConfig; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/exceptions/TelegraphException.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.exceptions; 2 | 3 | /** 4 | * @author Ruben Bermudez 5 | * @version 1.0 6 | */ 7 | public abstract class TelegraphException extends Exception { 8 | public TelegraphException() { 9 | super(); 10 | } 11 | 12 | public TelegraphException(String message) { 13 | super(message); 14 | } 15 | 16 | public TelegraphException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public TelegraphException(Throwable cause) { 21 | super(cause); 22 | } 23 | 24 | protected TelegraphException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 25 | super(message, cause, enableSuppression, writableStackTrace); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Telegraph.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | install: mvn install -Dgpg.skip 5 | script: mvn clean compile test 6 | after_success: 7 | - bash <(curl -s https://codecov.io/bash) 8 | notifications: 9 | webhooks: 10 | secure: "jC7dK/x67ONWQoeLZg4HfW0mHhcjDerJjsLLkrbcpltiqAbw2p7XfY8Pk4zHoD72a+5o6WKu5WvYvZ4OdldnjP8Y6ZUbliQ5RG3olg3gFDoe0+sc3geeb4HRYVcdI20O0z4Bup/qO0ZihxPBc0D5IpHmFxlaqlZG0WeST4CicU8PNnBh6aX9/VMrwXhkMb2vfzmjmIhMbx/uK5+93bnk/vR5Uwu00/Yd2cTAAWMaqK1MRdtR0WLbxlUNsprEfCjYiH3n9XZnlKXs6cLC8EOU436Wx7aepiAszW0wWFMe/7nVqOqztrQiKNvL0qXYwlQf0BLechJdt458EopL9QCu687TNDFYvg1yERAmCRiaayYZcX3PbUSMr6H5Q+Odntjs3XKyzfgSqqlkgf/SAND5jny1/1uteVoplZmFXuZFIiK4H8Rl2ezy1/8pnbp+JD3YEfiA2NuRjlou1BZXyMhiqqVXbrJqk/tXF6yZSkDlYJfNsWzRCGfra4B6JjEvUP927chIFm1ii3dgNstXDo1evV46+OQQO4HKvMPdtU2FPvWpPlkTxnmpZRZjB+bjmybluJdWT3E+e1C3wm7YbRe3vporhpfNPlnod6M0G10y9CKzl9Fbcku6X1FtM+IoPO/aqZ8S4/CBZoYEuR/Nk6bcvsYouxtyIl6PSuF9E8YjpJE=" 11 | email: false 12 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/objects/NodeText.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.objects; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 4 | import org.telegram.telegraph.jsonutilities.NodeTextSerializer; 5 | 6 | /** 7 | * @author Ruben Bermudez 8 | * @version 1.0 9 | */ 10 | @JsonSerialize(using = NodeTextSerializer.class) 11 | public class NodeText extends Node { 12 | private String content; 13 | 14 | public NodeText(String content) { 15 | this.content = content; 16 | } 17 | 18 | public String getContent() { 19 | return content; 20 | } 21 | 22 | public NodeText setContent(String content) { 23 | this.content = content; 24 | return this; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return "NodeText{" + 30 | "content='" + content + '\'' + 31 | '}'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /telegraph/src/main/java/org/telegram/telegraph/executors/DefaultTelegraphExecutorFactory.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.executors; 2 | 3 | import com.google.inject.Inject; 4 | import org.telegram.telegraph.ExecutorOptions; 5 | 6 | /** 7 | * @author Ruben Bermudez 8 | * @version 1.0 9 | */ 10 | public class DefaultTelegraphExecutorFactory implements TelegraphExecutorFactory { 11 | private TelegraphExecutor executor; 12 | private static final Object LOCK = new Object(); 13 | 14 | @Inject 15 | public DefaultTelegraphExecutorFactory() { 16 | if (executor == null) { 17 | synchronized (LOCK) { 18 | if (executor == null) { 19 | this.executor = new DefaultTelegraphExecutor(new ExecutorOptions()); 20 | } 21 | } 22 | } 23 | } 24 | 25 | @Override 26 | public TelegraphExecutor getExecutor() { 27 | return executor; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/executors/TelegraphExecutor.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.executors; 2 | 3 | import org.telegram.telegraph.api.TelegraphMethod; 4 | import org.telegram.telegraph.api.TelegraphObject; 5 | import org.telegram.telegraph.exceptions.TelegraphException; 6 | 7 | /** 8 | * @author Ruben Bermudez 9 | * @version 1.0 10 | * Base interface to execute a method, support any custom implementation. Library will create instances of this class 11 | * via TelegraphExecutorFactory when necessary. 12 | */ 13 | public interface TelegraphExecutor { 14 | /** 15 | * Executes a method and returns its result 16 | * @param method Method to execute 17 | * @param Type of method result 18 | * @return Results of the method 19 | * @throws TelegraphException If validation or requests fails 20 | */ 21 | T execute(TelegraphMethod method) throws TelegraphException; 22 | } 23 | -------------------------------------------------------------------------------- /telegraph-sample/telegraph-sample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.telegram 8 | telegra 9 | pom 10 | 1.0 11 | 12 | 13 | telegraph 14 | telegraph-meta 15 | telegraph-sample 16 | 17 | 18 | 19 | 20 | MIT License 21 | http://www.opensource.org/licenses/mit-license.php 22 | repo 23 | 24 | 25 | 26 | 27 | true 28 | 1.0 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Ruben Bermudez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/exceptions/TelegraphRequestException.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.exceptions; 2 | 3 | import org.json.JSONObject; 4 | import org.telegram.telegraph.api.objects.TelegraphResponse; 5 | 6 | /** 7 | * @author Ruben Bermudez 8 | * @version 1.0 9 | */ 10 | public class TelegraphRequestException extends TelegraphException { 11 | private static final String ERRORFIELD = "error"; 12 | 13 | private String error; 14 | 15 | public TelegraphRequestException(String message) { 16 | super(message); 17 | } 18 | 19 | public TelegraphRequestException(String message, JSONObject object) { 20 | super(message); 21 | error = object.getString(ERRORFIELD); 22 | } 23 | 24 | public TelegraphRequestException(String message, TelegraphResponse response) { 25 | super(message); 26 | error = response.getError(); 27 | } 28 | 29 | public TelegraphRequestException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | if (error == null) { 36 | return super.toString(); 37 | } else { 38 | return super.toString() + ": [" + error + "] "; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/exceptions/TelegraphValidationException.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.exceptions; 2 | 3 | import org.telegram.telegraph.api.TelegraphMethod; 4 | import org.telegram.telegraph.api.TelegraphObject; 5 | 6 | /** 7 | * @author Ruben Bermudez 8 | * @version 1.0 9 | */ 10 | public class TelegraphValidationException extends TelegraphException { 11 | private TelegraphMethod method; 12 | private TelegraphObject object; 13 | 14 | public TelegraphValidationException(String message, TelegraphMethod method) { 15 | super(message); 16 | this.method = method; 17 | } 18 | 19 | public TelegraphValidationException(String message, TelegraphObject object) { 20 | super(message); 21 | this.object = object; 22 | } 23 | 24 | public TelegraphMethod getMethod() { 25 | return method; 26 | } 27 | 28 | public TelegraphObject getObject() { 29 | return object; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | if (method != null) { 35 | return super.toString() + " in method: " + method.toString(); 36 | } 37 | if (object != null) { 38 | return super.toString() + " in object: " + object.toString(); 39 | } 40 | return super.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/objects/PageList.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.objects; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import org.telegram.telegraph.api.TelegraphObject; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author Ruben Bermudez 10 | * @version 1.0 11 | * This object represents a list of Telegraph articles belonging to an account. Most recently edited articles first. 12 | */ 13 | public class PageList implements TelegraphObject { 14 | private static final String TOTAL_COUNT_FIELD = "total_count"; 15 | private static final String PAGES_FIELD = "pages"; 16 | 17 | @JsonProperty(TOTAL_COUNT_FIELD) 18 | private Integer totalCount; ///< Total number of pages belonging to the target Telegraph account. 19 | @JsonProperty(PAGES_FIELD) 20 | private List pages; ///< Requested pages of the target Telegraph account. 21 | 22 | public PageList() { 23 | } 24 | 25 | public Integer getTotalCount() { 26 | return totalCount; 27 | } 28 | 29 | public List getPages() { 30 | return pages; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "PageList{" + 36 | "totalCount=" + totalCount + 37 | ", pages=" + pages + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/objects/TelegraphResponse.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.objects; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author Ruben Bermudez 9 | * @version 1.0 10 | */ 11 | public class TelegraphResponse implements Serializable { 12 | private static final String OK_FIELD = "ok"; 13 | private static final String ERROR_FIELD = "error"; 14 | private static final String RESULT_FIELD = "result"; 15 | 16 | @JsonProperty(OK_FIELD) 17 | private Boolean ok; 18 | @JsonProperty(ERROR_FIELD) 19 | private String error; 20 | @JsonProperty(RESULT_FIELD) 21 | private T result; 22 | 23 | public Boolean getOk() { 24 | return ok; 25 | } 26 | 27 | public String getError() { 28 | return error; 29 | } 30 | 31 | public T getResult() { 32 | return result; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | if (ok) { 38 | return "TelegraphResponse{" + 39 | "ok=" + ok + 40 | ", result=" + result + 41 | '}'; 42 | } else { 43 | return "TelegraphResponse{" + 44 | "ok=" + ok + 45 | ", error=" + error + 46 | '}'; 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /telegraph-meta/telegraph-meta.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/TelegraphMethod.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import org.telegram.telegraph.TelegraphContext; 8 | import org.telegram.telegraph.exceptions.TelegraphException; 9 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 10 | import org.telegram.telegraph.executors.TelegraphExecutorFactory; 11 | 12 | /** 13 | * @author Ruben Bermudez 14 | * @version 1.0 15 | */ 16 | @JsonIgnoreProperties(ignoreUnknown = true) 17 | @JsonInclude(JsonInclude.Include.NON_NULL) 18 | public abstract class TelegraphMethod implements Validable { 19 | @JsonIgnore 20 | protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); 21 | 22 | /** 23 | * Deserialize a json answer to the response type to a method 24 | * @param answer Json answer received 25 | * @return Answer for the method 26 | */ 27 | public abstract T deserializeResponse(String answer) throws TelegraphRequestException; 28 | 29 | /** 30 | * Return the path to perform Https request 31 | * @return Path that needs to be appended to the base url 32 | */ 33 | @JsonIgnore 34 | public abstract String getUrlPath(); 35 | 36 | /** 37 | * Execute this method directly 38 | * @return Result of method execution 39 | * @throws TelegraphException If request or validation fails. 40 | */ 41 | public T execute() throws TelegraphException { 42 | validate(); 43 | return TelegraphContext.getInstance(TelegraphExecutorFactory.class) 44 | .getExecutor().execute(this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/objects/NodeElement.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.objects; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** 9 | * @author Ruben Bermudez 10 | * @version 1.0 11 | * This object represents a DOM element node. 12 | */ 13 | public class NodeElement extends Node { 14 | public static final String TAG_FIELD = "tag"; 15 | public static final String ATTRS_FIELD = "attrs"; 16 | public static final String CHILDREN_FIELD = "children"; 17 | 18 | @JsonProperty(TAG_FIELD) 19 | private String tag; ///< Name of the DOM element. Available tags: a, aside, b, blockquote, br, code, em, figcaption, figure, h3, h4, hr, i, iframe, img, li, ol, p, pre, s, strong, u, ul, video. 20 | @JsonProperty(ATTRS_FIELD) 21 | private Map attrs; ///< Attributes of the DOM element. Key of object represents name of attribute, value represents value of attribute. Available attributes: href, src. 22 | @JsonProperty(CHILDREN_FIELD) 23 | private List children; ///< List of child nodes for the DOM element. 24 | 25 | public NodeElement() { 26 | } 27 | 28 | public NodeElement(String tag, Map attrs, List children) { 29 | this.tag = tag; 30 | this.attrs = attrs; 31 | this.children = children; 32 | } 33 | 34 | public String getTag() { 35 | return tag; 36 | } 37 | 38 | public NodeElement setTag(String tag) { 39 | this.tag = tag; 40 | return this; 41 | } 42 | 43 | public Map getAttrs() { 44 | return attrs; 45 | } 46 | 47 | public NodeElement setAttrs(Map attrs) { 48 | this.attrs = attrs; 49 | return this; 50 | } 51 | 52 | public List getChildren() { 53 | return children; 54 | } 55 | 56 | public NodeElement setChildren(List children) { 57 | this.children = children; 58 | return this; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "NodeElement{" + 64 | "tag='" + tag + '\'' + 65 | ", attrs=" + attrs + 66 | ", children=" + children + 67 | '}'; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /telegraph/telegraph.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ### Eclipse template 3 | 4 | .metadata 5 | bin/ 6 | tmp/ 7 | *.tmp 8 | *.bak 9 | *.swp 10 | *~.nib 11 | local.properties 12 | .settings/ 13 | .loadpath 14 | .recommenders 15 | 16 | # Eclipse Core 17 | .project 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # PyDev specific (Python IDE for Eclipse) 26 | *.pydevproject 27 | 28 | # CDT-specific (C/C++ Development Tooling) 29 | .cproject 30 | 31 | # JDT-specific (Eclipse Java Development Tools) 32 | .classpath 33 | 34 | # Java annotation processor (APT) 35 | .factorypath 36 | 37 | # PDT-specific (PHP Development Tools) 38 | .buildpath 39 | 40 | # sbteclipse plugin 41 | .target 42 | 43 | # Tern plugin 44 | .tern-project 45 | 46 | # TeXlipse plugin 47 | .texlipse 48 | 49 | # STS (Spring Tool Suite) 50 | .springBeans 51 | 52 | # Code Recommenders 53 | .recommenders/ 54 | ### JetBrains template 55 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 56 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 57 | 58 | # User-specific stuff: 59 | .idea/workspace.xml 60 | .idea/tasks.xml 61 | 62 | # Sensitive or high-churn files: 63 | .idea/dataSources/ 64 | .idea/dataSources.ids 65 | .idea/dataSources.xml 66 | .idea/dataSources.local.xml 67 | .idea/sqlDataSources.xml 68 | .idea/dynamic.xml 69 | .idea/uiDesigner.xml 70 | 71 | # Gradle: 72 | .idea/gradle.xml 73 | .idea/libraries 74 | 75 | # Mongo Explorer plugin: 76 | .idea/mongoSettings.xml 77 | 78 | ## File-based project format: 79 | *.iws 80 | 81 | ## Plugin-specific files: 82 | 83 | # IntelliJ 84 | /out/ 85 | 86 | # mpeltonen/sbt-idea plugin 87 | .idea_modules/ 88 | 89 | # JIRA plugin 90 | atlassian-ide-plugin.xml 91 | 92 | # Crashlytics plugin (for Android Studio and IntelliJ) 93 | com_crashlytics_export_strings.xml 94 | crashlytics.properties 95 | crashlytics-build.properties 96 | fabric.properties 97 | ### Java template 98 | *.class 99 | 100 | # BlueJ files 101 | *.ctxt 102 | 103 | # Mobile Tools for Java (J2ME) 104 | .mtj.tmp/ 105 | 106 | # Package Files # 107 | *.jar 108 | *.war 109 | *.ear 110 | 111 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 112 | hs_err_pid* 113 | 114 | telegraph/target/ 115 | telegraph-meta/target/ 116 | telegraph-sample/target/ -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/jsonutilities/NodeDeserializer.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.jsonutilities; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.databind.DeserializationContext; 5 | import com.fasterxml.jackson.databind.JsonNode; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 8 | import com.fasterxml.jackson.databind.node.ArrayNode; 9 | import com.fasterxml.jackson.databind.node.ObjectNode; 10 | import com.fasterxml.jackson.databind.node.TextNode; 11 | import org.telegram.telegraph.api.objects.Node; 12 | import org.telegram.telegraph.api.objects.NodeElement; 13 | import org.telegram.telegraph.api.objects.NodeText; 14 | 15 | import java.io.IOException; 16 | import java.util.*; 17 | 18 | /** 19 | * @author Ruben Bermudez 20 | * @version 1.0 21 | */ 22 | public class NodeDeserializer extends StdDeserializer { 23 | public NodeDeserializer() { 24 | super(Node.class); 25 | } 26 | 27 | @Override 28 | public Node deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException { 29 | ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec(); 30 | JsonNode node = mapper.readTree(jsonParser); 31 | if (node instanceof TextNode) { 32 | return new NodeText(node.asText()); 33 | } else { 34 | JsonNode childrenNode = node.get(NodeElement.CHILDREN_FIELD); 35 | JsonNode tagNode = node.get(NodeElement.TAG_FIELD); 36 | JsonNode attrsNode = node.get(NodeElement.ATTRS_FIELD); 37 | 38 | NodeElement element = new NodeElement(); 39 | element.setTag(tagNode.asText()); 40 | 41 | if (attrsNode != null && attrsNode instanceof ObjectNode) { 42 | Map attributes = new HashMap<>(); 43 | for (Iterator it = attrsNode.fieldNames(); it.hasNext(); ) { 44 | String field = it.next(); 45 | attributes.put(field, attrsNode.get(field).asText()); 46 | } 47 | element.setAttrs(attributes); 48 | } 49 | 50 | if (childrenNode != null && childrenNode instanceof ArrayNode) { 51 | List childNodes = new ArrayList<>(); 52 | for (Iterator it = childrenNode.elements(); it.hasNext(); ) { 53 | childNodes.add(mapper.treeToValue(it.next(), Node.class)); 54 | } 55 | element.setChildren(childNodes); 56 | } 57 | 58 | return element; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/methods/RevokeAccessToken.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.methods; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import org.telegram.telegraph.api.TelegraphMethod; 6 | import org.telegram.telegraph.api.objects.Account; 7 | import org.telegram.telegraph.api.objects.TelegraphResponse; 8 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 9 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author Ruben Bermudez 15 | * @version 1.0 16 | * Use this method to revoke access_token and generate a new one, for example, 17 | * if the user would like to reset all connected sessions, 18 | * or you have reasons to believe the token was compromised. 19 | * On success, returns an Account object with new access_token and auth_url fields. 20 | */ 21 | public class RevokeAccessToken extends TelegraphMethod { 22 | private static final String URL_PATH = "revokeAccessToken"; 23 | 24 | private static final String ACCESS_TOKEN_FIELD = "access_token"; 25 | 26 | @JsonProperty(ACCESS_TOKEN_FIELD) 27 | private String accessToken; ///< Required. Access token of the Telegraph account. 28 | 29 | public RevokeAccessToken(String accessToken) { 30 | this.accessToken = accessToken; 31 | } 32 | 33 | public String getAccessToken() { 34 | return accessToken; 35 | } 36 | 37 | public RevokeAccessToken setAccessToken(String accessToken) { 38 | this.accessToken = accessToken; 39 | return this; 40 | } 41 | 42 | @Override 43 | public void validate() throws TelegraphValidationException { 44 | if (accessToken == null || accessToken.isEmpty()) { 45 | throw new TelegraphValidationException("Parameter Access token is required", this); 46 | } 47 | } 48 | 49 | @Override 50 | public Account deserializeResponse(String answer) throws TelegraphRequestException { 51 | try { 52 | TelegraphResponse result = OBJECT_MAPPER.readValue(answer, 53 | new TypeReference>(){}); 54 | if (result.getOk()) { 55 | return result.getResult(); 56 | } else { 57 | throw new TelegraphRequestException("Error revoking token", result); 58 | } 59 | } catch (IOException e) { 60 | throw new TelegraphRequestException("Unable to deserialize response", e); 61 | } 62 | } 63 | 64 | @Override 65 | public String getUrlPath() { 66 | return URL_PATH; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "RevokeAccessToken{" + 72 | "accessToken='" + accessToken + '\'' + 73 | '}'; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/objects/Account.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.objects; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import org.telegram.telegraph.api.TelegraphObject; 5 | 6 | /** 7 | * @author Ruben Bermudez 8 | * @version 1.0 9 | * This object represents a Telegraph account. 10 | */ 11 | public class Account implements TelegraphObject { 12 | private static final String SHORT_NAME_FIELD = "short_name"; 13 | private static final String AUTHOR_NAME_FIELD = "author_name"; 14 | private static final String AUTHOR_URL_FIELD = "author_url"; 15 | private static final String ACCESS_TOKEN_FIELD = "access_token"; 16 | private static final String AUTH_URL_FIELD = "auth_url"; 17 | private static final String PAGE_COUNT_FIELD = "page_count"; 18 | 19 | @JsonProperty(SHORT_NAME_FIELD) 20 | private String shortName; ///< Account name, helps users with several accounts remember which they are currently using. Displayed to the user above the "Edit/Publish" button on Telegra.ph, other users don't see this name. 21 | @JsonProperty(AUTHOR_NAME_FIELD) 22 | private String authorName; ///< Author name displayed below the title. 23 | @JsonProperty(AUTHOR_URL_FIELD) 24 | private String authorUrl; ///< URL to be opened when a user clicks on the name below the title. 25 | @JsonProperty(ACCESS_TOKEN_FIELD) 26 | private String accessToken; ///< Optional. Only returned by the createAccount and revokeAccessToken method. Access token of the Telegraph account. 27 | @JsonProperty(AUTH_URL_FIELD) 28 | private String authUrl; ///< Optional. URL to authorize a browser on telegra.ph and connect it to a Telegraph account. This URL is valid for only one use and for 5 minutes only. 29 | @JsonProperty(PAGE_COUNT_FIELD) 30 | private Integer pageCount; ///< Optional. Number of pages belonging to the Telegraph account. 31 | 32 | public Account() { 33 | } 34 | 35 | public String getShortName() { 36 | return shortName; 37 | } 38 | 39 | public String getAuthorName() { 40 | return authorName; 41 | } 42 | 43 | public String getAuthorUrl() { 44 | return authorUrl; 45 | } 46 | 47 | public String getAccessToken() { 48 | return accessToken; 49 | } 50 | 51 | public String getAuthUrl() { 52 | return authUrl; 53 | } 54 | 55 | public Integer getPageCount() { 56 | return pageCount; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Account{" + 62 | "shortName='" + shortName + '\'' + 63 | ", authorName='" + authorName + '\'' + 64 | ", authorUrl='" + authorUrl + '\'' + 65 | ", accessToken='" + accessToken + '\'' + 66 | ", authUrl='" + authUrl + '\'' + 67 | ", pageCount=" + pageCount + 68 | '}'; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/TelegraphContext.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph; 2 | 3 | import com.google.inject.AbstractModule; 4 | import com.google.inject.Guice; 5 | import com.google.inject.Injector; 6 | import com.google.inject.Singleton; 7 | 8 | import java.text.MessageFormat; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * Created by rubenlagus on 15/12/2016. 14 | */ 15 | public class TelegraphContext { 16 | private static final Object lock = new Object(); 17 | private static Injector INJECTOR; 18 | private static Map bindings = new HashMap<>(); 19 | private static Map instanceBindings = new HashMap<>(); 20 | private static Map singletonBindings = new HashMap<>(); 21 | 22 | public static T getInstance(Class type) { 23 | return getInjector().getInstance(type); 24 | } 25 | 26 | public static void register(Class type, Class implementation) { 27 | if (bindings.containsKey(type)) { 28 | TelegraphLogger.debug("ApiContext", MessageFormat.format("Class {0} already registered", type.getName())); 29 | } 30 | bindings.put(type, implementation); 31 | } 32 | 33 | public static void registerInstance(Class type, S instance) { 34 | if (instanceBindings.containsKey(type)) { 35 | TelegraphLogger.debug("ApiContext", MessageFormat.format("Class {0} already registered", type.getName())); 36 | } 37 | instanceBindings.put(type, instance); 38 | } 39 | 40 | public static void registerSingleton(Class type, Class implementation) { 41 | if (singletonBindings.containsKey(type)) { 42 | TelegraphLogger.debug("ApiContext", MessageFormat.format("Class {0} already registered", type.getName())); 43 | } 44 | singletonBindings.put(type, implementation); 45 | } 46 | 47 | private static Injector getInjector() { 48 | if (INJECTOR == null) { 49 | synchronized (lock) { 50 | if (INJECTOR == null) { 51 | INJECTOR = Guice.createInjector(new ApiModule()); 52 | } 53 | } 54 | } 55 | return INJECTOR; 56 | } 57 | 58 | private static class ApiModule extends AbstractModule { 59 | @Override 60 | protected void configure() { 61 | for (Map.Entry binding : bindings.entrySet()) { 62 | bind(binding.getKey()).to(binding.getValue()); 63 | } 64 | for (Map.Entry binding : singletonBindings.entrySet()) { 65 | bind(binding.getKey()).to(binding.getValue()).in(Singleton.class); 66 | } 67 | for (Map.Entry binding : instanceBindings.entrySet()) { 68 | bind(binding.getKey()).toInstance(binding.getValue()); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/methods/GetPage.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.methods; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import org.telegram.telegraph.api.TelegraphMethod; 6 | import org.telegram.telegraph.api.objects.Page; 7 | import org.telegram.telegraph.api.objects.TelegraphResponse; 8 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 9 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author Ruben Bermudez 15 | * @version 1.0 16 | * Use this method to get a Telegraph page. 17 | * Returns a Page object on success. 18 | */ 19 | public class GetPage extends TelegraphMethod { 20 | private static final String URL_PATH = "getPage"; 21 | 22 | private static final String PATH_FIELD = "path"; 23 | private static final String RETURN_CONTENT_FIELD = "return_content"; 24 | 25 | @JsonProperty(PATH_FIELD) 26 | private String path; ///< Required. Path to the Telegraph page (in the format Title-12-31, i.e. everything that comes after http://telegra.ph/). 27 | @JsonProperty(RETURN_CONTENT_FIELD) 28 | private Boolean returnContent; ///< If true, content field will be returned in Page object. 29 | 30 | public GetPage(String path) { 31 | this.path = path; 32 | } 33 | 34 | public String getPath() { 35 | return path; 36 | } 37 | 38 | public GetPage setPath(String path) { 39 | this.path = path; 40 | return this; 41 | } 42 | 43 | public Boolean getReturnContent() { 44 | return returnContent; 45 | } 46 | 47 | public GetPage setReturnContent(Boolean returnContent) { 48 | this.returnContent = returnContent; 49 | return this; 50 | } 51 | 52 | @Override 53 | public void validate() throws TelegraphValidationException { 54 | if (path == null || path.isEmpty()) { 55 | throw new TelegraphValidationException("Parameter Path field is required", this); 56 | } 57 | } 58 | 59 | @Override 60 | public Page deserializeResponse(String answer) throws TelegraphRequestException { 61 | try { 62 | TelegraphResponse result = OBJECT_MAPPER.readValue(answer, 63 | new TypeReference>(){}); 64 | if (result.getOk()) { 65 | return result.getResult(); 66 | } else { 67 | throw new TelegraphRequestException("Error getting page", result); 68 | } 69 | } catch (IOException e) { 70 | throw new TelegraphRequestException("Unable to deserialize response", e); 71 | } 72 | } 73 | 74 | @Override 75 | public String getUrlPath() { 76 | return URL_PATH; 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return "GetPage{" + 82 | "path='" + path + '\'' + 83 | ", returnContent=" + returnContent + 84 | '}'; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /telegraph/src/main/java/org/telegram/telegraph/executors/DefaultTelegraphExecutor.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.executors; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.google.inject.Inject; 5 | import org.apache.http.HttpEntity; 6 | import org.apache.http.client.config.RequestConfig; 7 | import org.apache.http.client.methods.CloseableHttpResponse; 8 | import org.apache.http.client.methods.HttpPost; 9 | import org.apache.http.conn.ssl.NoopHostnameVerifier; 10 | import org.apache.http.entity.BufferedHttpEntity; 11 | import org.apache.http.entity.ContentType; 12 | import org.apache.http.entity.StringEntity; 13 | import org.apache.http.impl.client.CloseableHttpClient; 14 | import org.apache.http.impl.client.HttpClientBuilder; 15 | import org.apache.http.util.EntityUtils; 16 | import org.telegram.telegraph.ExecutorOptions; 17 | import org.telegram.telegraph.TelegraphConstants; 18 | import org.telegram.telegraph.api.TelegraphMethod; 19 | import org.telegram.telegraph.api.TelegraphObject; 20 | import org.telegram.telegraph.exceptions.TelegraphException; 21 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 22 | 23 | import java.io.IOException; 24 | import java.nio.charset.StandardCharsets; 25 | import java.util.concurrent.TimeUnit; 26 | 27 | /** 28 | * @author Ruben Bermudez 29 | * @version 1.0 30 | */ 31 | public class DefaultTelegraphExecutor implements TelegraphExecutor { 32 | private final ObjectMapper objectMapper; 33 | private volatile CloseableHttpClient httpclient; 34 | private volatile RequestConfig requestConfig; 35 | 36 | @Inject 37 | public DefaultTelegraphExecutor(ExecutorOptions options) { 38 | this.objectMapper = new ObjectMapper(); 39 | httpclient = HttpClientBuilder.create() 40 | .setSSLHostnameVerifier(new NoopHostnameVerifier()) 41 | .setConnectionTimeToLive(70, TimeUnit.SECONDS) 42 | .setMaxConnTotal(100) 43 | .build(); 44 | 45 | requestConfig = options.getRequestConfig(); 46 | } 47 | 48 | @Override 49 | public T execute(TelegraphMethod method) throws TelegraphException { 50 | String responseContent; 51 | try { 52 | String url = TelegraphConstants.BASE_URL + method.getUrlPath(); 53 | HttpPost httppost = new HttpPost(url); 54 | httppost.setConfig(requestConfig); 55 | httppost.addHeader("charset", StandardCharsets.UTF_8.name()); 56 | httppost.addHeader("Content-Type", "application/json"); 57 | httppost.setEntity(new StringEntity(objectMapper.writeValueAsString(method), ContentType.APPLICATION_JSON)); 58 | try (CloseableHttpResponse response = httpclient.execute(httppost)) { 59 | HttpEntity ht = response.getEntity(); 60 | BufferedHttpEntity buf = new BufferedHttpEntity(ht); 61 | responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8); 62 | } 63 | } catch (IOException e) { 64 | throw new TelegraphRequestException("Unable to execute " + method.getUrlPath() + " method", e); 65 | } 66 | 67 | return method.deserializeResponse(responseContent); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Telegraph Java Library 2 | [![Telegram](http://trellobot.doomdns.org/telegrambadge.svg)](https://telegram.me/JavaBotsApi) 3 | 4 | 5 | [![Build Status](https://travis-ci.org/rubenlagus/Telegraph.svg?branch=master)](https://travis-ci.org/rubenlagus/Telegraph) 6 | [![Jitpack](https://jitpack.io/v/rubenlagus/Telegraph.svg)](https://jitpack.io/#rubenlagus/Telegraph) 7 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.telegram/telegraph/badge.svg)](http://mvnrepository.com/artifact/org.telegram/telegraph) 8 | [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/rubenlagus/Telegraph/blob/master/LICENSE) 9 | 10 | A simple to use library to interact with Telegra.ph 11 | 12 | ## Contributions 13 | Feel free to fork this project, work on it and then make a pull request against **DEV** branch. Most of the times I will accept them if they add something valuable to the code. 14 | 15 | Please, **DO NOT PUSH ANY TOKEN OR API KEY**, I will never accept a pull request with that content. 16 | 17 | ## Usage 18 | 19 | Just import the library to your project with one of these options: 20 | 21 | 1. Using Maven Central Repository: 22 | 23 | ```xml 24 | 25 | org.telegram 26 | telegraph 27 | 1.0 28 | 29 | ``` 30 | 31 | 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/Telegraph/v1.0) 32 | 3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/Telegraph/releases/tag/v1.0) 33 | 34 | 35 | For detailed explanation, visite our [How To](https://github.com/rubenlagus/Telegraph/blob/master/telegraph-sample/src/main/java/org/telegram/telegraph/sample/Main.java) 36 | 37 | ## Telegraph API 38 | This library use [Telegraph API](https://telegraph.ph), you can find more information following the link. 39 | 40 | ## Questions or Suggestions 41 | Feel free to create issues [here](https://github.com/rubenlagus/Telegraph/issues) as you need or join the [chat](https://telegram.me/JavaTelegraph) 42 | 43 | ## License 44 | MIT License 45 | 46 | Copyright (c) 2016 Ruben Bermudez 47 | 48 | Permission is hereby granted, free of charge, to any person obtaining a copy 49 | of this software and associated documentation files (the "Software"), to deal 50 | in the Software without restriction, including without limitation the rights 51 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 52 | copies of the Software, and to permit persons to whom the Software is 53 | furnished to do so, subject to the following conditions: 54 | 55 | The above copyright notice and this permission notice shall be included in all 56 | copies or substantial portions of the Software. 57 | 58 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 61 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 62 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 63 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 64 | SOFTWARE. 65 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/methods/GetAccountInfo.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.methods; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import org.telegram.telegraph.api.TelegraphMethod; 6 | import org.telegram.telegraph.api.objects.Account; 7 | import org.telegram.telegraph.api.objects.TelegraphResponse; 8 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 9 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 10 | 11 | import java.io.IOException; 12 | import java.util.List; 13 | 14 | /** 15 | * @author Ruben Bermudez 16 | * @version 1.0 17 | * Use this method to get information about a Telegraph account. 18 | * Returns an Account object on success. 19 | */ 20 | public class GetAccountInfo extends TelegraphMethod { 21 | private static final String URL_PATH = "getAccountInfo"; 22 | 23 | private static final String ACCESS_TOKEN_FIELD = "access_token"; 24 | private static final String FIELDS_FIELD = "fields"; 25 | 26 | @JsonProperty(ACCESS_TOKEN_FIELD) 27 | private String accessToken; ///< Required. Access token of the Telegraph account. 28 | @JsonProperty(FIELDS_FIELD) 29 | private List fields; ///< List of account fields to return. Available fields: Check org.telegram.telegraph.api.objects.AccountField 30 | 31 | public GetAccountInfo(String accessToken) { 32 | this.accessToken = accessToken; 33 | } 34 | 35 | public String getAccessToken() { 36 | return accessToken; 37 | } 38 | 39 | public void setAccessToken(String accessToken) { 40 | this.accessToken = accessToken; 41 | } 42 | 43 | public List getFields() { 44 | return fields; 45 | } 46 | 47 | public void setFields(List fields) { 48 | this.fields = fields; 49 | } 50 | 51 | @Override 52 | public void validate() throws TelegraphValidationException { 53 | if (accessToken == null || accessToken.isEmpty()) { 54 | throw new TelegraphValidationException("Parameter Access token is required", this); 55 | } 56 | if (fields != null && fields.isEmpty()) { 57 | throw new TelegraphValidationException("Fields list is empty", this); 58 | } 59 | } 60 | 61 | @Override 62 | public Account deserializeResponse(String answer) throws TelegraphRequestException { 63 | try { 64 | TelegraphResponse result = OBJECT_MAPPER.readValue(answer, 65 | new TypeReference>(){}); 66 | if (result.getOk()) { 67 | return result.getResult(); 68 | } else { 69 | throw new TelegraphRequestException("Error getting account information", result); 70 | } 71 | } catch (IOException e) { 72 | throw new TelegraphRequestException("Unable to deserialize response", e); 73 | } 74 | } 75 | 76 | @Override 77 | public String getUrlPath() { 78 | return URL_PATH; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "GetAccountInfo{" + 84 | "accessToken='" + accessToken + '\'' + 85 | ", fields=" + fields + 86 | '}'; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/objects/Page.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.objects; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import org.telegram.telegraph.api.TelegraphObject; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author Ruben Bermudez 10 | * @version 1.0 11 | * This object represents a page on Telegraph. 12 | */ 13 | public class Page implements TelegraphObject { 14 | private static final String PATH_FIELD = "path"; 15 | private static final String URL_FIELD = "url"; 16 | private static final String TITLE_FIELD = "title"; 17 | private static final String DESCRIPTION_FIELD = "description"; 18 | private static final String AUTHOR_NAME_FIELD = "author_name"; 19 | private static final String AUTHOR_URL_FIELD = "author_url"; 20 | private static final String IMAGE_URL_FIELD = "image_url"; 21 | private static final String CONTENT_FIELD = "content"; 22 | private static final String CAN_EDIT_FIELD = "can_edit"; 23 | 24 | @JsonProperty(PATH_FIELD) 25 | private String path; ///< Path to the page. 26 | @JsonProperty(URL_FIELD) 27 | private String url; ///< URL of the page. 28 | @JsonProperty(TITLE_FIELD) 29 | private String title; ///< Title of the page. 30 | @JsonProperty(DESCRIPTION_FIELD) 31 | private String description; ///< Description of the page. 32 | @JsonProperty(AUTHOR_NAME_FIELD) 33 | private String authorName; ///< Optional. Name of the author. 34 | @JsonProperty(AUTHOR_URL_FIELD) 35 | private String authorUrl; ///< Optional. URL for the author. 36 | @JsonProperty(IMAGE_URL_FIELD) 37 | private String imageUrl; ///< Optional. Image URL of the page. 38 | @JsonProperty(CONTENT_FIELD) 39 | private List content; ///< Optional. Content of the page. 40 | @JsonProperty(CAN_EDIT_FIELD) 41 | private Boolean canEdit; ///< Optional. Only returned if access_token passed. True, if the target Telegraph account can edit the page. 42 | 43 | public Page() { 44 | } 45 | 46 | public String getPath() { 47 | return path; 48 | } 49 | 50 | public String getUrl() { 51 | return url; 52 | } 53 | 54 | public String getTitle() { 55 | return title; 56 | } 57 | 58 | public String getDescription() { 59 | return description; 60 | } 61 | 62 | public String getAuthorName() { 63 | return authorName; 64 | } 65 | 66 | public String getAuthorUrl() { 67 | return authorUrl; 68 | } 69 | 70 | public String getImageUrl() { 71 | return imageUrl; 72 | } 73 | 74 | public List getContent() { 75 | return content; 76 | } 77 | 78 | public Boolean getCanEdit() { 79 | return canEdit; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return "Page{" + 85 | "path='" + path + '\'' + 86 | ", url='" + url + '\'' + 87 | ", title='" + title + '\'' + 88 | ", description='" + description + '\'' + 89 | ", authorName='" + authorName + '\'' + 90 | ", authorUrl='" + authorUrl + '\'' + 91 | ", imageUrl='" + imageUrl + '\'' + 92 | ", content=" + content + 93 | ", canEdit=" + canEdit + 94 | '}'; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /telegraph-sample/src/main/java/org/telegram/telegraph/sample/Main.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.sample; 2 | 3 | import org.telegram.telegraph.ExecutorOptions; 4 | import org.telegram.telegraph.TelegraphContext; 5 | import org.telegram.telegraph.TelegraphContextInitializer; 6 | import org.telegram.telegraph.TelegraphLogger; 7 | import org.telegram.telegraph.api.methods.*; 8 | import org.telegram.telegraph.api.objects.*; 9 | import org.telegram.telegraph.exceptions.TelegraphException; 10 | 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.logging.ConsoleHandler; 15 | import java.util.logging.Level; 16 | 17 | /** 18 | * @author Ruben Bermudez 19 | * @version 1.0 20 | */ 21 | public class Main { 22 | public static void main(String[] args) { 23 | // Set up logger 24 | TelegraphLogger.setLevel(Level.ALL); 25 | TelegraphLogger.registerLogger(new ConsoleHandler()); 26 | 27 | // Initialize context 28 | TelegraphContextInitializer.init(); 29 | TelegraphContext.registerInstance(ExecutorOptions.class, new ExecutorOptions()); 30 | 31 | try { 32 | // Create account 33 | Account account = new CreateAccount("TestTelegraphApi") 34 | .setAuthorName("TelegraphApi") 35 | .execute(); 36 | 37 | // Edit account 38 | Account editedAccount = new EditAccountInfo(account.getAccessToken()) 39 | .setAuthorName("Default user") 40 | .setShortName("Short name") 41 | .execute(); 42 | 43 | // Get account info 44 | editedAccount = new GetAccountInfo(account.getAccessToken()) 45 | .execute(); 46 | 47 | Node contentNode= new NodeText("My content"); 48 | List content = new ArrayList<>(); 49 | content.add(contentNode); 50 | 51 | // Create new account 52 | Page page = new CreatePage(account.getAccessToken(), "My title", content) 53 | .setAuthorName("Random author") 54 | .setReturnContent(true) 55 | .execute(); 56 | 57 | // Get page 58 | page = new GetPage(page.getPath()).setReturnContent(true).execute(); 59 | 60 | Node tagNode = new NodeElement("p", new HashMap<>(), content); 61 | List tagContent = new ArrayList<>(); 62 | tagContent.add(tagNode); 63 | 64 | // Edit page 65 | Page editedPage = new EditPage(account.getAccessToken(), page.getPath(), page.getTitle(), tagContent) 66 | .setAuthorName("New Author") 67 | .execute(); 68 | 69 | // Get page list 70 | PageList pageList = new GetPageList(account.getAccessToken()) 71 | .setLimit(10) 72 | .execute(); 73 | 74 | // Get page view 75 | PageViews views = new GetViews(page.getPath()) 76 | .setYear(2016) 77 | .execute(); 78 | 79 | // Revoke account token 80 | Account revokedAccount = new RevokeAccessToken(account.getAccessToken()).execute(); 81 | } catch (TelegraphException e) { 82 | TelegraphLogger.severe("MAIN", e); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/methods/GetPageList.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.methods; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import org.telegram.telegraph.api.TelegraphMethod; 6 | import org.telegram.telegraph.api.objects.PageList; 7 | import org.telegram.telegraph.api.objects.TelegraphResponse; 8 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 9 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author Ruben Bermudez 15 | * @version 1.0 16 | * Use this method to get a list of pages belonging to a Telegraph account. 17 | * Returns a PageList object, sorted by most recently created pages first. 18 | */ 19 | public class GetPageList extends TelegraphMethod { 20 | private static final String URL_PATH = "getPageList"; 21 | 22 | private static final String ACCESS_TOKEN_FIELD = "access_token"; 23 | private static final String OFFSET_FIELD = "offset"; 24 | private static final String LIMIT_FIELD = "limit"; 25 | 26 | @JsonProperty(ACCESS_TOKEN_FIELD) 27 | private String accessToken; ///< Required. Access token of the Telegraph account 28 | @JsonProperty(OFFSET_FIELD) 29 | private Integer offset; ///< (Default 0) Sequential number of the first page to be returned. 30 | @JsonProperty(LIMIT_FIELD) 31 | private Integer limit; ///< (Default 50, 0-200) Limits the number of pages to be retrieved. 32 | 33 | public GetPageList(String accessToken) { 34 | this.accessToken = accessToken; 35 | } 36 | 37 | public String getAccessToken() { 38 | return accessToken; 39 | } 40 | 41 | public GetPageList setAccessToken(String accessToken) { 42 | this.accessToken = accessToken; 43 | return this; 44 | } 45 | 46 | public Integer getOffset() { 47 | return offset; 48 | } 49 | 50 | public GetPageList setOffset(Integer offset) { 51 | this.offset = offset; 52 | return this; 53 | } 54 | 55 | public Integer getLimit() { 56 | return limit; 57 | } 58 | 59 | public GetPageList setLimit(Integer limit) { 60 | this.limit = limit; 61 | return this; 62 | } 63 | 64 | @Override 65 | public void validate() throws TelegraphValidationException { 66 | if (accessToken == null || accessToken.isEmpty()) { 67 | throw new TelegraphValidationException("Parameter Access token is required", this); 68 | } 69 | if (offset != null && (offset < 0 || offset > 200)) { 70 | throw new TelegraphValidationException("Parameter offset out of range", this); 71 | } 72 | } 73 | 74 | @Override 75 | public PageList deserializeResponse(String answer) throws TelegraphRequestException { 76 | try { 77 | TelegraphResponse result = OBJECT_MAPPER.readValue(answer, 78 | new TypeReference>(){}); 79 | if (result.getOk()) { 80 | return result.getResult(); 81 | } else { 82 | throw new TelegraphRequestException("Error getting page list", result); 83 | } 84 | } catch (IOException e) { 85 | throw new TelegraphRequestException("Unable to deserialize response", e); 86 | } 87 | } 88 | 89 | @Override 90 | public String getUrlPath() { 91 | return URL_PATH; 92 | } 93 | 94 | @Override 95 | public String toString() { 96 | return "GetPageList{" + 97 | "accessToken='" + accessToken + '\'' + 98 | ", offset=" + offset + 99 | ", limit=" + limit + 100 | '}'; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/methods/CreateAccount.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.methods; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import org.telegram.telegraph.api.TelegraphMethod; 6 | import org.telegram.telegraph.api.objects.Account; 7 | import org.telegram.telegraph.api.objects.TelegraphResponse; 8 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 9 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author Ruben Bermudez 15 | * @version 1.0 16 | * Use this method to create a new Telegraph account. Most users only need one account, 17 | * but this can be useful for channel administrators who would like to keep individual 18 | * author names and links for each of their channels. On success, returns an Account 19 | * object with default fields and an additional access_token field. 20 | */ 21 | public class CreateAccount extends TelegraphMethod { 22 | private static final String URL_PATH = "createAccount"; 23 | 24 | private static final String SHORT_NAME_FIELD = "short_name"; 25 | private static final String AUTHOR_NAME_FIELD = "author_name"; 26 | private static final String AUTHOR_URL_FIELD = "author_url"; 27 | 28 | @JsonProperty(SHORT_NAME_FIELD) 29 | private String shortName; ///< Required (1-32 characters). Account name, helps users with several accounts remember which they are currently using. Displayed to the user above the "Edit/Publish" button on Telegra.ph, other users don't see this name. 30 | @JsonProperty(AUTHOR_NAME_FIELD) 31 | private String authorName; ///< (0-128 characters) Default author name for new articles, displayed below the title. 32 | @JsonProperty(AUTHOR_URL_FIELD) 33 | private String authorUrl; ///< (0-512 characters) Default author link, opened when users clicks on the name below the title. 34 | 35 | public CreateAccount(String shortName) { 36 | this.shortName = shortName; 37 | } 38 | 39 | public String getShortName() { 40 | return shortName; 41 | } 42 | 43 | public CreateAccount setShortName(String shortName) { 44 | this.shortName = shortName; 45 | return this; 46 | } 47 | 48 | public String getAuthorName() { 49 | return authorName; 50 | } 51 | 52 | public CreateAccount setAuthorName(String authorName) { 53 | this.authorName = authorName; 54 | return this; 55 | } 56 | 57 | public String getAuthorUrl() { 58 | return authorUrl; 59 | } 60 | 61 | public CreateAccount setAuthorUrl(String authorUrl) { 62 | this.authorUrl = authorUrl; 63 | return this; 64 | } 65 | 66 | @Override 67 | public void validate() throws TelegraphValidationException { 68 | if (shortName == null || shortName.length() < 1 || shortName.length() > 32) { 69 | throw new TelegraphValidationException("Wrong parameter Short Name", this); 70 | } 71 | if (authorName != null && (authorName.length() < 0 || authorName.length() > 128)) { 72 | throw new TelegraphValidationException("Wrong size for Author Name", this); 73 | } 74 | if (authorUrl != null && (authorUrl.length() < 0 || authorUrl.length() > 512)) { 75 | throw new TelegraphValidationException("Wrong size for Author Url", this); 76 | } 77 | } 78 | 79 | @Override 80 | public Account deserializeResponse(String answer) throws TelegraphRequestException { 81 | try { 82 | TelegraphResponse result = OBJECT_MAPPER.readValue(answer, 83 | new TypeReference>(){}); 84 | if (result.getOk()) { 85 | return result.getResult(); 86 | } else { 87 | throw new TelegraphRequestException("Error creating account", result); 88 | } 89 | } catch (IOException e) { 90 | throw new TelegraphRequestException("Unable to deserialize response", e); 91 | } 92 | } 93 | 94 | @Override 95 | public String getUrlPath() { 96 | return URL_PATH; 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return "CreateAccount{" + 102 | "shortName='" + shortName + '\'' + 103 | ", authorName='" + authorName + '\'' + 104 | ", authorUrl='" + authorUrl + '\'' + 105 | '}'; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/methods/EditAccountInfo.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.methods; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import org.telegram.telegraph.api.TelegraphMethod; 6 | import org.telegram.telegraph.api.objects.Account; 7 | import org.telegram.telegraph.api.objects.TelegraphResponse; 8 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 9 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author Ruben Bermudez 15 | * @version 1.0 16 | * Use this method to update information about a Telegraph account. 17 | * Pass only the parameters that you want to edit. On success, 18 | * returns an Account object with the default fields. 19 | */ 20 | public class EditAccountInfo extends TelegraphMethod { 21 | private static final String URL_PATH = "editAccountInfo"; 22 | 23 | private static final String ACCESS_TOKEN_FIELD = "access_token"; 24 | private static final String SHORT_NAME_FIELD = "short_name"; 25 | private static final String AUTHOR_NAME_FIELD = "author_name"; 26 | private static final String AUTHOR_URL_FIELD = "author_url"; 27 | 28 | @JsonProperty(ACCESS_TOKEN_FIELD) 29 | private String accessToken; ///< Required. Access token of the Telegraph account. 30 | @JsonProperty(SHORT_NAME_FIELD) 31 | private String shortName; ///< (1-32 characters). New account name. 32 | @JsonProperty(AUTHOR_NAME_FIELD) 33 | private String authorName; ///< (0-128 characters) New default author name used when creating new articles. 34 | @JsonProperty(AUTHOR_URL_FIELD) 35 | private String authorUrl; ///< (0-512 characters) New default profile link, opened when users click on the author's name below the title. Can be any link, not necessarily to a Telegram profile or channel. 36 | 37 | public EditAccountInfo(String accessToken) { 38 | this.accessToken = accessToken; 39 | } 40 | 41 | public String getAccessToken() { 42 | return accessToken; 43 | } 44 | 45 | public EditAccountInfo setAccessToken(String accessToken) { 46 | this.accessToken = accessToken; 47 | return this; 48 | } 49 | 50 | public String getShortName() { 51 | return shortName; 52 | } 53 | 54 | public EditAccountInfo setShortName(String shortName) { 55 | this.shortName = shortName; 56 | return this; 57 | } 58 | 59 | public String getAuthorName() { 60 | return authorName; 61 | } 62 | 63 | public EditAccountInfo setAuthorName(String authorName) { 64 | this.authorName = authorName; 65 | return this; 66 | } 67 | 68 | public String getAuthorUrl() { 69 | return authorUrl; 70 | } 71 | 72 | public EditAccountInfo setAuthorUrl(String authorUrl) { 73 | this.authorUrl = authorUrl; 74 | return this; 75 | } 76 | 77 | @Override 78 | public void validate() throws TelegraphValidationException { 79 | if (accessToken == null || accessToken.isEmpty()) { 80 | throw new TelegraphValidationException("Parameter Access token is required", this); 81 | } 82 | if (shortName != null && (shortName.length() < 1 || shortName.length() > 32)) { 83 | throw new TelegraphValidationException("Wrong size for Short Name", this); 84 | } 85 | if (authorName != null && (authorName.length() < 0 || authorName.length() > 128)) { 86 | throw new TelegraphValidationException("Wrong size for Author Name", this); 87 | } 88 | if (authorUrl != null && (authorUrl.length() < 0 || authorUrl.length() > 512)) { 89 | throw new TelegraphValidationException("Wrong size for Author Url", this); 90 | } 91 | } 92 | 93 | @Override 94 | public Account deserializeResponse(String answer) throws TelegraphRequestException { 95 | try { 96 | TelegraphResponse result = OBJECT_MAPPER.readValue(answer, 97 | new TypeReference>(){}); 98 | if (result.getOk()) { 99 | return result.getResult(); 100 | } else { 101 | throw new TelegraphRequestException("Error editing account", result); 102 | } 103 | } catch (IOException e) { 104 | throw new TelegraphRequestException("Unable to deserialize response", e); 105 | } 106 | } 107 | 108 | @Override 109 | public String getUrlPath() { 110 | return URL_PATH; 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | return "EditAccountInfo{" + 116 | "accessToken='" + accessToken + '\'' + 117 | ", shortName='" + shortName + '\'' + 118 | ", authorName='" + authorName + '\'' + 119 | ", authorUrl='" + authorUrl + '\'' + 120 | '}'; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/TelegraphLogger.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph; 2 | 3 | import java.util.logging.Handler; 4 | import java.util.logging.Level; 5 | import java.util.logging.Logger; 6 | 7 | /** 8 | * Created by rubenlagus on 15/12/2016. 9 | */ 10 | public class TelegraphLogger { 11 | private static final Logger logger = Logger.getLogger("Telegraph Api"); 12 | 13 | public static void setLevel(Level level) { 14 | logger.setLevel(level); 15 | } 16 | 17 | public static void registerLogger(Handler handler) { 18 | logger.addHandler(handler); 19 | } 20 | 21 | public static void log(Level level, String tag, String msg) { 22 | logger.log(level, String.format("%s - %s", tag, msg)); 23 | } 24 | 25 | public static void severe(String tag, String msg) { 26 | logger.severe(String.format("%s - %s", tag, msg)); 27 | } 28 | 29 | public static void warn(String tag, String msg) { 30 | warning(tag, msg); 31 | } 32 | 33 | public static void debug(String tag, String msg) { 34 | fine(tag, msg); 35 | } 36 | 37 | public static void error(String tag, String msg) { 38 | severe(tag, msg); 39 | } 40 | 41 | public static void trace(String tag, String msg) { 42 | finer(tag, msg); 43 | } 44 | 45 | public static void warning(String tag, String msg) { 46 | logger.warning(String.format("%s - %s", tag, msg)); 47 | } 48 | 49 | public static void info(String tag, String msg) { 50 | logger.info(String.format("%s - %s", tag, msg)); 51 | } 52 | 53 | public static void config(String tag, String msg) { 54 | logger.config(String.format("%s - %s", tag, msg)); 55 | } 56 | 57 | public static void fine(String tag, String msg) { 58 | logger.fine(String.format("%s - %s", tag, msg)); 59 | } 60 | 61 | public static void finer(String tag, String msg) { 62 | logger.finer(String.format("%s - %s", tag, msg)); 63 | } 64 | 65 | public static void finest(String tag, String msg) { 66 | logger.finest(String.format("%s - %s", tag, msg)); 67 | } 68 | 69 | public static void log(Level level, String tag, Throwable throwable) { 70 | logger.log(level, tag, throwable); 71 | } 72 | 73 | public static void log(Level level, String tag, String msg, Throwable thrown) { 74 | logger.log(level, String.format("%s - %s", tag, msg), thrown); 75 | } 76 | 77 | public static void severe(String tag, Throwable throwable) { 78 | logger.log(Level.SEVERE, tag, throwable); 79 | } 80 | 81 | public static void warning(String tag, Throwable throwable) { 82 | logger.log(Level.WARNING, tag, throwable); 83 | } 84 | 85 | public static void info(String tag, Throwable throwable) { 86 | logger.log(Level.INFO, tag, throwable); 87 | } 88 | 89 | public static void config(String tag, Throwable throwable) { 90 | logger.log(Level.CONFIG, tag, throwable); 91 | } 92 | 93 | public static void fine(String tag, Throwable throwable) { 94 | logger.log(Level.FINE, tag, throwable); 95 | } 96 | 97 | public static void finer(String tag, Throwable throwable) { 98 | logger.log(Level.FINER, tag, throwable); 99 | } 100 | 101 | public static void finest(String tag, Throwable throwable) { 102 | logger.log(Level.FINEST, tag, throwable); 103 | } 104 | 105 | public static void warn(String tag, Throwable throwable) { 106 | warning(tag, throwable); 107 | } 108 | 109 | public static void debug(String tag, Throwable throwable) { 110 | fine(tag, throwable); 111 | } 112 | 113 | public static void error(String tag, Throwable throwable) { 114 | severe(tag, throwable); 115 | } 116 | 117 | public static void trace(String tag, Throwable throwable) { 118 | finer(tag, throwable); 119 | } 120 | 121 | public static void severe(String msg, String tag, Throwable throwable) { 122 | log(Level.SEVERE, tag, msg, throwable); 123 | } 124 | 125 | public static void warning(String msg, String tag, Throwable throwable) { 126 | log(Level.WARNING, tag, msg, throwable); 127 | } 128 | 129 | public static void info(String msg, String tag, Throwable throwable) { 130 | log(Level.INFO, tag, msg, throwable); 131 | } 132 | 133 | public static void config(String msg, String tag, Throwable throwable) { 134 | log(Level.CONFIG, tag, msg, throwable); 135 | } 136 | 137 | public static void fine(String msg, String tag, Throwable throwable) { 138 | log(Level.FINE, tag, msg, throwable); 139 | } 140 | 141 | public static void finer(String msg, String tag, Throwable throwable) { 142 | log(Level.FINER, tag, msg, throwable); 143 | } 144 | 145 | public static void finest(String msg, String tag, Throwable throwable) { 146 | log(Level.FINEST, tag, msg, throwable); 147 | } 148 | 149 | public static void warn(String msg, String tag, Throwable throwable) { 150 | log(Level.WARNING, tag, msg, throwable); 151 | } 152 | 153 | public static void debug(String msg, String tag, Throwable throwable) { 154 | log(Level.FINE, tag, msg, throwable); 155 | } 156 | 157 | public static void error(String msg, String tag, Throwable throwable) { 158 | log(Level.SEVERE, tag, msg, throwable); 159 | } 160 | 161 | public static void trace(String msg, String tag, Throwable throwable) { 162 | log(Level.FINER, tag, msg, throwable); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/methods/GetViews.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.methods; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import org.telegram.telegraph.api.TelegraphMethod; 6 | import org.telegram.telegraph.api.objects.PageViews; 7 | import org.telegram.telegraph.api.objects.TelegraphResponse; 8 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 9 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author Ruben Bermudez 15 | * @version 1.0 16 | * Use this method to get the number of views for a Telegraph article. 17 | * Returns a PageViews object on success. 18 | * By default, the total number of page views will be returned. 19 | */ 20 | public class GetViews extends TelegraphMethod { 21 | private static final String URL_PATH = "getViews"; 22 | 23 | private static final String PATH_FIELD = "path"; 24 | private static final String YEAR_FIELD = "year"; 25 | private static final String MONTH_FIELD = "month"; 26 | private static final String DAY_FIELD = "day"; 27 | private static final String HOUR_FIELD = "hour"; 28 | 29 | @JsonProperty(PATH_FIELD) 30 | private String path; ///< Required. Path to the Telegraph page (in the format Title-12-31, where 12 is the month and 31 the day the article was first published). 31 | @JsonProperty(YEAR_FIELD) 32 | private Integer year; ///< (2000-2100) Required if month is passed. If passed, the number of page views for the requested year will be returned. 33 | @JsonProperty(MONTH_FIELD) 34 | private Integer month; ///< (1-12) Required if day is passed. If passed, the number of page views for the requested month will be returned. 35 | @JsonProperty(DAY_FIELD) 36 | private Integer day; ///< (1-31) Required if hour is passed. If passed, the number of page views for the requested day will be returned. 37 | @JsonProperty(HOUR_FIELD) 38 | private Integer hour; ///< (0-24) If passed, the number of page views for the requested hour will be returned. 39 | 40 | public GetViews(String path) { 41 | this.path = path; 42 | } 43 | 44 | public String getPath() { 45 | return path; 46 | } 47 | 48 | public GetViews setPath(String path) { 49 | this.path = path; 50 | return this; 51 | } 52 | 53 | public Integer getYear() { 54 | return year; 55 | } 56 | 57 | public GetViews setYear(Integer year) { 58 | this.year = year; 59 | return this; 60 | } 61 | 62 | public Integer getMonth() { 63 | return month; 64 | } 65 | 66 | public GetViews setMonth(Integer month) { 67 | this.month = month; 68 | return this; 69 | } 70 | 71 | public Integer getDay() { 72 | return day; 73 | } 74 | 75 | public GetViews setDay(Integer day) { 76 | this.day = day; 77 | return this; 78 | } 79 | 80 | public Integer getHour() { 81 | return hour; 82 | } 83 | 84 | public GetViews setHour(Integer hour) { 85 | this.hour = hour; 86 | return this; 87 | } 88 | 89 | @Override 90 | public void validate() throws TelegraphValidationException { 91 | if (path == null || path.isEmpty()) { 92 | throw new TelegraphValidationException("Parameter Path is required", this); 93 | } 94 | if (year != null && (year < 2000 || year > 2100)) { 95 | throw new TelegraphValidationException("Parameter year out of range", this); 96 | } 97 | if (month != null && year == null) { 98 | throw new TelegraphValidationException("Parameter year is required when month is present", this); 99 | } 100 | if (month != null && (month < 1 || month > 12)) { 101 | throw new TelegraphValidationException("Parameter month out of range", this); 102 | } 103 | if (day != null && month == null) { 104 | throw new TelegraphValidationException("Parameter month is required when day is present", this); 105 | } 106 | if (day != null && (day < 1 || day > 31)) { 107 | throw new TelegraphValidationException("Parameter day out of range", this); 108 | } 109 | if (hour != null && day == null) { 110 | throw new TelegraphValidationException("Parameter day is required when hour is present", this); 111 | } 112 | if (hour != null && (hour < 0 || hour > 24)) { 113 | throw new TelegraphValidationException("Parameter hour out of range", this); 114 | } 115 | } 116 | 117 | @Override 118 | public PageViews deserializeResponse(String answer) throws TelegraphRequestException { 119 | try { 120 | TelegraphResponse result = OBJECT_MAPPER.readValue(answer, 121 | new TypeReference>(){}); 122 | if (result.getOk()) { 123 | return result.getResult(); 124 | } else { 125 | throw new TelegraphRequestException("Error getting views", result); 126 | } 127 | } catch (IOException e) { 128 | throw new TelegraphRequestException("Unable to deserialize response", e); 129 | } 130 | } 131 | 132 | @Override 133 | public String getUrlPath() { 134 | return URL_PATH; 135 | } 136 | 137 | @Override 138 | public String toString() { 139 | return "GetViews{" + 140 | "path='" + path + '\'' + 141 | ", year=" + year + 142 | ", month=" + month + 143 | ", day=" + day + 144 | ", hour=" + hour + 145 | '}'; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/methods/CreatePage.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.methods; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import org.telegram.telegraph.api.TelegraphMethod; 6 | import org.telegram.telegraph.api.objects.Node; 7 | import org.telegram.telegraph.api.objects.Page; 8 | import org.telegram.telegraph.api.objects.TelegraphResponse; 9 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 10 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 11 | 12 | import java.io.IOException; 13 | import java.util.List; 14 | 15 | /** 16 | * @author Ruben Bermudez 17 | * @version 1.0 18 | * Use this method to create a new Telegraph page. 19 | * On success, returns a Page object. 20 | */ 21 | public class CreatePage extends TelegraphMethod { 22 | private static final String URL_PATH = "createPage"; 23 | 24 | private static final String ACCESS_TOKEN_FIELD = "access_token"; 25 | private static final String TITLE_FIELD = "title"; 26 | private static final String AUTHOR_NAME_FIELD = "author_name"; 27 | private static final String AUTHOR_URL_FIELD = "author_url"; 28 | private static final String CONTENT_FIELD = "content"; 29 | private static final String RETURN_CONTENT_FIELD = "return_content"; 30 | 31 | @JsonProperty(ACCESS_TOKEN_FIELD) 32 | private String accessToken; ///< Required. Access token of the Telegraph account. 33 | @JsonProperty(TITLE_FIELD) 34 | private String title; ///< Required (1-256 characters). Page title. 35 | @JsonProperty(AUTHOR_NAME_FIELD) 36 | private String authorName; ///< (0-128 characters) Default author name for new articles, displayed below the title. 37 | @JsonProperty(AUTHOR_URL_FIELD) 38 | private String authorUrl; ///< (0-512 characters) Default author link, opened when users clicks on the name below the title. 39 | @JsonProperty(CONTENT_FIELD) 40 | private List content; ///< Required (Up to 64KB). Content of the page. 41 | @JsonProperty(RETURN_CONTENT_FIELD) 42 | private Boolean returnContent; ///< If true, a content field will be returned in the Page object (see: Content format). 43 | 44 | public CreatePage(String accessToken, String title, List content) { 45 | this.accessToken = accessToken; 46 | this.title = title; 47 | this.content = content; 48 | } 49 | 50 | public String getAccessToken() { 51 | return accessToken; 52 | } 53 | 54 | public CreatePage setAccessToken(String accessToken) { 55 | this.accessToken = accessToken; 56 | return this; 57 | } 58 | 59 | public String getTitle() { 60 | return title; 61 | } 62 | 63 | public CreatePage setTitle(String title) { 64 | this.title = title; 65 | return this; 66 | } 67 | 68 | public String getAuthorName() { 69 | return authorName; 70 | } 71 | 72 | public CreatePage setAuthorName(String authorName) { 73 | this.authorName = authorName; 74 | return this; 75 | } 76 | 77 | public String getAuthorUrl() { 78 | return authorUrl; 79 | } 80 | 81 | public CreatePage setAuthorUrl(String authorUrl) { 82 | this.authorUrl = authorUrl; 83 | return this; 84 | } 85 | 86 | public List getContent() { 87 | return content; 88 | } 89 | 90 | public CreatePage setContent(List content) { 91 | this.content = content; 92 | return this; 93 | } 94 | 95 | public Boolean getReturnContent() { 96 | return returnContent; 97 | } 98 | 99 | public CreatePage setReturnContent(Boolean returnContent) { 100 | this.returnContent = returnContent; 101 | return this; 102 | } 103 | 104 | @Override 105 | public void validate() throws TelegraphValidationException { 106 | if (accessToken == null || accessToken.isEmpty()) { 107 | throw new TelegraphValidationException("Parameter Access token is required", this); 108 | } 109 | if (title == null || title.length() < 1 || title.length() > 256) { 110 | throw new TelegraphValidationException("Parameter Title is missing or out of size", this); 111 | } 112 | if (content == null || content.isEmpty()) { 113 | throw new TelegraphValidationException("Parameter Content is required", this); 114 | } 115 | if (authorName != null && (authorName.length() < 0 || authorName.length() > 128)) { 116 | throw new TelegraphValidationException("Wrong size for Author Name", this); 117 | } 118 | if (authorUrl != null && (authorUrl.length() < 0 || authorUrl.length() > 512)) { 119 | throw new TelegraphValidationException("Wrong size for Author Url", this); 120 | } 121 | } 122 | 123 | @Override 124 | public Page deserializeResponse(String answer) throws TelegraphRequestException { 125 | try { 126 | TelegraphResponse result = OBJECT_MAPPER.readValue(answer, 127 | new TypeReference>(){}); 128 | if (result.getOk()) { 129 | return result.getResult(); 130 | } else { 131 | throw new TelegraphRequestException("Error creating page", result); 132 | } 133 | } catch (IOException e) { 134 | throw new TelegraphRequestException("Unable to deserialize response", e); 135 | } 136 | } 137 | 138 | @Override 139 | public String getUrlPath() { 140 | return URL_PATH; 141 | } 142 | 143 | @Override 144 | public String toString() { 145 | return "CreatePage{" + 146 | "accessToken='" + accessToken + '\'' + 147 | ", title='" + title + '\'' + 148 | ", authorName='" + authorName + '\'' + 149 | ", authorUrl='" + authorUrl + '\'' + 150 | ", content=" + content + 151 | ", returnContent=" + returnContent + 152 | '}'; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /telegraph-meta/src/main/java/org/telegram/telegraph/api/methods/EditPage.java: -------------------------------------------------------------------------------- 1 | package org.telegram.telegraph.api.methods; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import org.telegram.telegraph.api.TelegraphMethod; 6 | import org.telegram.telegraph.api.objects.Node; 7 | import org.telegram.telegraph.api.objects.Page; 8 | import org.telegram.telegraph.api.objects.TelegraphResponse; 9 | import org.telegram.telegraph.exceptions.TelegraphRequestException; 10 | import org.telegram.telegraph.exceptions.TelegraphValidationException; 11 | 12 | import java.io.IOException; 13 | import java.util.List; 14 | 15 | /** 16 | * @author Ruben Bermudez 17 | * @version 1.0 18 | * Use this method to edit an existing Telegraph page. 19 | * On success, returns a Page object. 20 | */ 21 | public class EditPage extends TelegraphMethod { 22 | private static final String URL_PATH = "editPage"; 23 | 24 | private static final String ACCESS_TOKEN_FIELD = "access_token"; 25 | private static final String PATH_FIELD = "path"; 26 | private static final String TITLE_FIELD = "title"; 27 | private static final String CONTENT_FIELD = "content"; 28 | private static final String AUTHOR_NAME_FIELD = "author_name"; 29 | private static final String AUTHOR_URL_FIELD = "author_url"; 30 | private static final String RETURN_CONTENT_FIELD = "return_content"; 31 | 32 | @JsonProperty(ACCESS_TOKEN_FIELD) 33 | private String accessToken; ///< Required. Access token of the Telegraph account. 34 | @JsonProperty(PATH_FIELD) 35 | private String path; ///< Required. Path to the page. 36 | @JsonProperty(TITLE_FIELD) 37 | private String title; ///< Required (1-256 characters). Page title. 38 | @JsonProperty(CONTENT_FIELD) 39 | private List content; ///< Required (Up to 64KB). Content of the page. 40 | @JsonProperty(AUTHOR_NAME_FIELD) 41 | private String authorName; ///< (0-128 characters) Default author name for new articles, displayed below the title. 42 | @JsonProperty(AUTHOR_URL_FIELD) 43 | private String authorUrl; ///< (0-512 characters) Default author link, opened when users clicks on the name below the title. 44 | @JsonProperty(RETURN_CONTENT_FIELD) 45 | private Boolean returnContent; ///< If true, a content field will be returned in the Page object (see: Content format). 46 | 47 | public EditPage(String accessToken, String path, String title, List content) { 48 | this.accessToken = accessToken; 49 | this.path = path; 50 | this.title = title; 51 | this.content = content; 52 | } 53 | 54 | public String getAccessToken() { 55 | return accessToken; 56 | } 57 | 58 | public EditPage setAccessToken(String accessToken) { 59 | this.accessToken = accessToken; 60 | return this; 61 | } 62 | 63 | public String getPath() { 64 | return path; 65 | } 66 | 67 | public EditPage setPath(String path) { 68 | this.path = path; 69 | return this; 70 | } 71 | 72 | public String getTitle() { 73 | return title; 74 | } 75 | 76 | public EditPage setTitle(String title) { 77 | this.title = title; 78 | return this; 79 | } 80 | 81 | public List getContent() { 82 | return content; 83 | } 84 | 85 | public EditPage setContent(List content) { 86 | this.content = content; 87 | return this; 88 | } 89 | 90 | public String getAuthorName() { 91 | return authorName; 92 | } 93 | 94 | public EditPage setAuthorName(String authorName) { 95 | this.authorName = authorName; 96 | return this; 97 | } 98 | 99 | public String getAuthorUrl() { 100 | return authorUrl; 101 | } 102 | 103 | public EditPage setAuthorUrl(String authorUrl) { 104 | this.authorUrl = authorUrl; 105 | return this; 106 | } 107 | 108 | public Boolean getReturnContent() { 109 | return returnContent; 110 | } 111 | 112 | public EditPage setReturnContent(Boolean returnContent) { 113 | this.returnContent = returnContent; 114 | return this; 115 | } 116 | 117 | @Override 118 | public void validate() throws TelegraphValidationException { 119 | if (accessToken == null || accessToken.isEmpty()) { 120 | throw new TelegraphValidationException("Parameter Access token is required", this); 121 | } 122 | if (path == null || path.isEmpty()) { 123 | throw new TelegraphValidationException("Parameter Path field is required", this); 124 | } 125 | if (title == null || title.length() < 1 || title.length() > 256) { 126 | throw new TelegraphValidationException("Parameter Title is missing or out of size", this); 127 | } 128 | if (content == null || content.isEmpty()) { 129 | throw new TelegraphValidationException("Parameter Content is required", this); 130 | } 131 | if (authorName != null && (authorName.length() < 0 || authorName.length() > 128)) { 132 | throw new TelegraphValidationException("Wrong size for Author Name", this); 133 | } 134 | if (authorUrl != null && (authorUrl.length() < 0 || authorUrl.length() > 512)) { 135 | throw new TelegraphValidationException("Wrong size for Author Url", this); 136 | } 137 | } 138 | 139 | @Override 140 | public Page deserializeResponse(String answer) throws TelegraphRequestException { 141 | try { 142 | TelegraphResponse result = OBJECT_MAPPER.readValue(answer, 143 | new TypeReference>(){}); 144 | if (result.getOk()) { 145 | return result.getResult(); 146 | } else { 147 | throw new TelegraphRequestException("Error editing page", result); 148 | } 149 | } catch (IOException e) { 150 | throw new TelegraphRequestException("Unable to deserialize response", e); 151 | } 152 | } 153 | 154 | @Override 155 | public String getUrlPath() { 156 | return URL_PATH; 157 | } 158 | 159 | @Override 160 | public String toString() { 161 | return "EditPage{" + 162 | "accessToken='" + accessToken + '\'' + 163 | ", path='" + path + '\'' + 164 | ", title='" + title + '\'' + 165 | ", content=" + content + 166 | ", authorName='" + authorName + '\'' + 167 | ", authorUrl='" + authorUrl + '\'' + 168 | ", returnContent=" + returnContent + 169 | '}'; 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /telegraph-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.telegram 8 | telegraph-sample 9 | jar 10 | 1.0 11 | 12 | Sample for Telegraph 13 | Samples for using Telegra.ph Api 14 | 15 | 16 | 17 | MIT License 18 | http://www.opensource.org/licenses/mit-license.php 19 | repo 20 | 21 | 22 | 23 | 24 | true 25 | UTF-8 26 | UTF-8 27 | 28 | 1.0 29 | 30 | 31 | 32 | 33 | org.telegram 34 | telegraph 35 | ${telegraph.version} 36 | 37 | 38 | 39 | 40 | ${project.basedir}/target 41 | ${project.build.directory}/classes 42 | ${project.artifactId}-${project.version} 43 | ${project.build.directory}/test-classes 44 | ${project.basedir}/src/main/java 45 | 46 | 47 | maven-clean-plugin 48 | 3.0.0 49 | 50 | 51 | clean-project 52 | clean 53 | 54 | clean 55 | 56 | 57 | 58 | 59 | 60 | maven-assembly-plugin 61 | 62 | 63 | 64 | org.telegram.bot.Main 65 | 66 | 67 | 68 | jar-with-dependencies 69 | 70 | 71 | 72 | 73 | make-assembly 74 | package 75 | 76 | single 77 | 78 | 79 | 80 | 81 | 82 | org.apache.maven.plugins 83 | maven-source-plugin 84 | 3.0.0 85 | 86 | 87 | attach-sources 88 | verify 89 | 90 | jar-no-fork 91 | 92 | 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-javadoc-plugin 98 | 2.10.3 99 | 100 | 101 | attach-javadocs 102 | site 103 | 104 | javadoc-no-fork 105 | 106 | 107 | 108 | 109 | 110 | org.apache.maven.plugins 111 | maven-jar-plugin 112 | 2.4 113 | 114 | 115 | jar 116 | package 117 | 118 | jar 119 | 120 | 121 | 122 | 123 | 124 | 125 | true 126 | lib/ 127 | org.telegram.bot.Main 128 | 129 | 130 | 131 | 132 | 133 | org.apache.maven.plugins 134 | maven-dependency-plugin 135 | 2.9 136 | 137 | 138 | copy-dependencies 139 | package 140 | 141 | copy-dependencies 142 | 143 | 144 | ${project.build.directory}/lib 145 | false 146 | false 147 | true 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | org.apache.maven.plugins 157 | maven-compiler-plugin 158 | 159 | 1.8 160 | 1.8 161 | UTF-8 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /telegraph/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.telegram 8 | telegraph 9 | 1.0 10 | jar 11 | 12 | Telegraph 13 | https://github.com/rubenlagus/Telegraph 14 | Easy to use library to interact with Telegra.ph 15 | 16 | 17 | https://github.com/rubenlagus/Telegraph/issues 18 | GitHub Issues 19 | 20 | 21 | 22 | https://github.com/rubenlagus/Telegraph 23 | scm:git:git://github.com/rubenlagus/Telegraph.git 24 | scm:git:git@github.com:rubenlagus/Telegraph.git 25 | 26 | 27 | 28 | https://travis-ci.org/rubenlagus/Telegraph 29 | Travis 30 | 31 | 32 | 33 | 34 | rberlopez@gmail.com 35 | Ruben Bermudez 36 | https://github.com/rubenlagus 37 | rubenlagus 38 | 39 | 40 | 41 | 42 | 43 | MIT License 44 | http://www.opensource.org/licenses/mit-license.php 45 | repo 46 | 47 | 48 | 49 | 50 | 51 | ossrh 52 | https://oss.sonatype.org/content/repositories/snapshots 53 | 54 | 55 | ossrh 56 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 57 | 58 | 59 | 60 | 61 | UTF-8 62 | UTF-8 63 | 1.0 64 | 4.5.2 65 | 66 | 67 | 68 | 69 | org.telegram 70 | telegraph-meta 71 | ${telegraph.version} 72 | 73 | 74 | org.apache.httpcomponents 75 | httpclient 76 | ${httpcompontents.version} 77 | 78 | 79 | 80 | 81 | ${project.basedir}/target 82 | ${project.build.directory}/classes 83 | ${project.artifactId}-${project.version} 84 | ${project.build.directory}/test-classes 85 | ${project.basedir}/src/main/java 86 | 87 | 88 | org.apache.maven.plugins 89 | maven-gpg-plugin 90 | 1.5 91 | 92 | 93 | sign-artifacts 94 | verify 95 | 96 | sign 97 | 98 | 99 | 100 | 101 | 102 | org.sonatype.plugins 103 | nexus-staging-maven-plugin 104 | 1.6.3 105 | true 106 | 107 | ossrh 108 | https://oss.sonatype.org/ 109 | true 110 | 111 | 112 | 113 | maven-clean-plugin 114 | 3.0.0 115 | 116 | 117 | clean-project 118 | clean 119 | 120 | clean 121 | 122 | 123 | 124 | 125 | 126 | maven-assembly-plugin 127 | 2.6 128 | 129 | 130 | jar-with-dependencies 131 | 132 | 133 | 134 | 135 | make-assembly 136 | package 137 | 138 | single 139 | 140 | 141 | 142 | 143 | 144 | org.apache.maven.plugins 145 | maven-source-plugin 146 | 3.0.0 147 | 148 | 149 | 150 | jar 151 | 152 | 153 | 154 | 155 | 156 | org.apache.maven.plugins 157 | maven-javadoc-plugin 158 | 2.10.3 159 | 160 | 161 | 162 | jar 163 | 164 | 165 | -Xdoclint:none 166 | 167 | 168 | 169 | 170 | 171 | org.jacoco 172 | jacoco-maven-plugin 173 | 0.7.7.201606060606 174 | 175 | 176 | 177 | prepare-agent 178 | 179 | 180 | 181 | report 182 | test 183 | 184 | report 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | org.apache.maven.plugins 194 | maven-compiler-plugin 195 | 196 | 1.8 197 | 1.8 198 | UTF-8 199 | 200 | 201 | 202 | 203 | 204 | -------------------------------------------------------------------------------- /telegraph-meta/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | org.telegram 7 | telegraph-meta 8 | 1.0 9 | jar 10 | 11 | Telegraph Meta 12 | https://github.com/rubenlagus/Telegraph 13 | Easy to use library to interact with Telegra.ph 14 | 15 | 16 | https://github.com/rubenlagus/Telegraph/issues 17 | GitHub Issues 18 | 19 | 20 | 21 | https://github.com/rubenlagus/Telegraph 22 | scm:git:git://github.com/rubenlagus/Telegraph.git 23 | scm:git:git@github.com:rubenlagus/Telegraph.git 24 | 25 | 26 | 27 | https://travis-ci.org/rubenlagus/Telegraph 28 | Travis 29 | 30 | 31 | 32 | 33 | rberlopez@gmail.com 34 | Ruben Bermudez 35 | https://github.com/rubenlagus 36 | rubenlagus 37 | 38 | 39 | 40 | 41 | 42 | MIT License 43 | http://www.opensource.org/licenses/mit-license.php 44 | repo 45 | 46 | 47 | 48 | 49 | 50 | ossrh 51 | https://oss.sonatype.org/content/repositories/snapshots 52 | 53 | 54 | ossrh 55 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 56 | 57 | 58 | 59 | 60 | UTF-8 61 | UTF-8 62 | 4.1.0 63 | 2.8.5 64 | 20160810 65 | 66 | 67 | 68 | 69 | com.google.inject 70 | guice 71 | ${guice.version} 72 | 73 | 74 | com.fasterxml.jackson.core 75 | jackson-databind 76 | ${jackson.version} 77 | 78 | 79 | com.fasterxml.jackson.core 80 | jackson-annotations 81 | ${jackson.version} 82 | 83 | 84 | org.json 85 | json 86 | ${json.version} 87 | 88 | 89 | javax.validation 90 | validation-api 91 | 1.1.0.Final 92 | 93 | 94 | 95 | 96 | ${project.basedir}/target 97 | ${project.build.directory}/classes 98 | ${project.artifactId}-${project.version} 99 | ${project.build.directory}/test-classes 100 | ${project.basedir}/src/main/java 101 | 102 | 103 | org.apache.maven.plugins 104 | maven-gpg-plugin 105 | 1.5 106 | 107 | 108 | sign-artifacts 109 | verify 110 | 111 | sign 112 | 113 | 114 | 115 | 116 | 117 | org.sonatype.plugins 118 | nexus-staging-maven-plugin 119 | 1.6.3 120 | true 121 | 122 | ossrh 123 | https://oss.sonatype.org/ 124 | true 125 | 126 | 127 | 128 | maven-clean-plugin 129 | 3.0.0 130 | 131 | 132 | clean-project 133 | clean 134 | 135 | clean 136 | 137 | 138 | 139 | 140 | 141 | maven-assembly-plugin 142 | 2.6 143 | 144 | 145 | jar-with-dependencies 146 | 147 | 148 | 149 | 150 | make-assembly 151 | package 152 | 153 | single 154 | 155 | 156 | 157 | 158 | 159 | org.apache.maven.plugins 160 | maven-source-plugin 161 | 3.0.0 162 | 163 | 164 | 165 | jar 166 | 167 | 168 | 169 | 170 | 171 | org.apache.maven.plugins 172 | maven-javadoc-plugin 173 | 2.10.3 174 | 175 | 176 | 177 | jar 178 | 179 | 180 | -Xdoclint:none 181 | 182 | 183 | 184 | 185 | 186 | org.jacoco 187 | jacoco-maven-plugin 188 | 0.7.7.201606060606 189 | 190 | 191 | 192 | prepare-agent 193 | 194 | 195 | 196 | report 197 | test 198 | 199 | report 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | org.apache.maven.plugins 209 | maven-compiler-plugin 210 | 211 | 1.8 212 | 1.8 213 | UTF-8 214 | 215 | 216 | 217 | 218 | 219 | -------------------------------------------------------------------------------- /Telegraph.ipr: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 38 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | --------------------------------------------------------------------------------