Skip to content

laika255/monobank

 
 

Repository files navigation

Build Status

Monobank

Unofficial Ruby Gem for Monobank API.

Installation

Add this line to your application's Gemfile:

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:

# 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

GET /bank/currency

Get a basic list of monobank exchange rates. The information is cached and updated at least once every 5 minutes.

bank_currency = Monobank.bank_currency
bank_currency                   # Array
some_currency = bank_currency.first
some_currency.class             # Monobank::Resources::Bank::Currency
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        # Float

some_currency.attributes        # Hash with all fields above

(!) About ISO 4217.

Personal data

Information provided only with the access token that the client can obtain in his personal account Monobank API

Client Info

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.

client_info = Monobank.client_info(token: YOUR_MONO_TOKEN)
client_info                     # Monobank::Resources::Personal::ClientInfo
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
account = client_info.accounts.first
account                         # Monobank::Resources::Personal::Account
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, Miles 

account.attributes              # Hash with all fields above

Statement

API Method: personal-statement

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.

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
statements = Monobank.statement(token: YOUR_MONO_TOKEN, account_id: ACCOUNT_ID, from: 1546304461, to: 1546306461)
statements                  # array of statements (type Monobank::Resources::Personal::Statement)
statement = statements.first
statement                   # Monobank::Resources::Personal::Statement
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 cents

statement.attributes        # Hash with all fields above

Set WebHook

API Method: personal-webhook

POST /personal/webhook

Sends json ~ {type:"StatementItem", data:{account:"...", statementItem:{#StatementItem}}} to WEBHOOK_URL

webhook = Monobank.set_webhook(token: YOUR_MONO_TOKEN,  url: WEBHOOK_URL)
webhook                     # Monobank::Resources::Personal::Webhhok
webhook.status              # String, "ok" if ok :)

webhook.attributes          # Hash with all fields above

Errors

Error object with code and description.

error.class                 # Monobank::Resources::Error

error.code                  # Integer, (e.g. 429 for Too many requests)
error.error_description     # String, Error description

error.attributes            # Hash with all fields above

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/vergilet/monobank

Feel free to contribute:

  1. Fork it (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

That's all folks.

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 72.6%
  • HTML 19.0%
  • CSS 8.4%