diff --git a/README.md b/README.md index 8dec2544..cf31e95d 100644 --- a/README.md +++ b/README.md @@ -36,21 +36,19 @@ ApiContext apiContext = ApiContext.create(ENVIRONMENT_TYPE, API_KEY, apiContext.save(API_CONTEXT_FILE_PATH); ``` -**Please note:** initializing your application is a heavy task and it is recommended to do it only once per device. +**Please note:** initialising your application is a heavy task and it is recommended to do it only once per device. After saving the context, you can restore it at any time: ``` ApiContext apiContext = ApiContext.restore(API_CONTEXT_FILE_PATH); +BunqContext.loadApiContext(apiContext); ``` -**Tip:** both saving and restoring the context can be done without any arguments. In this case the context will be saved -to/restored from the `bunq.conf` file in the same folder with your executable. +**Tip:** both saving and restoring the context can be done without any arguments. In this case the context will be saved to/restored from the `bunq.conf` file in the same folder with your executable. #### Example -See [`ApiContextSaveExample.java`](./src/main/java/com/bunq/sdk/examples/ApiContextSaveExample.java) - -The API context can then be saved with: +See [`tinker/load_api_context`](https://github.com/bunq/tinker_java/blob/b03cbc2b84f35de9721a4083843c4015665d67f8/src/main/java/com/bunq/tinker/libs/BunqLib.java#L96-L101) #### Safety considerations The file storing the context details (i.e. `bunq.conf`) is a key to your account. Anyone having @@ -58,116 +56,68 @@ access to it is able to perform any Public API actions with your account. Theref choosing a truly safe place to store it. ### Making API calls -There is a class for each endpoint. Each class has functions for each supported action. These -actions can be `create`, `get`, `update`, `delete` and `list`. +There is a class for each endpoint. Each class has functions for each supported action. These actions can be `create`, `get`, `update`, `delete` and `list`. + +When making calls, The `userId` and `monetaryAccountId` needed to make calls will be determined by the SDK it. When no `monetaryAccountId` has been passed, the SDK will use the first active monetary account it can find. This is normally the monetary account used for billing. -Sometimes API calls have dependencies, for instance `MonetaryAccount`. Making changes to a monetary -account always also needs a reference to a `User`. These dependencies are required as arguments when -performing API calls. Take a look at [doc.bunq.com](https://doc.bunq.com) for the full -documentation. +Before you make a call, make sure that you have loaded `ApiContext` in to the `BunqContext`. #### Creating objects -Creating objects through the API requires an `ApiContext`, a `requestMap` and identifiers of all -dependencies (such as User ID required for accessing a Monetary Account). Optionally, custom headers -can be passed to requests. +With the `create` method you can create new models. This method normally returns the `id` of the created model. ``` -Map paymentMap = new HashMap<>(); -Amount paymentAmount = new Amount(PAYMENT_AMOUNT, PAYMENT_CURRENCY); -paymentMap.put(Payment.FIELD_AMOUNT, paymentAmount); -Pointer pointerCounterparty = new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL); -paymentMap.put(Payment.FIELD_COUNTERPARTY_ALIAS, pointerCounterparty); -paymentMap.put(Payment.FIELD_DESCRIPTION, PAYMENT_DESCRIPTION); - -Integer paymentId = Payment.create( - apiContext, - generateExamplePaymentMap(), - USER_ITEM_ID, - MONETARY_ACCOUNT_ITEM_ID +Payment.create( + new Amount(amount, CURRENCY_EURO), + new Pointer(POINTER_TYPE_EMAIL, recipient), + description ); ``` ##### Example -See [`PaymentExample.java`](./src/main/java/com/bunq/sdk/examples/PaymentExample.java) +See [`tinker/make_payment`](https://github.com/bunq/tinker_java/blob/cc41ff072d01e61b44bb53169edb80bde9620dc5/src/main/java/com/bunq/tinker/MakePayment.java#L46) #### Reading objects -Reading objects through the API requires an `ApiContext`, identifiers of all dependencies (such as -User ID required for accessing a Monetary Account), and the identifier of the object to read (ID or -UUID) Optionally, custom headers can be passed to requests. -This type of calls always returns a model. +Reading objects can be done via the `get` or `list` method. + +These type of calls always returns the model or binary data. ``` -MonetaryAccount monetaryAccount = MonetaryAccount.get( - apiContext, - USER_ITEM_ID, - MONETARY_ACCOUNT_ITEM_ID -); +Payment.list( + monetaryAccountBank.getId(), + pagination.getUrlParamsCountOnly() +) ``` ##### Example -See [`MonetaryAccountExample.java`](./src/main/java/com/bunq/sdk/examples/MonetaryAccountExample.java) +See [`tinker/get_all_payment`](https://github.com/bunq/tinker_java/blob/b03cbc2b84f35de9721a4083843c4015665d67f8/src/main/java/com/bunq/tinker/libs/BunqLib.java#L161-L164) #### Updating objects -Updating objects through the API goes the same way as creating objects, except that also the object to update identifier -(ID or UUID) is needed. +Updating objects through the API goes the same way as creating objects, except that also the object to update identifier (ID or UUID) is needed. + +The `update` method will also normally return the `Id` of the updated model. ``` -Map requestMapUpdate = new HashMap<>(); -requestMapUpdate.put(RequestInquiry.FIELD_STATUS, STATUS_REVOKED); - -RequestInquiry.update( - apiContext, - requestMapUpdate, - USER_ITEM_ID, - MONETARY_ACCOUNT_ITEM_ID, - REQUEST_ID -); + MonetaryAccountBank.update(Integer.parseInt(accountId), name); ``` ##### Example -See [`RequestExample.java`](./src/main/java/com/bunq/sdk/examples/RequestExample.java) +See [`tinker/update_monetary_account`](https://github.com/bunq/tinker_java/blob/b03cbc2b84f35de9721a4083843c4015665d67f8/src/main/java/com/bunq/tinker/UpdateAccount.java#L36) #### Deleting objects -Deleting objects through the API requires an `ApiContext`, identifiers of all dependencies (such as User ID required for -accessing a Monetary Account), and the identifier of the object to delete (ID or UUID) Optionally, custom headers can be -passed to requests. - -``` -CustomerStatementExport.delete(apiContext, userId, monetaryAccountId, customerStatementId); -``` -##### Example -See [`CustomerStatementExportExample.java`](./src/main/java/com/bunq/sdk/examples/CustomerStatementExportExample.java) +Deleting object can be done via the `delete` method. This method also requires the object identifier which could be an `Id` or `uuid`. -#### Listing objects -Listing objects through the API requires an `ApiContext` and identifiers of all dependencies (such as User ID required -for accessing a Monetary Account). Optionally, custom headers can be passed to requests. +This method normally returns an empty response. ``` -List users = User.list(apiContext); +CustomerStatementExport.delete(customerStatementId); ``` -##### Example -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/examples/`). - -To run an example, please do the following: -1. In your IDE, open the example you are interested in and adjust the constants, -such as `API_KEY` or `USER_ID`, to hold your data. -2. Since Java IDE's are typically advanced just run the example of your choice in your IDE. - -In order for examples to run, you would need a valid context file (`bunq.conf`) -to be present in the bunq SDK project root directory. The file can either copied -from somewhere else (e.g. tests) or created by executing the `ApiContextSaveExample.java` in your -IDE. -Please do not forget to set the `API_KEY` constant in `ApiContextSaveExample.java` to your actual -API key before running the example! +To have an idea on how the SDK works you can play around with the java tinker located at: https://github.com/bunq/tinker_java ## Running tests Information regarding the test cases can be found in the [README.md](./src/test/README.md)