monobank 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9be615cce7c32eea11cd8383a32c9966c10a0ae9e285abf6010b478cd8fa96f8
4
- data.tar.gz: bc8dfce3b3971d44307482c63136905472f850db4633a3acefb484978921f571
3
+ metadata.gz: b3875523c369f56b0b6a1cbaa1c86394ddf8ed4060baef32f8e1c7e43851a0ac
4
+ data.tar.gz: 31e57627ab4ae406ccea2815745fcd93887f09a68939ab12e5470e6440c692ad
5
5
  SHA512:
6
- metadata.gz: 64015cf3ea7b39d859029a4bc82ab4799f2657c1e6976ef3a19216982b83c0441e4e2550eddb5cb8fb2344af5b86fa01d31ef47084328d6f0e8cd0c8017ac34f
7
- data.tar.gz: 65b865d9e5c52d236374000cd514e1b1c7dc21326bb861ed7773c8276aa62ac2992e04bfe4a1c762bec38c097d9e234288c23977a38ca17576af5f345c87aaf0
6
+ metadata.gz: 472156cfe0897fdeb10542915a5b9d7d82df0fc72e9eefc53ba2827c9c34a802168ade061aeb2b5e2184a1b2d2a842be187f1268c38aeb013373ae0194c82ee2
7
+ data.tar.gz: ed3f5f077c2870b4d13da80156c84730746e21b4d72ca443a116b5923002eb4bcc92419b2332a948a866a0ebfc2104af7267cd5fb39375bb66dd1a08355a78cf
@@ -4,7 +4,7 @@ require 'forwardable'
4
4
 
5
5
  module Monobank
6
6
  extend SingleForwardable
7
- def_delegators :client, :bank_currency, :client_info, :statement
7
+ def_delegators :client, :bank_currency, :client_info, :statement, :set_webhook
8
8
 
9
9
  def self.client
10
10
  @client ||= Client.new
@@ -1,9 +1,9 @@
1
- require 'monobank/endpoint'
1
+ require 'monobank/methods/get'
2
2
  require 'monobank/resources/bank/currency'
3
3
 
4
4
  module Monobank
5
5
  module Bank
6
- class Currency < Endpoint
6
+ class Currency < Methods::Get
7
7
  ENDPOINT = '/bank/currency'.freeze
8
8
 
9
9
  private
@@ -2,6 +2,7 @@ require 'monobank/connection'
2
2
  require 'monobank/bank/currency'
3
3
  require 'monobank/personal/client_info'
4
4
  require 'monobank/personal/statement'
5
+ require 'monobank/personal/webhook'
5
6
 
6
7
  module Monobank
7
8
  class Client
@@ -16,5 +17,9 @@ module Monobank
16
17
  def statement(token:, account_id:, from:, to: nil)
17
18
  Personal::Statement.new(token: token, account_id: account_id, from: from, to: to).call
18
19
  end
20
+
21
+ def set_webhook(token:, url:)
22
+ Personal::Webhook.new(token: token, url: url).call
23
+ end
19
24
  end
20
- end
25
+ end
@@ -8,5 +8,9 @@ module Monobank
8
8
  def get(pathname, options = {})
9
9
  self.class.get(pathname, options)
10
10
  end
11
+
12
+ def post(pathname, options = {})
13
+ self.class.post(pathname, options)
14
+ end
11
15
  end
12
16
  end
@@ -0,0 +1,35 @@
1
+ require 'monobank/resources/error'
2
+
3
+ module Monobank
4
+ module Methods
5
+ class Base
6
+ def call
7
+ attributes = response
8
+ return define_resources(attributes) if attributes.code == 200
9
+
10
+ Monobank::Resources::Error.new(attributes.merge('code' => attributes.code))
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :token
16
+
17
+ def response
18
+ raise NotImplementedError
19
+ end
20
+
21
+ def options
22
+ {
23
+ headers: { 'X-Token' => token.to_s },
24
+ body: body.to_json
25
+ }
26
+ end
27
+
28
+ def body; end
29
+
30
+ def connection
31
+ @connection ||= Connection.new
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'monobank/methods/base'
2
+ require 'monobank/resources/error'
3
+
4
+ module Monobank
5
+ module Methods
6
+ class Get < Base
7
+
8
+ private
9
+
10
+ def response
11
+ connection.get(pathname, options)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'monobank/methods/base'
2
+ require 'monobank/resources/error'
3
+
4
+ module Monobank
5
+ module Methods
6
+ class Post < Base
7
+
8
+ private
9
+
10
+ def response
11
+ connection.post(pathname, options)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,9 @@
1
- require 'monobank/endpoint'
1
+ require 'monobank/methods/get'
2
2
  require 'monobank/resources/personal/client_info'
3
3
 
4
4
  module Monobank
5
5
  module Personal
6
- class ClientInfo < Endpoint
6
+ class ClientInfo < Methods::Get
7
7
  ENDPOINT = '/personal/client-info'.freeze
8
8
 
9
9
  def initialize(token:)
@@ -1,9 +1,9 @@
1
- require 'monobank/endpoint'
1
+ require 'monobank/methods/get'
2
2
  require 'monobank/resources/personal/statement'
3
3
 
4
4
  module Monobank
5
5
  module Personal
6
- class Statement < Endpoint
6
+ class Statement < Methods::Get
7
7
  ENDPOINT = '/personal/statement'.freeze
8
8
 
9
9
  def initialize(token:, account_id:, from:, to:)
@@ -0,0 +1,31 @@
1
+ require 'monobank/methods/post'
2
+ require 'monobank/resources/personal/webhook'
3
+
4
+ module Monobank
5
+ module Personal
6
+ class Webhook < Methods::Post
7
+ ENDPOINT = '/personal/webhook'.freeze
8
+
9
+ def initialize(token:, url:)
10
+ @token = token
11
+ @url = url
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :url
17
+
18
+ def pathname
19
+ ENDPOINT
20
+ end
21
+
22
+ def body
23
+ { webHookUrl: url }
24
+ end
25
+
26
+ def define_resources(attributes)
27
+ Monobank::Resources::Personal::Webhook.new(attributes)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,7 +3,7 @@ require 'monobank/resources/base'
3
3
  module Monobank
4
4
  module Resources
5
5
  class Error < Base
6
- define_fields %w[error_description]
6
+ define_fields %w[error_description code]
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,12 @@
1
+ require 'monobank/resources/base'
2
+ require 'monobank/resources/personal/accounts'
3
+
4
+ module Monobank
5
+ module Resources
6
+ module Personal
7
+ class Webhook < Base
8
+ define_fields %w[status]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Monobank
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monobank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vergilet
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-07 00:00:00.000000000 Z
12
+ date: 2020-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashable
@@ -51,19 +51,21 @@ files:
51
51
  - lib/monobank/bank/currency.rb
52
52
  - lib/monobank/client.rb
53
53
  - lib/monobank/connection.rb
54
- - lib/monobank/endpoint.rb
55
54
  - lib/monobank/error.rb
55
+ - lib/monobank/methods/base.rb
56
+ - lib/monobank/methods/get.rb
57
+ - lib/monobank/methods/post.rb
56
58
  - lib/monobank/personal/client_info.rb
57
59
  - lib/monobank/personal/statement.rb
60
+ - lib/monobank/personal/webhook.rb
58
61
  - lib/monobank/resources/bank/currency.rb
59
62
  - lib/monobank/resources/base.rb
60
63
  - lib/monobank/resources/error.rb
61
64
  - lib/monobank/resources/personal/accounts.rb
62
65
  - lib/monobank/resources/personal/client_info.rb
63
66
  - lib/monobank/resources/personal/statement.rb
67
+ - lib/monobank/resources/personal/webhook.rb
64
68
  - lib/monobank/version.rb
65
- - spec/monobank_spec.rb
66
- - spec/spec_helper.rb
67
69
  homepage: https://github.com/vergilet/monobank
68
70
  licenses:
69
71
  - MIT
@@ -86,10 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
88
  - !ruby/object:Gem::Version
87
89
  version: '0'
88
90
  requirements: []
89
- rubygems_version: 3.0.2
91
+ rubygems_version: 3.0.6
90
92
  signing_key:
91
93
  specification_version: 4
92
94
  summary: Unofficial Ruby Gem for Monobank API.
93
- test_files:
94
- - spec/spec_helper.rb
95
- - spec/monobank_spec.rb
95
+ test_files: []
@@ -1,24 +0,0 @@
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
@@ -1,9 +0,0 @@
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
@@ -1,14 +0,0 @@
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