From 87e2e023828b799b2cfcc70794d12d33a3120462 Mon Sep 17 00:00:00 2001 From: Kevin Hellemun Date: Wed, 30 May 2018 18:06:35 +0200 Subject: [PATCH] Merge pull request #9 from bunq/move-to-new-sandbox-bunq/sdk_java#89 Update sandbox url. (bunq/sdk_java#89) --- .../java/com/bunq/tinker/libs/BunqLib.java | 58 +++++++++---------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/bunq/tinker/libs/BunqLib.java b/src/main/java/com/bunq/tinker/libs/BunqLib.java index c7fabd6..5d550bc 100644 --- a/src/main/java/com/bunq/tinker/libs/BunqLib.java +++ b/src/main/java/com/bunq/tinker/libs/BunqLib.java @@ -178,8 +178,33 @@ public List getAllRequest(MonetaryAccountBank monetaryAccountBan ).getValue(); } - public List getAllCard() { - return getAllCard(DEFAULT_FETCH_COUNT); + private SandboxUser generateNewSandboxUser() { + OkHttpClient client = new OkHttpClient(); + + Request request = new Request.Builder() + .url("https://public-api.sandbox.bunq.com/v1/sandbox-user") + .post(RequestBody.create(null, new byte[0])) + .addHeader("x-bunq-client-request-id", "1234") + .addHeader("cache-control", "no-cache") + .addHeader("x-bunq-geolocation", "0 0 0 0 NL") + .addHeader("x-bunq-language", "en_US") + .addHeader("x-bunq-region", "en_US") + .build(); + + try { + Response response = client.newCall(request).execute(); + if (response.code() == HTTP_STATUS_OK) { + String responseString = response.body().string(); + JsonObject jsonObject = new Gson().fromJson(responseString, JsonObject.class); + JsonObject apiKEy = jsonObject.getAsJsonArray(FIELD_RESPONSE).get(INDEX_FIRST).getAsJsonObject().get(FIELD_API_KEY).getAsJsonObject(); + + return SandboxUser.fromJsonReader(new JsonReader(new StringReader(apiKEy.toString()))); + } else { + throw new BunqException(String.format(ERROR_COULD_NOT_GENERATE_NEW_API_KEY, response.body().string())); + } + } catch (IOException e) { + throw new BunqException(e.getMessage()); + } } public List getAllCard(int count) { @@ -234,33 +259,4 @@ public List getAllUserAlias() { throw new BunqException(ERROR_COULD_NOT_DETERMINE_USER_TYPE); } } - - private SandboxUser generateNewSandboxUser() { - OkHttpClient client = new OkHttpClient(); - - Request request = new Request.Builder() - .url("https://sandbox.public.api.bunq.com/v1/sandbox-user") - .post(RequestBody.create(null, new byte[0])) - .addHeader("x-bunq-client-request-id", "1234") - .addHeader("cache-control", "no-cache") - .addHeader("x-bunq-geolocation", "0 0 0 0 NL") - .addHeader("x-bunq-language", "en_US") - .addHeader("x-bunq-region", "en_US") - .build(); - - try { - Response response = client.newCall(request).execute(); - if (response.code() == HTTP_STATUS_OK) { - String responseString = response.body().string(); - JsonObject jsonObject = new Gson().fromJson(responseString, JsonObject.class); - JsonObject apiKEy = jsonObject.getAsJsonArray(FIELD_RESPONSE).get(INDEX_FIRST).getAsJsonObject().get(FIELD_API_KEY).getAsJsonObject(); - - return SandboxUser.fromJsonReader(new JsonReader(new StringReader(apiKEy.toString()))); - } else { - throw new BunqException(String.format(ERROR_COULD_NOT_GENERATE_NEW_API_KEY, response.body().string())); - } - } catch (IOException e) { - throw new BunqException(e.getMessage()); - } - } }