@@ -178,8 +178,33 @@ public List<RequestInquiry> getAllRequest(MonetaryAccountBank monetaryAccountBan
178178 ).getValue ();
179179 }
180180
181- public List <Card > getAllCard () {
182- return getAllCard (DEFAULT_FETCH_COUNT );
181+ private SandboxUser generateNewSandboxUser () {
182+ OkHttpClient client = new OkHttpClient ();
183+
184+ Request request = new Request .Builder ()
185+ .url ("https://public-api.sandbox.bunq.com/v1/sandbox-user" )
186+ .post (RequestBody .create (null , new byte [0 ]))
187+ .addHeader ("x-bunq-client-request-id" , "1234" )
188+ .addHeader ("cache-control" , "no-cache" )
189+ .addHeader ("x-bunq-geolocation" , "0 0 0 0 NL" )
190+ .addHeader ("x-bunq-language" , "en_US" )
191+ .addHeader ("x-bunq-region" , "en_US" )
192+ .build ();
193+
194+ try {
195+ Response response = client .newCall (request ).execute ();
196+ if (response .code () == HTTP_STATUS_OK ) {
197+ String responseString = response .body ().string ();
198+ JsonObject jsonObject = new Gson ().fromJson (responseString , JsonObject .class );
199+ JsonObject apiKEy = jsonObject .getAsJsonArray (FIELD_RESPONSE ).get (INDEX_FIRST ).getAsJsonObject ().get (FIELD_API_KEY ).getAsJsonObject ();
200+
201+ return SandboxUser .fromJsonReader (new JsonReader (new StringReader (apiKEy .toString ())));
202+ } else {
203+ throw new BunqException (String .format (ERROR_COULD_NOT_GENERATE_NEW_API_KEY , response .body ().string ()));
204+ }
205+ } catch (IOException e ) {
206+ throw new BunqException (e .getMessage ());
207+ }
183208 }
184209
185210 public List <Card > getAllCard (int count ) {
@@ -234,33 +259,4 @@ public List<Pointer> getAllUserAlias() {
234259 throw new BunqException (ERROR_COULD_NOT_DETERMINE_USER_TYPE );
235260 }
236261 }
237-
238- private SandboxUser generateNewSandboxUser () {
239- OkHttpClient client = new OkHttpClient ();
240-
241- Request request = new Request .Builder ()
242- .url ("https://sandbox.public.api.bunq.com/v1/sandbox-user" )
243- .post (RequestBody .create (null , new byte [0 ]))
244- .addHeader ("x-bunq-client-request-id" , "1234" )
245- .addHeader ("cache-control" , "no-cache" )
246- .addHeader ("x-bunq-geolocation" , "0 0 0 0 NL" )
247- .addHeader ("x-bunq-language" , "en_US" )
248- .addHeader ("x-bunq-region" , "en_US" )
249- .build ();
250-
251- try {
252- Response response = client .newCall (request ).execute ();
253- if (response .code () == HTTP_STATUS_OK ) {
254- String responseString = response .body ().string ();
255- JsonObject jsonObject = new Gson ().fromJson (responseString , JsonObject .class );
256- JsonObject apiKEy = jsonObject .getAsJsonArray (FIELD_RESPONSE ).get (INDEX_FIRST ).getAsJsonObject ().get (FIELD_API_KEY ).getAsJsonObject ();
257-
258- return SandboxUser .fromJsonReader (new JsonReader (new StringReader (apiKEy .toString ())));
259- } else {
260- throw new BunqException (String .format (ERROR_COULD_NOT_GENERATE_NEW_API_KEY , response .body ().string ()));
261- }
262- } catch (IOException e ) {
263- throw new BunqException (e .getMessage ());
264- }
265- }
266262}
0 commit comments