Skip to content

Commit

Permalink
Merge branch 'release-0.11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dnl-blkv committed Sep 6, 2017
2 parents d91d7da + 5878640 commit 28ec1bf
Show file tree
Hide file tree
Showing 95 changed files with 2,525 additions and 444 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/main/java/com/bunq/sdk/model/generated linguist-generated=true
16 changes: 0 additions & 16 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ApiContext apiContext = ApiContext.restore(API_CONTEXT_FILE_PATH);
to/restored from the `bunq.conf` file in the same folder with your executable.

#### Example
See [`ApiContextSaveExample.java`](./src/main/java/com/bunq/sdk/example/ApiContextSaveExample.java)
See [`ApiContextSaveExample.java`](./src/main/java/com/bunq/sdk/examples/ApiContextSaveExample.java)

The API context can then be saved with:

Expand Down Expand Up @@ -89,7 +89,7 @@ Integer paymentId = Payment.create(
```

##### Example
See [`PaymentExample.java`](./src/main/java/com/bunq/sdk/example/PaymentExample.java)
See [`PaymentExample.java`](./src/main/java/com/bunq/sdk/examples/PaymentExample.java)

#### Reading objects
Reading objects through the API requires an `ApiContext`, identifiers of all dependencies (such as
Expand All @@ -107,7 +107,7 @@ MonetaryAccount monetaryAccount = MonetaryAccount.get(
```

##### Example
See [`MonetaryAccountExample.java`](./src/main/java/com/bunq/sdk/example/MonetaryAccountExample.java)
See [`MonetaryAccountExample.java`](./src/main/java/com/bunq/sdk/examples/MonetaryAccountExample.java)

#### Updating objects
Updating objects through the API goes the same way as creating objects, except that also the object to update identifier
Expand All @@ -127,7 +127,7 @@ RequestInquiry.update(
```

##### Example
See [`RequestExample.java`](./src/main/java/com/bunq/sdk/example/RequestExample.java)
See [`RequestExample.java`](./src/main/java/com/bunq/sdk/examples/RequestExample.java)

#### Deleting objects
Deleting objects through the API requires an `ApiContext`, identifiers of all dependencies (such as User ID required for
Expand All @@ -139,7 +139,7 @@ CustomerStatementExport.delete(apiContext, userId, monetaryAccountId, customerSt
```

##### Example
See [`CustomerStatementExportExample.java`](./src/main/java/com/bunq/sdk/example/CustomerStatementExportExample.java)
See [`CustomerStatementExportExample.java`](./src/main/java/com/bunq/sdk/examples/CustomerStatementExportExample.java)

#### Listing objects
Listing objects through the API requires an `ApiContext` and identifiers of all dependencies (such as User ID required
Expand All @@ -150,11 +150,11 @@ List<User> users = User.list(apiContext);
```

##### Example
See [`UserListExample.java`](./src/main/java/com/bunq/sdk/example/UserListExample.java)
See [`UserListExample.java`](./src/main/java/com/bunq/sdk/examples/UserListExample.java)

## Running Examples
In order to make the experience of getting into bunq Java SDK smoother, we
have bundled it with example use cases (located under `./src/main/java/com/bunq/sdk/example/`).
have bundled it with example use cases (located under `./src/main/java/com/bunq/sdk/examples/`).

To run an example, please do the following:
1. In your IDE, open the example you are interested in and adjust the constants,
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.bunq.sdk'
version '0.10.0'
version '0.11.0'

apply plugin: 'java'
apply plugin: 'maven'
Expand Down
51 changes: 48 additions & 3 deletions src/main/java/com/bunq/sdk/examples/PaymentListExample.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.bunq.sdk.examples;

import com.bunq.sdk.context.ApiContext;
import com.bunq.sdk.http.BunqResponse;
import com.bunq.sdk.http.Pagination;
import com.bunq.sdk.model.generated.Payment;
import java.util.List;

Expand All @@ -9,7 +11,26 @@
*/
public class PaymentListExample {

/**
* Path to the API Context file.
*/
private static final String API_CONTEXT_FILE_PATH = "bunq.conf";

/**
* Message constants.
*/
private static final String MESSAGE_LATEST_PAGE_IDS = "Latest page IDs: ";
private static final String MESSAGE_SECOND_LATEST_PAGE_IDS = "Second latest page IDs: ";
private static final String MESSAGE_NO_PRIOR_PAYMENTS_FOUND = "No prior payments found!";

/**
* Size of each page of payments listing.
*/
private static final int PAGE_SIZE = 3;

/**
* Constants to be changed to run the example.
*/
private static final int USER_ITEM_ID = 0; // Put your user ID here
private static final int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here

Expand All @@ -18,14 +39,38 @@ public class PaymentListExample {
*/
public static void main(String[] args) {
ApiContext apiContext = ApiContext.restore(API_CONTEXT_FILE_PATH);
List<Payment> payments = Payment.list(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID)
.getValue();
Pagination paginationCountOnly = new Pagination();
paginationCountOnly.setCount(PAGE_SIZE);
BunqResponse<List<Payment>> paymentListResponse = Payment.list(
apiContext,
USER_ITEM_ID,
MONETARY_ACCOUNT_ITEM_ID,
paginationCountOnly.getUrlParamsCountOnly()
);
List<Payment> payments = paymentListResponse.getValue();

System.out.println(MESSAGE_LATEST_PAGE_IDS);
printPayments(payments);

Pagination pagination = paymentListResponse.getPagination();

if (pagination.hasPreviousPage()) {
System.out.println(MESSAGE_SECOND_LATEST_PAGE_IDS);
List<Payment> previousPayments = Payment.list(
apiContext,
USER_ITEM_ID,
MONETARY_ACCOUNT_ITEM_ID,
pagination.getUrlParamsPreviousPage()
).getValue();
printPayments(previousPayments);
} else {
System.out.println(MESSAGE_NO_PRIOR_PAYMENTS_FOUND);
}
}

private static void printPayments(List<Payment> payments) {
for (Payment payment : payments) {
System.out.println(payment);
System.out.println(payment.getId());
}
}

Expand Down
34 changes: 25 additions & 9 deletions src/main/java/com/bunq/sdk/http/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;
import org.apache.http.Header;
import org.apache.http.HttpHost;
Expand All @@ -32,6 +35,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
Expand Down Expand Up @@ -75,7 +79,7 @@ public class ApiClient {
/**
* Prefix for bunq's own headers.
*/
private static final String USER_AGENT_BUNQ = "bunq-sdk-java/0.10.0";
private static final String USER_AGENT_BUNQ = "bunq-sdk-java/0.11.0";
private static final String LANGUAGE_EN_US = "en_US";
private static final String REGION_NL_NL = "nl_NL";
private static final String GEOLOCATION_ZERO = "0 0 0 0 000";
Expand Down Expand Up @@ -135,13 +139,24 @@ public BunqResponseRaw post(String uri, byte[] requestBodyBytes,
CloseableHttpResponse response = executeRequest(httpPost, customHeaders);

return createBunqResponseRaw(response);
} catch (IOException exception) {
} catch (IOException | URISyntaxException exception) {
throw new UncaughtExceptionError(exception);
}
}

private URI determineFullUri(String uri) {
return URI.create(apiContext.getBaseUri().toString() + uri);
private URI determineFullUri(String uri) throws URISyntaxException {
return determineFullUri(uri, new HashMap<>());
}

private URI determineFullUri(String uri, Map<String, String> params) throws URISyntaxException {
URIBuilder builder = new URIBuilder(apiContext.getBaseUri().toString() + uri);
SortedMap<String, String> paramsSorted = new TreeMap<>(params);

for (Map.Entry<String, String> param : paramsSorted.entrySet()) {
builder.addParameter(param.getKey(), param.getValue());
}

return builder.build();
}

private CloseableHttpResponse executeRequest(HttpUriRequest request,
Expand Down Expand Up @@ -279,13 +294,14 @@ private static Map<String, String> getHeadersMap(CloseableHttpResponse response)
*
* @return The raw response of the GET request.
*/
public BunqResponseRaw get(String uri, Map<String, String> customHeaders) {
public BunqResponseRaw get(String uri, Map<String, String> params,
Map<String, String> customHeaders) {
try {
HttpGet httpGet = new HttpGet(determineFullUri(uri));
HttpGet httpGet = new HttpGet(determineFullUri(uri, params));
CloseableHttpResponse response = executeRequest(httpGet, customHeaders);

return createBunqResponseRaw(response);
} catch (IOException exception) {
} catch (IOException | URISyntaxException exception) {
throw new UncaughtExceptionError(exception);
}
}
Expand All @@ -303,7 +319,7 @@ public BunqResponseRaw put(String uri, byte[] requestBodyBytes,
CloseableHttpResponse response = executeRequest(httpPut, customHeaders);

return createBunqResponseRaw(response);
} catch (IOException exception) {
} catch (IOException | URISyntaxException exception) {
throw new UncaughtExceptionError(exception);
}
}
Expand All @@ -319,7 +335,7 @@ public BunqResponseRaw delete(String uri, Map<String, String> customHeaders) {
CloseableHttpResponse response = executeRequest(httpDelete, customHeaders);

return createBunqResponseRaw(response);
} catch (IOException exception) {
} catch (IOException | URISyntaxException exception) {
throw new UncaughtExceptionError(exception);
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/bunq/sdk/http/BunqResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ public class BunqResponse<T> {

private T value;
private Map<String, String> headers;
private Pagination pagination;

public BunqResponse(T value, Map<String, String> headers) {
this(value, headers, null);
}

public BunqResponse(T value, Map<String, String> headers, Pagination pagination) {
this.value = value;
this.headers = headers;
this.pagination = pagination;
}

public T getValue() {
Expand All @@ -20,4 +26,8 @@ public Map<String, String> getHeaders() {
return headers;
}

public Pagination getPagination() {
return pagination;
}

}
Loading

0 comments on commit 28ec1bf

Please sign in to comment.