From 4d9a09b0e119e9d56839992c866d899e58d8e876 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 9 Apr 2021 01:20:20 +0200 Subject: [PATCH] Removed Pastebin code (replaced by Privatebin code). --- .../april/hebdobot/pastebin/APIException.java | 52 -- .../april/hebdobot/pastebin/Expiration.java | 55 -- src/org/april/hebdobot/pastebin/Format.java | 55 -- src/org/april/hebdobot/pastebin/Option.java | 51 -- .../hebdobot/pastebin/PastebinClient.java | 493 ------------------ .../hebdobot/pastebin/PastebinSettings.java | 80 --- src/org/april/hebdobot/pastebin/Private.java | 53 -- .../hebdobot/pastebin/PastebinClientTest.java | 42 -- 8 files changed, 881 deletions(-) delete mode 100644 src/org/april/hebdobot/pastebin/APIException.java delete mode 100644 src/org/april/hebdobot/pastebin/Expiration.java delete mode 100644 src/org/april/hebdobot/pastebin/Format.java delete mode 100644 src/org/april/hebdobot/pastebin/Option.java delete mode 100644 src/org/april/hebdobot/pastebin/PastebinClient.java delete mode 100644 src/org/april/hebdobot/pastebin/PastebinSettings.java delete mode 100644 src/org/april/hebdobot/pastebin/Private.java delete mode 100644 test/org/april/hebdobot/pastebin/PastebinClientTest.java diff --git a/src/org/april/hebdobot/pastebin/APIException.java b/src/org/april/hebdobot/pastebin/APIException.java deleted file mode 100644 index 136d434..0000000 --- a/src/org/april/hebdobot/pastebin/APIException.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (C) 2017-2018 Christian Pierre MOMON - * Copyright (C) 2011-2013 Nicolas Vinot - * - * This file is part of (April) Hebdobot. - * - * Hebdobot is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Hebdobot is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Hebdobot. If not, see - */ -package org.april.hebdobot.pastebin; - -public class APIException extends Exception -{ - private static final long serialVersionUID = 1852384776503676687L; - - /** - * Instantiates a new API exception. - * - * @param message - * the message - */ - private APIException(final String message) - { - super(message); - } - - /** - * Throw if error. - * - * @param content - * the content - * @throws APIException - * the API exception - */ - public static void throwIfError(final String content) throws APIException - { - if (content.contains(PastebinClient.API_ERROR)) - { - throw new APIException(content.replaceFirst(PastebinClient.API_ERROR, "")); - } - } -} diff --git a/src/org/april/hebdobot/pastebin/Expiration.java b/src/org/april/hebdobot/pastebin/Expiration.java deleted file mode 100644 index c9fd15b..0000000 --- a/src/org/april/hebdobot/pastebin/Expiration.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (C) 2017-2018 Christian Pierre MOMON - * Copyright (C) 2011-2013 Nicolas Vinot - * - * This file is part of (April) Hebdobot. - * - * Hebdobot is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Hebdobot is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Hebdobot. If not, see - */ -package org.april.hebdobot.pastebin; - -/** - * The Enum Expiration. - */ -public enum Expiration -{ - NEVER(null), - MINUTE_10("10M"), - HOUR_1("1H"), - DAY_1("1D"), - MONTH_1("1M"); - - private final String value; - - /** - * Instantiates a new expiration. - * - * @param value - * the value - */ - private Expiration(final String value) - { - this.value = value; - } - - /** - * Gets the value. - * - * @return the value - */ - public String getValue() - { - return this.value; - } -} diff --git a/src/org/april/hebdobot/pastebin/Format.java b/src/org/april/hebdobot/pastebin/Format.java deleted file mode 100644 index 8d0ef55..0000000 --- a/src/org/april/hebdobot/pastebin/Format.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (C) 2017-2018 Christian Pierre MOMON - * Copyright (C) 2011-2013 Nicolas Vinot - * - * This file is part of (April) Hebdobot. - * - * Hebdobot is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Hebdobot is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Hebdobot. If not, see - */ -package org.april.hebdobot.pastebin; - -/** - * The Enum Format. - */ -public enum Format -{ - NONE(null), - C("c"), - CPP("cpp"), - JAVA("java"), - JAVA_5("java5"); - - private final String value; - - /** - * Instantiates a new format. - * - * @param value - * the value - */ - private Format(final String value) - { - this.value = value; - } - - /** - * Gets the value. - * - * @return the value - */ - public String getValue() - { - return this.value; - } -} diff --git a/src/org/april/hebdobot/pastebin/Option.java b/src/org/april/hebdobot/pastebin/Option.java deleted file mode 100644 index 1c9960f..0000000 --- a/src/org/april/hebdobot/pastebin/Option.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright (C) 2017-2018 Christian Pierre MOMON - * Copyright (C) 2011-2013 Nicolas Vinot - * - * This file is part of (April) Hebdobot. - * - * Hebdobot is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Hebdobot is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Hebdobot. If not, see - */ -package org.april.hebdobot.pastebin; - -/** - * The Enum Option. - */ -public enum Option -{ - PASTE("paste"); - - private final String value; - - /** - * Instantiates a new option. - * - * @param value - * the value - */ - private Option(final String value) - { - this.value = value; - } - - /** - * Gets the value. - * - * @return the value - */ - public String getValue() - { - return this.value; - } -} diff --git a/src/org/april/hebdobot/pastebin/PastebinClient.java b/src/org/april/hebdobot/pastebin/PastebinClient.java deleted file mode 100644 index ffa6c6f..0000000 --- a/src/org/april/hebdobot/pastebin/PastebinClient.java +++ /dev/null @@ -1,493 +0,0 @@ -/** - * Copyright (C) 2017-2018 Christian Pierre MOMON - * Copyright (C) 2011-2013 Nicolas Vinot - * - * This file is part of (April) Hebdobot. - * - * Hebdobot is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Hebdobot is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Hebdobot. If not, see - */ -package org.april.hebdobot.pastebin; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; -import java.util.LinkedList; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.NameValuePair; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.HttpClient; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.message.BasicNameValuePair; -import org.apache.http.protocol.HTTP; -import org.april.hebdobot.HebdobotException; - -/** - * The Class PastebinClient. - */ -public class PastebinClient -{ - private static final String API_LOGIN_URL = "https://pastebin.com/api/api_login.php"; - private static final String API_POST_URL = "https://pastebin.com/api/api_post.php"; - - private static final String API_DEV_KEY = "api_dev_key"; - private static final String API_USER_KEY = "api_user_key"; - private static final String API_USER_NAME = "api_user_name"; - private static final String API_USER_PASSWORD = "api_user_password"; - private static final String API_OPTION = "api_option"; - private static final String API_PASTE_PRIVATE = "api_paste_private"; - private static final String API_PASTE_NAME = "api_paste_name"; - private static final String API_PASTE_EXPIRATION = "api_paste_expire_date"; - private static final String API_PASTE_FORMAT = "api_paste_format"; - private static final String API_PASTE_CODE = "api_paste_code"; - public static final String API_ERROR = "Bad API request,"; - - private String apiKey; - private String apiUserKey; - private HttpClient httpClient; - - /** - * Instantiates a new pastebin client. - * - * @param apiKey - * the api key - */ - public PastebinClient(final String apiKey) - { - this.apiKey = apiKey; - this.httpClient = new DefaultHttpClient(); - } - - /** - * Login. - * - * @param name - * the name - * @param password - * the password - * @throws HebdobotException - * the hebdobot exception - */ - public void login(final String name, final String password) throws HebdobotException - { - try - { - final List params = new LinkedList<>(); - setParameter(params, API_DEV_KEY, this.apiKey); - setParameter(params, API_USER_NAME, name); - setParameter(params, API_USER_PASSWORD, password); - - final HttpPost request = new HttpPost(API_LOGIN_URL); - request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); - - final HttpResponse response = this.httpClient.execute(request); - final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - APIException.throwIfError(content); - this.apiUserKey = content; - } - catch (UnsupportedEncodingException exception) - { - throw new HebdobotException(exception); - } - catch (ClientProtocolException exception) - { - throw new HebdobotException(exception); - } - catch (IOException exception) - { - throw new HebdobotException(exception); - } - catch (APIException exception) - { - throw new HebdobotException(exception); - } - } - - /** - * Paste. - * - * @param code - * the code - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code) throws HebdobotException - { - String result; - - result = this.paste(code, null, Format.NONE, Private.PUBLIC, Expiration.DAY_1); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param expiration - * the expiration - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final Expiration expiration) throws HebdobotException - { - String result; - - result = this.paste(code, null, Format.NONE, Private.PUBLIC, expiration); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param format - * the format - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final Format format) throws HebdobotException - { - String result; - - result = this.paste(code, null, format, Private.PUBLIC, Expiration.DAY_1); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param format - * the format - * @param expiration - * the expiration - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final Format format, final Expiration expiration) throws HebdobotException - { - String result; - - result = this.paste(code, null, format, Private.PUBLIC, expiration); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param format - * the format - * @param privat - * the privat - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final Format format, final Private privat) throws HebdobotException - { - String result; - - result = this.paste(code, null, format, privat, Expiration.DAY_1); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param format - * the format - * @param privat - * the privat - * @param expiration - * the expiration - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final Format format, final Private privat, final Expiration expiration) throws HebdobotException - { - String result; - - result = this.paste(code, null, format, privat, expiration); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param privat - * the privat - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final Private privat) throws HebdobotException - { - String result; - - result = this.paste(code, null, Format.NONE, privat, Expiration.DAY_1); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param privat - * the privat - * @param expiration - * the expiration - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final Private privat, final Expiration expiration) throws HebdobotException - { - String result; - - result = this.paste(code, null, Format.NONE, privat, expiration); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param name - * the name - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final String name) throws HebdobotException - { - String result; - - result = this.paste(code, name, Format.NONE, Private.PUBLIC, Expiration.DAY_1); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param name - * the name - * @param format - * the format - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final String name, final Format format) throws HebdobotException - { - String result; - - result = this.paste(code, name, format, Private.PUBLIC, Expiration.DAY_1); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param name - * the name - * @param format - * the format - * @param expiration - * the expiration - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final String name, final Format format, final Expiration expiration) throws HebdobotException - { - String result; - - result = this.paste(code, name, format, Private.PUBLIC, expiration); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param name - * the name - * @param format - * the format - * @param privat - * the privat - * @return the string - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final String name, final Format format, final Private privat) throws HebdobotException - { - String result; - - result = this.paste(code, name, format, privat, Expiration.DAY_1); - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param name - * the name - * @param format - * the format - * @param privat - * the privat - * @param expiration - * the expiration - * @return the pastebin URL - * @throws HebdobotException - * the exception - */ - public String paste(final String code, final String name, final Format format, final Private privat, final Expiration expiration) - throws HebdobotException - { - String result; - - try - { - List params = new LinkedList<>(); - setParameter(params, API_DEV_KEY, this.apiKey); - setParameter(params, API_USER_KEY, this.apiUserKey); - setParameter(params, API_OPTION, Option.PASTE.getValue()); - setParameter(params, API_PASTE_PRIVATE, privat.getValue()); - setParameter(params, API_PASTE_NAME, name); - setParameter(params, API_PASTE_EXPIRATION, expiration.getValue()); - setParameter(params, API_PASTE_FORMAT, format.getValue()); - setParameter(params, API_PASTE_CODE, code); - - final HttpPost request = new HttpPost(API_POST_URL); - request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); - - final HttpResponse response = this.httpClient.execute(request); - result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - APIException.throwIfError(result); - } - catch (UnsupportedEncodingException exception) - { - throw new HebdobotException(exception); - } - catch (ClientProtocolException exception) - { - throw new HebdobotException(exception); - } - catch (IOException exception) - { - throw new HebdobotException(exception); - } - catch (APIException exception) - { - throw new HebdobotException(exception); - } - - // - return result; - } - - /** - * Paste. - * - * @param code - * the code - * @param name - * the name - * @param privat - * the privat - * @return the pastebin URL - * @throws HebdobotException - * the hebdobot exception - */ - public String paste(final String code, final String name, final Private privat) throws HebdobotException - { - String result; - - result = this.paste(code, name, Format.NONE, privat, Expiration.DAY_1); - - // - return result; - } - - /** - * Sets the parameter. - * - * @param params - * the params - * @param name - * the name - * @param value - * the value - */ - private static void setParameter(final List params, final String name, final String value) - { - if (value != null) - { - params.add(new BasicNameValuePair(name, value)); - } - } -} diff --git a/src/org/april/hebdobot/pastebin/PastebinSettings.java b/src/org/april/hebdobot/pastebin/PastebinSettings.java deleted file mode 100644 index fd7874b..0000000 --- a/src/org/april/hebdobot/pastebin/PastebinSettings.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (C) 2017-2018 Christian Pierre MOMON - * - * This file is part of (April) Hebdobot. - * - * Hebdobot is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Hebdobot is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Hebdobot. If not, see - */ -package org.april.hebdobot.pastebin; - -import org.apache.commons.lang3.StringUtils; - -/** - * The Class PatebinSettings. - */ -public class PastebinSettings -{ - private String apiKey; - - /** - * Instantiates a new pastebin settings. - */ - public PastebinSettings() - { - this.apiKey = null; - } - - /** - * Instantiates a new pastebin settings. - * - * @param apiKey - * the api key - */ - public PastebinSettings(final String apiKey) - { - this.apiKey = apiKey; - } - - public String getApiKey() - { - return this.apiKey; - } - - /** - * Checks if is valid. - * - * @return true, if is valid - */ - public boolean isValid() - { - boolean result; - - if ((StringUtils.isBlank(this.apiKey)) || (StringUtils.containsOnly(this.apiKey, 'X'))) - { - result = false; - } - else - { - result = true; - } - - // - return result; - } - - public void setApiKey(final String apiKey) - { - this.apiKey = apiKey; - } -} diff --git a/src/org/april/hebdobot/pastebin/Private.java b/src/org/april/hebdobot/pastebin/Private.java deleted file mode 100644 index 0fe3620..0000000 --- a/src/org/april/hebdobot/pastebin/Private.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (C) 2017-2018 Christian Pierre MOMON - * Copyright (C) 2011-2013 Nicolas Vinot - * - * This file is part of (April) Hebdobot. - * - * Hebdobot is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Hebdobot is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Hebdobot. If not, see - */ -package org.april.hebdobot.pastebin; - -/** - * The Enum Private. - */ -public enum Private -{ - PUBLIC("0"), - UNLISTED("1"), - PRIVATE("2"); - - private String value; - - /** - * Instantiates a new private. - * - * @param value - * the value - */ - private Private(final String value) - { - this.value = value; - } - - /** - * Gets the value. - * - * @return the value - */ - String getValue() - { - return this.value; - } -} diff --git a/test/org/april/hebdobot/pastebin/PastebinClientTest.java b/test/org/april/hebdobot/pastebin/PastebinClientTest.java deleted file mode 100644 index c0f5aef..0000000 --- a/test/org/april/hebdobot/pastebin/PastebinClientTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (C) 2017-2018 Christian Pierre MOMON - * Copyright (C) 2011-2013 Nicolas Vinot - * - * This file is part of (April) Hebdobot. - * - * Hebdobot is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Hebdobot is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Hebdobot. If not, see - */ -package org.april.hebdobot.pastebin; - -import org.junit.Test; - -/** - * The Class PastebinClientTest. - */ -public class PastebinClientTest -{ - private final PastebinClient client = new PastebinClient("b95ea42d539ec9dca02a7da1f5b229c7"); - - /** - * Test paste. - * - * @throws Exception - * the exception - */ - @Test - public void testPaste() throws Exception - { - System.out.println(this.client.paste("ééé", Expiration.MINUTE_10)); - } -}