Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vergilet/monobank
Monobank API Ruby
https://github.com/vergilet/monobank
hacktoberfest mono mono-api monobank monobank-api ruby
Last synced: about 2 months ago
JSON representation
Monobank API Ruby
- Host: GitHub
- URL: https://github.com/vergilet/monobank
- Owner: vergilet
- License: mit
- Created: 2020-01-02T08:55:10.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-20T12:40:09.000Z (7 months ago)
- Last Synced: 2024-10-12T03:52:56.696Z (2 months ago)
- Topics: hacktoberfest, mono, mono-api, monobank, monobank-api, ruby
- Language: Ruby
- Homepage: https://vergilet.github.io/monobank/
- Size: 130 KB
- Stars: 14
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Build Status](https://api.travis-ci.com/vergilet/repost.svg?branch=master)](https://app.travis-ci.com/github/vergilet/monobank)
# Monobank
Unofficial Ruby Gem for [Monobank API](https://api.monobank.ua/docs/).
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'monobank'
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install monobank
## Endpoints
Use available methods to gather needed data from Monobank API:
```ruby
# Bank currency
Monobank.bank_currency# Client Info
Monobank.client_info(token: YOUR_MONO_TOKEN)# Statement
Monobank.statement(token: YOUR_MONO_TOKEN, account_id: ACCOUNT_ID, from: 1546304461, to: 1546306461) # 30 days ago: (Date.today - 30).to_time.to_i# Set webhook
Monobank.set_webhook(token: YOUR_MONO_TOKEN, url: WEBHOOK_URL)
```### Public data
General information provided without authorization.
#### Bank Currency
##### API Method: [bank-currency](https://api.monobank.ua/docs/#tag/Publichni-dani/paths/~1bank~1currency/get)
`GET /bank/currency`
*Get a basic list of monobank exchange rates. The information is cached and updated at least once every 5 minutes.*
```ruby
bank_currency = Monobank.bank_currency
bank_currency # Array
``````ruby
some_currency = bank_currency.first
some_currency.class # Monobank::Resources::Bank::Currency
``````ruby
some_currency.currency_code_a # Integer, ISO 4217
some_currency.currency_code_b # Integer, ISO 4217
some_currency.date # Integer, Unix time in sec (use Time.at)
some_currency.rate_sell # Float
some_currency.rate_buy # Float
some_currency.rate_cross # Floatsome_currency.attributes # Hash with all fields above
```*(!) About [ISO 4217](https://uk.wikipedia.org/wiki/%D0%9A%D0%BB%D0%B0%D1%81%D0%B8%D1%84%D1%96%D0%BA%D0%B0%D1%86%D1%96%D1%8F_%D0%B2%D0%B0%D0%BB%D1%8E%D1%82_(ISO_4217)?section=2#%D0%9F%D0%B5%D1%80%D0%B5%D0%BB%D1%96%D0%BA_%D0%B4%D1%96%D1%8E%D1%87%D0%B8%D1%85_%D0%BA%D0%BE%D0%B4%D1%96%D0%B2).*
### Personal data
Information provided only with the access token that the client can obtain in his personal account [Monobank API](https://api.monobank.ua/)
#### Client Info
##### API Method: [personal-client-info](https://api.monobank.ua/docs/#tag/Kliyentski-personalni-dani/paths/~1personal~1client-info/get)
`GET /personal/client-info`
*Receiving information about the client and a list of his accounts. Restrictions on the use of the function no more than once every 60 seconds.*
```ruby
client_info = Monobank.client_info(token: YOUR_MONO_TOKEN)
client_info.class # Monobank::Resources::Personal::ClientInfo
```
```ruby
client_info.name # String, client name
client_info.web_hook_url # String, webhook url
client_info.accounts # array of accounts (type Monobank::Resources::Personal::Account)client_info.attributes # Hash with all fields above
```
##### Client Info > Account```ruby
account = client_info.accounts.first
account.class # Monobank::Resources::Personal::Account
```
```ruby
account.id # String, Account identifier
account.balance # Integer, Balance in cents
account.credit_limit # Integer, Credit limit
account.currency_code # Integer, ISO 4217
account.cashback_type # String, None, UAH, Milesaccount.attributes # Hash with all fields above
```#### Statement
##### API Method: [personal-statement](https://api.monobank.ua/docs/#tag/Kliyentski-personalni-dani/paths/~1personal~1statement~1{account}~1{from}~1{to}/get)
`GET /personal/statement/{account}/{from}/{to}`
*Receiving a statement {from} - {to} time in seconds in Unix time format.
The maximum time for which it is possible to receive a statement is 31 days + 1 hour (2682000 seconds).
Limit on using the function no more than 1 time in 60 seconds.*```ruby
account_id = 'QWERTY-1SdSD' # String, ClientInfo -> Account ID
from = 1546304461 # Integer, Unix time in sec (use Time.at)
to = 1546306461 # Integer, Optional, uses current time if blank
``````ruby
statements = Monobank.statement(token: YOUR_MONO_TOKEN, account_id: ACCOUNT_ID, from: 1546304461, to: 1546306461)
statements # array of statements (type Monobank::Resources::Personal::Statement)
``````ruby
statement = statements.first
statement.class # Monobank::Resources::Personal::Statement
```
```ruby
statement.id # String, transaction ID
statement.time # Integer, Unix time in sec (use Time.at)
statement.description # String, transaction description
statement.mcc # Integer, Merchant Category Code, (ISO 18245)
statement.hold # Boolean, Lock status
statement.amount # Integer, Amount in cents
statement.operation_amount # Integer, Amount in cents
statement.currency_code # Integer, ISO 4217
statement.commission_rate # Integer, commission amount in cents
statement.cashback_amount # Integer, cashback amount in cents
statement.balance # Integer, balance in centsstatement.attributes # Hash with all fields above
```#### Set WebHook
##### API Method: [personal-webhook](https://api.monobank.ua/docs/#tag/Kliyentski-personalni-dani/paths/~1personal~1webhook/post)
`POST /personal/webhook`
*Sends json ~ `{type:"StatementItem", data:{account:"...", statementItem:{#StatementItem}}}` to WEBHOOK_URL*
```ruby
webhook = Monobank.set_webhook(token: YOUR_MONO_TOKEN, url: WEBHOOK_URL)
webhook.class # Monobank::Resources::Personal::Webhhok
```
```ruby
webhook.status # String, "ok" if ok :)webhook.attributes # Hash with all fields above
```#### Errors
Error object with code and description.
```ruby
error.class # Monobank::Resources::Errorerror.code # Integer, (e.g. 429 for Too many requests)
error.error_description # String, Error descriptionerror.attributes # Hash with all fields above
```### Corporate API
For now please use specs as a documentation - [MonobankCorporate Spec](https://github.com/vergilet/monobank/blob/master/spec/monobank_corporate_spec.rb)
## Contributing
Bug reports and pull requests are welcome on GitHub at [https://github.com/vergilet/monobank](https://github.com/vergilet/monobank)
Feel free to contribute:
1. Fork it ([https://github.com/vergilet/monobank/fork](https://github.com/vergilet/monobank/fork))
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create new Pull Request## License
The gem is available as open source under the terms of the MIT License.Copyright © 2020 Yaro & Tolik.
[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen)](https://raw.githubusercontent.com/vergilet/monobank/master/LICENSE.txt)
**That's all folks.**