Removed Pastebin code (replaced by Privatebin code).

This commit is contained in:
Christian P. MOMON 2021-04-09 01:20:20 +02:00
parent b5cfa87aa9
commit 4d9a09b0e1
8 changed files with 0 additions and 881 deletions

View File

@ -1,52 +0,0 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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 <http://www.gnu.org/licenses/>
*/
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, ""));
}
}
}

View File

@ -1,55 +0,0 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View File

@ -1,55 +0,0 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View File

@ -1,51 +0,0 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View File

@ -1,493 +0,0 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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 <http://www.gnu.org/licenses/>
*/
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<NameValuePair> 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<NameValuePair> 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<NameValuePair> params, final String name, final String value)
{
if (value != null)
{
params.add(new BasicNameValuePair(name, value));
}
}
}

View File

@ -1,80 +0,0 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
*
* 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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View File

@ -1,53 +0,0 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View File

@ -1,42 +0,0 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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 <http://www.gnu.org/licenses/>
*/
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));
}
}