Skip to content

Commit

Permalink
[chore] format all files using the netbeans command
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimlawal committed Sep 23, 2017
1 parent 0f5d671 commit 687950d
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 161 deletions.
14 changes: 7 additions & 7 deletions Keys.json
@@ -1,9 +1,9 @@
{
"API_KEYS":{
"KEY_IN_USE": "sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"TEST_SECRET_KEY": "sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"TEST_PUBLIC_KEY": "pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"LIVE_SECRET_KEY": "sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"LIVE_PUBLIC_KEY": "pk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
"API_KEYS": {
"KEY_IN_USE": "sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"TEST_SECRET_KEY": "sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"TEST_PUBLIC_KEY": "pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"LIVE_SECRET_KEY": "sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"LIVE_PUBLIC_KEY": "pk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
}
9 changes: 4 additions & 5 deletions src/me/iyanuadelekan/paystackjava/constants/Definitions.java
Expand Up @@ -6,12 +6,11 @@
public class Definitions {

/**
* The following are URL definitions for the Paystack API.
* All URLs are RESTful endpoints and as such modification of any
* of these URL resources will lead to problems with querying the Paystack API.
* Only modify if you know what you are doing.
* The following are URL definitions for the Paystack API. All URLs are
* RESTful endpoints and as such modification of any of these URL resources
* will lead to problems with querying the Paystack API. Only modify if you
* know what you are doing.
*/

private final static String BASE_API_ENDPOINT = "https://api.paystack.co";

public static final String PAYSTACK_INLINE_PAYSTACK_STANDARD = BASE_API_ENDPOINT + "/transaction/initialize";
Expand Down
48 changes: 27 additions & 21 deletions src/me/iyanuadelekan/paystackjava/core/ApiConnection.java
Expand Up @@ -15,7 +15,7 @@
*/
public class ApiConnection {

private String url;
private String url;
private String apiKey;

/**
Expand All @@ -37,14 +37,15 @@ public ApiConnection(String url) {

/**
* Connects to and queries Paystack API with POST
*
* @param query - APIQuery containing parameters to send
* @return - JSONObject containing API response
*/
public JSONObject connectAndQuery(ApiQuery query) {
try {
HttpResponse<JsonNode> queryForResponse = Unirest.post(url)
.header("Accept","application/json")
.header("Authorization","Bearer " + apiKey)
.header("Accept", "application/json")
.header("Authorization", "Bearer " + apiKey)
.fields(query.getParams())
.asJson();
return queryForResponse.getBody().getObject();
Expand All @@ -54,17 +55,17 @@ public JSONObject connectAndQuery(ApiQuery query) {
return null;
}


/**
* Connects to and queries API with POST
*
* @param query - HashMap containing parameters to send
* @return - JSONObject containing API response
*/
public JSONObject connectAndQuery(HashMap<String,Object> query) {
public JSONObject connectAndQuery(HashMap<String, Object> query) {
try {
HttpResponse<JsonNode> queryForResponse = Unirest.post(url)
.header("Accept","application/json")
.header("Authorization","Bearer " + apiKey)
.header("Accept", "application/json")
.header("Authorization", "Bearer " + apiKey)
.fields(query)
.asJson();
return queryForResponse.getBody().getObject();
Expand All @@ -76,13 +77,14 @@ public JSONObject connectAndQuery(HashMap<String,Object> query) {

/**
* Used to send a GET request to the Paystack API
*
* @return - JSONObject containing the API response
*/
public JSONObject connectAndQueryWithGet(){
public JSONObject connectAndQueryWithGet() {
try {
HttpResponse<JsonNode> queryForResponse = Unirest.get(url)
.header("Accept","application/json")
.header("Authorization","Bearer " + apiKey)
.header("Accept", "application/json")
.header("Authorization", "Bearer " + apiKey)
.asJson();
return queryForResponse.getBody().getObject();
} catch (UnirestException e) {
Expand All @@ -93,14 +95,15 @@ public JSONObject connectAndQueryWithGet(){

/**
* Used to send a GET request to the Paystack API
*
* @param query - APIQuery containing parameters to send
* @return - JSONObject containing API response
*/
public JSONObject connectAndQueryWithGet(ApiQuery query){
public JSONObject connectAndQueryWithGet(ApiQuery query) {
try {
HttpResponse<JsonNode> queryForResponse = Unirest.get(url)
.header("Accept","application/json")
.header("Authorization","Bearer " + apiKey)
.header("Accept", "application/json")
.header("Authorization", "Bearer " + apiKey)
.queryString(query.getParams())
.asJson();
return queryForResponse.getBody().getObject();
Expand All @@ -112,14 +115,15 @@ public JSONObject connectAndQueryWithGet(ApiQuery query){

/**
* Used to send a GET request to the Paystack API
*
* @param query - HashMap containing parameters to send
* @return - JSONObject containing API response
*/
public JSONObject connectAndQueryWithGet(HashMap<String,Object> query) {
public JSONObject connectAndQueryWithGet(HashMap<String, Object> query) {
try {
HttpResponse<JsonNode> queryForResponse = Unirest.get(url)
.header("Accept","application/json")
.header("Authorization","Bearer " + apiKey)
.header("Accept", "application/json")
.header("Authorization", "Bearer " + apiKey)
.queryString(query)
.asJson();
return queryForResponse.getBody().getObject();
Expand All @@ -131,14 +135,15 @@ public JSONObject connectAndQueryWithGet(HashMap<String,Object> query) {

/**
* Used to send a PUT request to the Paystack API
*
* @param query - APIQuery containing parameters to send
* @return - JSONObject containing API response
*/
public JSONObject connectAndQueryWithPut(ApiQuery query) {
try {
HttpResponse<JsonNode> queryForResponse = Unirest.put(url)
.header("Accept","application/json")
.header("Authorization","Bearer " + apiKey)
.header("Accept", "application/json")
.header("Authorization", "Bearer " + apiKey)
.fields(query.getParams())
.asJson();
return queryForResponse.getBody().getObject();
Expand All @@ -150,14 +155,15 @@ public JSONObject connectAndQueryWithPut(ApiQuery query) {

/**
* Used to send a PUT request to the Paystack API
*
* @param query - HashMap containing parameters to send
* @return - JSONObject containing API response
*/
public JSONObject connectAndQueryWithPut(HashMap<String,Object> query) {
public JSONObject connectAndQueryWithPut(HashMap<String, Object> query) {
try {
HttpResponse<JsonNode> queryForResponse = Unirest.get(url)
.header("Accept","application/json")
.header("Authorization","Bearer " + apiKey)
.header("Accept", "application/json")
.header("Authorization", "Bearer " + apiKey)
.queryString(query)
.asJson();
return queryForResponse.getBody().getObject();
Expand Down
14 changes: 8 additions & 6 deletions src/me/iyanuadelekan/paystackjava/core/ApiQuery.java
Expand Up @@ -7,29 +7,31 @@
*/
public class ApiQuery {

private HashMap<String,Object> queryMap;
private HashMap<String, Object> queryMap;

/**
* Initializes a new query map
*/
public ApiQuery(){
this.queryMap = new HashMap<String,Object>();
public ApiQuery() {
this.queryMap = new HashMap<String, Object>();
}

/**
* Used to add a parameter to the query map
*
* @param key
* @param value
*/
public void putParams(String key, Object value){
this.queryMap.put(key,value);
public void putParams(String key, Object value) {
this.queryMap.put(key, value);
}

/**
* Used to get all parameters within the query map
*
* @return - HashMap containin g query parameters
*/
public HashMap <String,Object> getParams(){
public HashMap<String, Object> getParams() {
return this.queryMap;
}

Expand Down
42 changes: 26 additions & 16 deletions src/me/iyanuadelekan/paystackjava/core/Customers.java
Expand Up @@ -14,16 +14,18 @@ public class Customers {

/**
* Used to create a new customer
*
* @param queryMap
* @return JSONObject
*/
public JSONObject createCustomer(HashMap<String,Object> queryMap){
public JSONObject createCustomer(HashMap<String, Object> queryMap) {
this.apiConnection = new ApiConnection(Definitions.PAYSTACK_CUSTOMERS_CREATE_CUSTOMER);
return this.apiConnection.connectAndQuery(queryMap);
}

/**
* Used to create a new customer
*
* @param query
* @return JSONObject
*/
Expand All @@ -34,6 +36,7 @@ public JSONObject createCustomer(ApiQuery query) {

/**
* Used to create a new customer
*
* @param email
* @param firstName
* @param lastName
Expand All @@ -42,31 +45,33 @@ public JSONObject createCustomer(ApiQuery query) {
* @return JSONObject
*/
public JSONObject createCustomer(String email, String firstName, String lastName,
String phone, Object metadata) {
String phone, Object metadata) {
this.apiConnection = new ApiConnection(Definitions.PAYSTACK_CUSTOMERS_CREATE_CUSTOMER);
ApiQuery apiQuery = new ApiQuery();

apiQuery.putParams("email",email);
apiQuery.putParams("first_name",firstName);
apiQuery.putParams("last_name",lastName);
apiQuery.putParams("phone",phone);
apiQuery.putParams("metadata",metadata);
apiQuery.putParams("email", email);
apiQuery.putParams("first_name", firstName);
apiQuery.putParams("last_name", lastName);
apiQuery.putParams("phone", phone);
apiQuery.putParams("metadata", metadata);

return this.apiConnection.connectAndQuery(apiQuery);
}

/**
* Used to get a list of customers
*
* @param queryMap
* @return JSONObject
*/
public JSONObject listCustomers(HashMap<String,Object> queryMap) {
public JSONObject listCustomers(HashMap<String, Object> queryMap) {
this.apiConnection = new ApiConnection(Definitions.PAYSTACK_CUSTOMERS_LIST_CUSTOMERS);
return this.apiConnection.connectAndQueryWithGet(queryMap);
}

/**
* Used to get a list of customers
*
* @param query
* @return JSONObject
*/
Expand All @@ -77,6 +82,7 @@ public JSONObject listCustomers(ApiQuery query) {

/**
* Used to get a list of customers
*
* @param perPage
* @param page
* @return JSONObject
Expand All @@ -85,14 +91,15 @@ public JSONObject listCustomers(int perPage, int page) {
this.apiConnection = new ApiConnection(Definitions.PAYSTACK_CUSTOMERS_LIST_CUSTOMERS);

ApiQuery apiQuery = new ApiQuery();
apiQuery.putParams("perPage",perPage);
apiQuery.putParams("page",page);
apiQuery.putParams("perPage", perPage);
apiQuery.putParams("page", page);

return this.apiConnection.connectAndQueryWithGet(apiQuery);
}

/**
* Used to get a customer
*
* @param idOrCustomerCode
* @return JSONObject
*/
Expand All @@ -103,17 +110,19 @@ public JSONObject fetchCustomer(String idOrCustomerCode) {

/**
* Used to update a customer
*
* @param queryMap
* @param idOrCustomerCode
* @return JSONObject
*/
public JSONObject updateCustomer(HashMap<String,Object> queryMap, String idOrCustomerCode) {
public JSONObject updateCustomer(HashMap<String, Object> queryMap, String idOrCustomerCode) {
this.apiConnection = new ApiConnection(Definitions.PAYSTACK_CUSTOMERS_UPDATE_CUSTOMER + idOrCustomerCode);
return this.apiConnection.connectAndQueryWithPut(queryMap);
}

/**
* Used to update a customer
*
* @param query
* @param idOrCustomerCode
* @return JSONObject
Expand All @@ -125,6 +134,7 @@ public JSONObject updateCustomer(ApiQuery query, String idOrCustomerCode) {

/**
* Used to update a customer
*
* @param idOrCustomerCode
* @param email
* @param firstName
Expand All @@ -134,14 +144,14 @@ public JSONObject updateCustomer(ApiQuery query, String idOrCustomerCode) {
* @return JSONObject
*/
public JSONObject updateCustomer(String idOrCustomerCode, String email, String firstName, String lastName,
String phone, Object metadata) {
String phone, Object metadata) {
this.apiConnection = new ApiConnection(Definitions.PAYSTACK_CUSTOMERS_UPDATE_CUSTOMER.concat(idOrCustomerCode));

ApiQuery apiQuery = new ApiQuery();
apiQuery.putParams("first_name",firstName);
apiQuery.putParams("last_name",lastName);
apiQuery.putParams("phone",phone);
apiQuery.putParams("metadata",metadata);
apiQuery.putParams("first_name", firstName);
apiQuery.putParams("last_name", lastName);
apiQuery.putParams("phone", phone);
apiQuery.putParams("metadata", metadata);

return this.apiConnection.connectAndQueryWithPut(apiQuery);
}
Expand Down

0 comments on commit 687950d

Please sign in to comment.