Coder Social home page Coder Social logo

demo_bankinapi's Introduction

Bankin API

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.

Internals

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 a resource object of Bankin API.
  • Pagination: Represents the pagination information of each page.
  • User: Represents a user, with its username and password.
  • BankinAPIDB and UserDB: 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.

API

Reference

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

Usage

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:

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
	}
]

Test

To run the tests, open a terminal and run: To run the project, just open the folder and run:

$ cd demo_bankinapi
$ sbt test

Documentation

Classes and code contains its own comments explaining how they work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.