monobank 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9be615cce7c32eea11cd8383a32c9966c10a0ae9e285abf6010b478cd8fa96f8
4
+ data.tar.gz: bc8dfce3b3971d44307482c63136905472f850db4633a3acefb484978921f571
5
+ SHA512:
6
+ metadata.gz: 64015cf3ea7b39d859029a4bc82ab4799f2657c1e6976ef3a19216982b83c0441e4e2550eddb5cb8fb2344af5b86fa01d31ef47084328d6f0e8cd0c8017ac34f
7
+ data.tar.gz: 65b865d9e5c52d236374000cd514e1b1c7dc21326bb861ed7773c8276aa62ac2992e04bfe4a1c762bec38c097d9e234288c23977a38ca17576af5f345c87aaf0
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ require 'monobank/version'
2
+ require 'monobank/client'
3
+ require 'forwardable'
4
+
5
+ module Monobank
6
+ extend SingleForwardable
7
+ def_delegators :client, :bank_currency, :client_info, :statement
8
+
9
+ def self.client
10
+ @client ||= Client.new
11
+ end
12
+
13
+ class << self
14
+ attr_accessor :token
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ require 'monobank/endpoint'
2
+ require 'monobank/resources/bank/currency'
3
+
4
+ module Monobank
5
+ module Bank
6
+ class Currency < Endpoint
7
+ ENDPOINT = '/bank/currency'.freeze
8
+
9
+ private
10
+
11
+ def define_resources(attributes)
12
+ attributes.map do |attrs|
13
+ Monobank::Resources::Bank::Currency.new(attrs)
14
+ end
15
+ end
16
+
17
+ def pathname
18
+ ENDPOINT
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'monobank/connection'
2
+ require 'monobank/bank/currency'
3
+ require 'monobank/personal/client_info'
4
+ require 'monobank/personal/statement'
5
+
6
+ module Monobank
7
+ class Client
8
+ def bank_currency
9
+ Bank::Currency.new.call
10
+ end
11
+
12
+ def client_info(token:)
13
+ Personal::ClientInfo.new(token: token).call
14
+ end
15
+
16
+ def statement(token:, account_id:, from:, to: nil)
17
+ Personal::Statement.new(token: token, account_id: account_id, from: from, to: to).call
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ require 'httparty'
2
+
3
+ module Monobank
4
+ class Connection
5
+ include HTTParty
6
+ base_uri 'api.monobank.ua'
7
+
8
+ def get(pathname, options = {})
9
+ self.class.get(pathname, options)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ require 'monobank/resources/error'
2
+
3
+ module Monobank
4
+ class Endpoint
5
+ def call
6
+ attributes = connection.get(pathname, options)
7
+ return define_resources(attributes) if attributes.success?
8
+
9
+ Monobank::Resources::Error.new(attributes)
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :token
15
+
16
+ def options
17
+ { headers: { "X-Token" => token.to_s } }
18
+ end
19
+
20
+ def connection
21
+ @connection ||= Connection.new
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Monobank
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'monobank/endpoint'
2
+ require 'monobank/resources/personal/client_info'
3
+
4
+ module Monobank
5
+ module Personal
6
+ class ClientInfo < Endpoint
7
+ ENDPOINT = '/personal/client-info'.freeze
8
+
9
+ def initialize(token:)
10
+ @token = token
11
+ end
12
+
13
+ private
14
+
15
+ def pathname
16
+ ENDPOINT
17
+ end
18
+
19
+ def define_resources(attributes)
20
+ Monobank::Resources::Personal::ClientInfo.new(attributes)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'monobank/endpoint'
2
+ require 'monobank/resources/personal/statement'
3
+
4
+ module Monobank
5
+ module Personal
6
+ class Statement < Endpoint
7
+ ENDPOINT = '/personal/statement'.freeze
8
+
9
+ def initialize(token:, account_id:, from:, to:)
10
+ @token = token
11
+ @account_id = account_id
12
+ @from = from
13
+ @to = to
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :account_id, :from, :to
19
+
20
+ def pathname
21
+ path = "#{ENDPOINT}/#{account_id}/#{from}"
22
+ path = "#{path}/#{to}" if to
23
+ path
24
+ end
25
+
26
+ def define_resources(attributes)
27
+ attributes.map do |attrs|
28
+ Monobank::Resources::Personal::Statement.new(attrs)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ require 'monobank/resources/base'
2
+
3
+ module Monobank
4
+ module Resources
5
+ module Bank
6
+ class Currency < Base
7
+ define_fields %w[currency_code_a currency_code_b date rate_sell rate_buy rate_cross]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ module Monobank
2
+ module Resources
3
+ class Base
4
+ def self.define_fields(attributes)
5
+ attributes.each do |attribute|
6
+ define_method(attribute) { instance_variable_get("@attributes")[attribute] }
7
+ end
8
+ end
9
+
10
+ def initialize(attributes)
11
+ @attributes = {}
12
+ snake_case_attributes = deep_snake_case(attributes)
13
+ snake_case_attributes.each { |key, value| @attributes[method_name(key)] = value }
14
+ end
15
+
16
+ def method_name(key)
17
+ key.gsub(/(.)([A-Z])/,'\1_\2').downcase
18
+ end
19
+
20
+ def deep_snake_case(hash)
21
+ hash.each_with_object({}) do |(key, value), object|
22
+ object[method_name(key)] =
23
+ if value.kind_of? Hash
24
+ deep_snake_case(value)
25
+ elsif value.kind_of? Array
26
+ value.map { |element| deep_snake_case(element) }
27
+ else
28
+ value
29
+ end
30
+ end
31
+ end
32
+
33
+ attr_reader :attributes
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ require 'monobank/resources/base'
2
+
3
+ module Monobank
4
+ module Resources
5
+ class Error < Base
6
+ define_fields %w[error_description]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'monobank/resources/base'
2
+
3
+ module Monobank
4
+ module Resources
5
+ module Personal
6
+ class Accounts < Base
7
+ define_fields %w[id balance credit_limit currency_code cashback_type]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'monobank/resources/base'
2
+ require 'monobank/resources/personal/accounts'
3
+
4
+ module Monobank
5
+ module Resources
6
+ module Personal
7
+ class ClientInfo < Base
8
+ define_fields %w[name web_hook_url accounts]
9
+
10
+ def accounts
11
+ @attributes['accounts'].map do |account|
12
+ Monobank::Resources::Personal::Accounts.new(account)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ require 'monobank/resources/base'
2
+
3
+ module Monobank
4
+ module Resources
5
+ module Personal
6
+ class Statement < Base
7
+ define_fields %w[id time description mcc hold amount operation_amount currency_code commission_rate cashback_amount balance]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Monobank
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.describe Monobank do
2
+ it "has a version number" do
3
+ expect(Monobank::VERSION).not_to be nil
4
+ end
5
+
6
+ it "does something useful" do
7
+ expect(false).to eq(true)
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "monobank"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monobank
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - vergilet
8
+ - anatoliikryvishyn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-01-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.1.2
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.2
28
+ - !ruby/object:Gem::Dependency
29
+ name: httparty
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.17.3
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.17.3
42
+ description: Unofficial Ruby Gem for Monobank API.
43
+ email:
44
+ - osyaroslav@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - Rakefile
50
+ - lib/monobank.rb
51
+ - lib/monobank/bank/currency.rb
52
+ - lib/monobank/client.rb
53
+ - lib/monobank/connection.rb
54
+ - lib/monobank/endpoint.rb
55
+ - lib/monobank/error.rb
56
+ - lib/monobank/personal/client_info.rb
57
+ - lib/monobank/personal/statement.rb
58
+ - lib/monobank/resources/bank/currency.rb
59
+ - lib/monobank/resources/base.rb
60
+ - lib/monobank/resources/error.rb
61
+ - lib/monobank/resources/personal/accounts.rb
62
+ - lib/monobank/resources/personal/client_info.rb
63
+ - lib/monobank/resources/personal/statement.rb
64
+ - lib/monobank/version.rb
65
+ - spec/monobank_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: https://github.com/vergilet/monobank
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ homepage_uri: https://github.com/vergilet/monobank
72
+ source_code_uri: https://github.com/vergilet/monobank
73
+ changelog_uri: https://github.com/vergilet/monobank
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.0.2
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Unofficial Ruby Gem for Monobank API.
93
+ test_files:
94
+ - spec/spec_helper.rb
95
+ - spec/monobank_spec.rb