The idea of this project is to show the application of consuming an API. In here we present two REST API, one to compute the arrondis for each transaction for a given user. The second one computes the aggregation of the arrondis for a given list of users.
In order to connect to the Bankin API, a client_id and client_secret is required, along with
the user email and password credentials. The classes BankinAPI
and User
are meant to hold
these credentials respectively.
After the connection is set up, a promise is returned with the access_token. This promise is passed to the method (another promise) in charge to perform the queries.
Once the query is resolved, the data collected is stored in different classes:
Transactions
: Represents one page of transactions from the Bankin API.Transaction
: Represents a single transaction for a given user.BankinResource
: Represents aresource
object of Bankin API.Pagination
: Represents the pagination information of each page.User
: Represents a user, with its username and password.BankinAPIDB
andUserDB
: Represent a storage for the credentials.
Once the information was retrieved and stored in objects, it follows the next_uri to process the next page. This process is done until the last page is rendered.
To output the results, the objects are treated using Java 8 streams
: They are filtered,
mapped and collected in order to extract the information relative to the query.
This API provides two REST API:
/arrondis/<user>
: It returns a list of transactions, with their amount and arrondis calculated./aggregateArrondis/since/until
: IT returns the aggregation of all arrondis for all users, along with their email
To run the project, just open the terminal and run:
$ cd demo_bankinapi
$ sbt run
Open a browser, and query the API as the example:
To retrieve the list of arrondis:
http://localhost:9000/arrondis/[email protected]
http://localhost:9000/arrondis/[email protected]
http://localhost:9000/arrondis/[email protected]
An example response would be:
[{
"arrondis": 1.51,
"currency_code": "EUR",
"amount": -138.49,
"transaction_id": 38000003650888
}, {
"arrondis": 3.63,
"currency_code": "EUR",
"amount": -26.38,
"transaction_id": 38000003650892
}]
To retrieve the aggregation:
http://localhost:9000/aggregateArrondis/2010-05-01/2017-06-01
http://localhost:9000/aggregateArrondis/2016-05-01/2016-06-01
http://localhost:9000/aggregateArrondis/2010-05-01/2010-06-01
An example response for the aggregated data would be:
[{
"currency_code": "EUR",
"accounts": ["[email protected]"],
"totalArrondis": 306.0
},
{
"currency_code": "USD",
"accounts": ["[email protected]"],
"totalArrondis": 12.0
}
]
To run the tests, open a terminal and run: To run the project, just open the folder and run:
$ cd demo_bankinapi
$ sbt test
Classes and code contains its own comments explaining how they work.