83 lines
2.7 KiB
Java
83 lines
2.7 KiB
Java
package netneutrality.http;
|
|
/*
|
|
* Copyright (c) anthorob
|
|
*
|
|
* https://xtremcommunity.com/
|
|
* https://discord.gg/CdFcyQ
|
|
*/
|
|
|
|
import netneutrality.db.entities.OSellyOrder;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Base64;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class Selly {
|
|
|
|
private final byte[] encodedAuth;
|
|
|
|
public Selly(String email, String apiKey) {
|
|
String concat = email + ":" + apiKey;
|
|
encodedAuth = Base64.getEncoder().encode(concat.getBytes());
|
|
}
|
|
|
|
public Map<String, OSellyOrder> getOrders() {
|
|
WebModule sellyApi = new WebModule("https://selly.gg/api/v2/orders");
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, OSellyOrder> orders = new HashMap<>();
|
|
headers.put("Authorization", "Basic " + new String(encodedAuth));
|
|
JSONArray response = null;
|
|
try {
|
|
sellyApi.request(headers);
|
|
response = sellyApi.getAsArray();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
|
|
for (int i = 0; i < response.length(); i++) {
|
|
JSONObject order = response.getJSONObject(i);
|
|
orders.put(order.getString("id"), new OSellyOrder(order.getString("id"), order.getString("product_id"), order.getString("email"), order.getString("ip_address"),
|
|
Float.parseFloat(order.getString("value")), order.getString("currency"), order.getString("gateway"), order.getInt("risk_level"), order.getInt("status"),
|
|
order.getInt("crypto_value"), order.getString("crypto_address"), Float.parseFloat(order.getString("usd_value")), order.getString("created_at")));
|
|
}
|
|
|
|
|
|
return orders;
|
|
}
|
|
|
|
public JSONObject getOrderById(String id) {
|
|
WebModule order = new WebModule("https://selly.gg/api/v2/orders/" + id);
|
|
Map<String, String> headers = new HashMap<>();
|
|
headers.put("Authorization", "Basic " + new String(encodedAuth));
|
|
JSONObject response = null;
|
|
try {
|
|
order.request(headers);
|
|
response = order.getAsObject();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
public JSONArray getProducts() {
|
|
WebModule orders = new WebModule("https://selly.gg/api/v2/products");
|
|
Map<String, String> headers = new HashMap<>();
|
|
headers.put("Authorization", "Basic " + new String(encodedAuth));
|
|
JSONArray response = null;
|
|
|
|
try {
|
|
orders.request(headers);
|
|
response = orders.getAsArray();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return response;
|
|
}
|
|
}
|