Skip to content

Commit 28ec1bf

Browse files
committed
Merge branch 'release-0.11.0'
2 parents d91d7da + 5878640 commit 28ec1bf

File tree

95 files changed

+2525
-444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+2525
-444
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/main/java/com/bunq/sdk/model/generated linguist-generated=true

.idea/misc.xml

-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ApiContext apiContext = ApiContext.restore(API_CONTEXT_FILE_PATH);
4848
to/restored from the `bunq.conf` file in the same folder with your executable.
4949

5050
#### Example
51-
See [`ApiContextSaveExample.java`](./src/main/java/com/bunq/sdk/example/ApiContextSaveExample.java)
51+
See [`ApiContextSaveExample.java`](./src/main/java/com/bunq/sdk/examples/ApiContextSaveExample.java)
5252

5353
The API context can then be saved with:
5454

@@ -89,7 +89,7 @@ Integer paymentId = Payment.create(
8989
```
9090

9191
##### Example
92-
See [`PaymentExample.java`](./src/main/java/com/bunq/sdk/example/PaymentExample.java)
92+
See [`PaymentExample.java`](./src/main/java/com/bunq/sdk/examples/PaymentExample.java)
9393

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

109109
##### Example
110-
See [`MonetaryAccountExample.java`](./src/main/java/com/bunq/sdk/example/MonetaryAccountExample.java)
110+
See [`MonetaryAccountExample.java`](./src/main/java/com/bunq/sdk/examples/MonetaryAccountExample.java)
111111

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

129129
##### Example
130-
See [`RequestExample.java`](./src/main/java/com/bunq/sdk/example/RequestExample.java)
130+
See [`RequestExample.java`](./src/main/java/com/bunq/sdk/examples/RequestExample.java)
131131

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

141141
##### Example
142-
See [`CustomerStatementExportExample.java`](./src/main/java/com/bunq/sdk/example/CustomerStatementExportExample.java)
142+
See [`CustomerStatementExportExample.java`](./src/main/java/com/bunq/sdk/examples/CustomerStatementExportExample.java)
143143

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

152152
##### Example
153-
See [`UserListExample.java`](./src/main/java/com/bunq/sdk/example/UserListExample.java)
153+
See [`UserListExample.java`](./src/main/java/com/bunq/sdk/examples/UserListExample.java)
154154

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

159159
To run an example, please do the following:
160160
1. In your IDE, open the example you are interested in and adjust the constants,

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.bunq.sdk'
2-
version '0.10.0'
2+
version '0.11.0'
33

44
apply plugin: 'java'
55
apply plugin: 'maven'

src/main/java/com/bunq/sdk/examples/PaymentListExample.java

+48-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.bunq.sdk.examples;
22

33
import com.bunq.sdk.context.ApiContext;
4+
import com.bunq.sdk.http.BunqResponse;
5+
import com.bunq.sdk.http.Pagination;
46
import com.bunq.sdk.model.generated.Payment;
57
import java.util.List;
68

@@ -9,7 +11,26 @@
911
*/
1012
public class PaymentListExample {
1113

14+
/**
15+
* Path to the API Context file.
16+
*/
1217
private static final String API_CONTEXT_FILE_PATH = "bunq.conf";
18+
19+
/**
20+
* Message constants.
21+
*/
22+
private static final String MESSAGE_LATEST_PAGE_IDS = "Latest page IDs: ";
23+
private static final String MESSAGE_SECOND_LATEST_PAGE_IDS = "Second latest page IDs: ";
24+
private static final String MESSAGE_NO_PRIOR_PAYMENTS_FOUND = "No prior payments found!";
25+
26+
/**
27+
* Size of each page of payments listing.
28+
*/
29+
private static final int PAGE_SIZE = 3;
30+
31+
/**
32+
* Constants to be changed to run the example.
33+
*/
1334
private static final int USER_ITEM_ID = 0; // Put your user ID here
1435
private static final int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here
1536

@@ -18,14 +39,38 @@ public class PaymentListExample {
1839
*/
1940
public static void main(String[] args) {
2041
ApiContext apiContext = ApiContext.restore(API_CONTEXT_FILE_PATH);
21-
List<Payment> payments = Payment.list(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID)
22-
.getValue();
42+
Pagination paginationCountOnly = new Pagination();
43+
paginationCountOnly.setCount(PAGE_SIZE);
44+
BunqResponse<List<Payment>> paymentListResponse = Payment.list(
45+
apiContext,
46+
USER_ITEM_ID,
47+
MONETARY_ACCOUNT_ITEM_ID,
48+
paginationCountOnly.getUrlParamsCountOnly()
49+
);
50+
List<Payment> payments = paymentListResponse.getValue();
51+
52+
System.out.println(MESSAGE_LATEST_PAGE_IDS);
2353
printPayments(payments);
54+
55+
Pagination pagination = paymentListResponse.getPagination();
56+
57+
if (pagination.hasPreviousPage()) {
58+
System.out.println(MESSAGE_SECOND_LATEST_PAGE_IDS);
59+
List<Payment> previousPayments = Payment.list(
60+
apiContext,
61+
USER_ITEM_ID,
62+
MONETARY_ACCOUNT_ITEM_ID,
63+
pagination.getUrlParamsPreviousPage()
64+
).getValue();
65+
printPayments(previousPayments);
66+
} else {
67+
System.out.println(MESSAGE_NO_PRIOR_PAYMENTS_FOUND);
68+
}
2469
}
2570

2671
private static void printPayments(List<Payment> payments) {
2772
for (Payment payment : payments) {
28-
System.out.println(payment);
73+
System.out.println(payment.getId());
2974
}
3075
}
3176

src/main/java/com/bunq/sdk/http/ApiClient.java

+25-9
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
import java.io.IOException;
1616
import java.net.MalformedURLException;
1717
import java.net.URI;
18+
import java.net.URISyntaxException;
1819
import java.security.KeyManagementException;
1920
import java.security.NoSuchAlgorithmException;
2021
import java.util.ArrayList;
2122
import java.util.HashMap;
2223
import java.util.List;
2324
import java.util.Map;
25+
import java.util.SortedMap;
26+
import java.util.TreeMap;
2427
import java.util.UUID;
2528
import org.apache.http.Header;
2629
import org.apache.http.HttpHost;
@@ -32,6 +35,7 @@
3235
import org.apache.http.client.methods.HttpPost;
3336
import org.apache.http.client.methods.HttpPut;
3437
import org.apache.http.client.methods.HttpUriRequest;
38+
import org.apache.http.client.utils.URIBuilder;
3539
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
3640
import org.apache.http.entity.ByteArrayEntity;
3741
import org.apache.http.entity.ContentType;
@@ -75,7 +79,7 @@ public class ApiClient {
7579
/**
7680
* Prefix for bunq's own headers.
7781
*/
78-
private static final String USER_AGENT_BUNQ = "bunq-sdk-java/0.10.0";
82+
private static final String USER_AGENT_BUNQ = "bunq-sdk-java/0.11.0";
7983
private static final String LANGUAGE_EN_US = "en_US";
8084
private static final String REGION_NL_NL = "nl_NL";
8185
private static final String GEOLOCATION_ZERO = "0 0 0 0 000";
@@ -135,13 +139,24 @@ public BunqResponseRaw post(String uri, byte[] requestBodyBytes,
135139
CloseableHttpResponse response = executeRequest(httpPost, customHeaders);
136140

137141
return createBunqResponseRaw(response);
138-
} catch (IOException exception) {
142+
} catch (IOException | URISyntaxException exception) {
139143
throw new UncaughtExceptionError(exception);
140144
}
141145
}
142146

143-
private URI determineFullUri(String uri) {
144-
return URI.create(apiContext.getBaseUri().toString() + uri);
147+
private URI determineFullUri(String uri) throws URISyntaxException {
148+
return determineFullUri(uri, new HashMap<>());
149+
}
150+
151+
private URI determineFullUri(String uri, Map<String, String> params) throws URISyntaxException {
152+
URIBuilder builder = new URIBuilder(apiContext.getBaseUri().toString() + uri);
153+
SortedMap<String, String> paramsSorted = new TreeMap<>(params);
154+
155+
for (Map.Entry<String, String> param : paramsSorted.entrySet()) {
156+
builder.addParameter(param.getKey(), param.getValue());
157+
}
158+
159+
return builder.build();
145160
}
146161

147162
private CloseableHttpResponse executeRequest(HttpUriRequest request,
@@ -279,13 +294,14 @@ private static Map<String, String> getHeadersMap(CloseableHttpResponse response)
279294
*
280295
* @return The raw response of the GET request.
281296
*/
282-
public BunqResponseRaw get(String uri, Map<String, String> customHeaders) {
297+
public BunqResponseRaw get(String uri, Map<String, String> params,
298+
Map<String, String> customHeaders) {
283299
try {
284-
HttpGet httpGet = new HttpGet(determineFullUri(uri));
300+
HttpGet httpGet = new HttpGet(determineFullUri(uri, params));
285301
CloseableHttpResponse response = executeRequest(httpGet, customHeaders);
286302

287303
return createBunqResponseRaw(response);
288-
} catch (IOException exception) {
304+
} catch (IOException | URISyntaxException exception) {
289305
throw new UncaughtExceptionError(exception);
290306
}
291307
}
@@ -303,7 +319,7 @@ public BunqResponseRaw put(String uri, byte[] requestBodyBytes,
303319
CloseableHttpResponse response = executeRequest(httpPut, customHeaders);
304320

305321
return createBunqResponseRaw(response);
306-
} catch (IOException exception) {
322+
} catch (IOException | URISyntaxException exception) {
307323
throw new UncaughtExceptionError(exception);
308324
}
309325
}
@@ -319,7 +335,7 @@ public BunqResponseRaw delete(String uri, Map<String, String> customHeaders) {
319335
CloseableHttpResponse response = executeRequest(httpDelete, customHeaders);
320336

321337
return createBunqResponseRaw(response);
322-
} catch (IOException exception) {
338+
} catch (IOException | URISyntaxException exception) {
323339
throw new UncaughtExceptionError(exception);
324340
}
325341
}

src/main/java/com/bunq/sdk/http/BunqResponse.java

+10
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ public class BunqResponse<T> {
66

77
private T value;
88
private Map<String, String> headers;
9+
private Pagination pagination;
910

1011
public BunqResponse(T value, Map<String, String> headers) {
12+
this(value, headers, null);
13+
}
14+
15+
public BunqResponse(T value, Map<String, String> headers, Pagination pagination) {
1116
this.value = value;
1217
this.headers = headers;
18+
this.pagination = pagination;
1319
}
1420

1521
public T getValue() {
@@ -20,4 +26,8 @@ public Map<String, String> getHeaders() {
2026
return headers;
2127
}
2228

29+
public Pagination getPagination() {
30+
return pagination;
31+
}
32+
2333
}

0 commit comments

Comments
 (0)