coins_paid_api 1.0.6 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 020d45404c81037d89565ba5e7dcb231982db444abdbd00a6f1535bfd9e73170
4
- data.tar.gz: 84f0ab1f61a80fe45dedca5cc0d0ce8467e5328315fc75d0f3812702e84774a4
3
+ metadata.gz: 14dc12db1d0e7f9f90746feb4e0ec39f491bdf2533984282e197cc87babad6dd
4
+ data.tar.gz: 34baccc03be0e0fd327f7240f71a58fa181805ae835a105e158db3863722610b
5
5
  SHA512:
6
- metadata.gz: cfd4a488e8434dd0ccc78b68feed059545f1d193bbaf2b226e597da371b04b454f459c4a157f55d56750805181048135322ef1671c09f82c78bb8e83186fc50f
7
- data.tar.gz: c7ad6dea7bc2c80882df508506df798d7864cb59073db39f14cf46df55ea8d904d20a4416daf4e26ce8c5eee44570cd3c41b8a451760b2642f1ad1b9dc6761b9
6
+ metadata.gz: cb016be8a69caefbb956d4d7939164f78e4d6fed5b6f3d3b1dba050284a57e6c882725e60a7f2439a80483aad724e3eb9b6647ba76286ffff696bfa1edd70e2d
7
+ data.tar.gz: 345be14c726a21cd9f4f21ac98dc11aa46ff1a95b92cf690a445f0d2dbad90252106bf1d4fb7aec0f1f41fc59d42f497f83b04bdcfaeec7b303f498a8cacab50
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  /*.gem
2
2
  /Gemfile.lock
3
+ spec/examples.txt
data/.rubocop.yml ADDED
@@ -0,0 +1,64 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rails
4
+ AllCops:
5
+ TargetRubyVersion: 2.7
6
+ NewCops: enable
7
+ SuggestExtensions: false
8
+
9
+ Naming/MethodParameterName:
10
+ MinNameLength: 1
11
+ Naming/VariableNumber:
12
+ Enabled: false
13
+
14
+ Lint/MissingCopEnableDirective:
15
+ Enabled: false
16
+
17
+ Layout/EmptyLineAfterMagicComment:
18
+ Enabled: false
19
+ Layout/LineLength:
20
+ Max: 120
21
+ Layout/MultilineOperationIndentation:
22
+ Enabled: false
23
+ Layout/MultilineMethodCallIndentation:
24
+ EnforcedStyle: indented_relative_to_receiver
25
+
26
+ Style/AsciiComments:
27
+ Enabled: false
28
+ Style/ClassAndModuleChildren:
29
+ Enabled: false
30
+ Style/Documentation:
31
+ Enabled: false
32
+ Style/FormatStringToken:
33
+ Enabled: false
34
+ Style/Lambda:
35
+ Enabled: false
36
+ Style/LambdaCall:
37
+ Enabled: false
38
+ Style/ModuleFunction:
39
+ Enabled: false
40
+ Style/PercentLiteralDelimiters:
41
+ PreferredDelimiters:
42
+ '%i': '()'
43
+ '%I': '()'
44
+ '%r': '{}'
45
+ '%w': '()'
46
+ '%W': '()'
47
+ Style/SignalException:
48
+ EnforcedStyle: 'only_raise'
49
+
50
+ Metrics/AbcSize:
51
+ Exclude:
52
+ - 'config/**/*'
53
+ - 'db/**/*'
54
+ - 'spec/**/*'
55
+ Metrics/BlockLength:
56
+ Exclude:
57
+ - 'config/**/*'
58
+ - 'db/**/*'
59
+ - 'spec/**/*'
60
+ Metrics/MethodLength:
61
+ Exclude:
62
+ - 'config/**/*'
63
+ - 'db/**/*'
64
+ - 'spec/**/*'
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'coins_paid_api'
3
3
  s.authors = ['Artem Biserov(artembiserov)', 'Oleg Ivanov(morhekil)']
4
- s.version = '1.0.6'
4
+ s.version = '1.2.0'
5
5
  s.files = `git ls-files`.split("\n")
6
6
  s.summary = 'Coins Paid Integration'
7
7
  s.license = 'MIT'
@@ -23,10 +23,12 @@ module CoinsPaid
23
23
  end
24
24
 
25
25
  attribute? :currency_sent do
26
+ attribute :currency, Types::String
26
27
  attribute :amount, Types::String
27
28
  end
28
29
 
29
30
  attribute? :currency_received do
31
+ attribute :currency, Types::String
30
32
  attribute :amount, Types::String
31
33
  attribute? :amount_minus_fee, Types::String
32
34
  end
@@ -6,13 +6,18 @@ module CoinsPaid
6
6
  class Request < Dry::Struct
7
7
  attribute :foreign_id, Types::Coercible::String
8
8
  attribute :currency, Types::String
9
- attribute :convert_to, Types::String
9
+ attribute :convert_to, Types::String.optional
10
+
11
+ def to_hash
12
+ convert_value = convert_to != currency ? convert_to : nil
13
+ super().merge(convert_to: convert_value).compact
14
+ end
10
15
  end
11
16
 
12
17
  class Response < Dry::Struct
13
18
  attribute :external_id, Types::Integer
14
19
  attribute :address, Types::String
15
- attribute :tag, Types::String.optional
20
+ attribute :tag, Types::Coercible::String.optional
16
21
  end
17
22
 
18
23
  PATH = 'addresses/take'
@@ -35,7 +35,7 @@ module CoinsPaid
35
35
  yield self
36
36
  end
37
37
 
38
- def take_address(foreign_id:, currency:, convert_to:)
38
+ def take_address(foreign_id:, currency:, convert_to: nil)
39
39
  Requester.call(
40
40
  TakeAddress,
41
41
  foreign_id: foreign_id, currency: currency, convert_to: convert_to
@@ -42,11 +42,8 @@ describe CoinsPaid::API, '.callback' do
42
42
  { transaction_type: 'blockchain', type: 'deposit', id: 714576 },
43
43
  { transaction_type: 'exchange', type: 'exchange', id: 714577 }
44
44
  ],
45
- currency_sent: { amount: '0.01000000' },
46
- currency_received: {
47
- amount_minus_fee: '90',
48
- amount: '84.17070222'
49
- }
45
+ currency_sent: { currency: 'BTC', amount: '0.01000000' },
46
+ currency_received: { currency: 'EUR', amount_minus_fee: '90', amount: '84.17070222' }
50
47
  }
51
48
  end
52
49
 
@@ -91,10 +88,8 @@ describe CoinsPaid::API, '.callback' do
91
88
  { transaction_type: 'exchange', type: 'exchange', id: 1 },
92
89
  { transaction_type: 'blockchain', type: 'withdrawal', id: 1 }
93
90
  ],
94
- currency_sent: { amount: '381' },
95
- currency_received: {
96
- amount: '0.01000000'
97
- }
91
+ currency_sent: { currency: 'EUR', amount: '381' },
92
+ currency_received: { currency: 'BTC', amount: '0.01000000' }
98
93
  }
99
94
  end
100
95
 
@@ -132,8 +127,8 @@ describe CoinsPaid::API, '.callback' do
132
127
  status: 'confirmed',
133
128
  foreign_id: '',
134
129
  error: '',
135
- currency_sent: { amount: "0.56114000"},
136
- currency_received: { amount: "80.21790617"},
130
+ currency_sent: { currency: 'ETH', amount: '0.56114000'},
131
+ currency_received: { currency: 'EUR', amount: '80.21790617'},
137
132
  transactions: [
138
133
  { transaction_type: 'exchange', type: 'exchange', id: 714576 },
139
134
  ]
@@ -3,7 +3,8 @@
3
3
  require_relative './request_examples'
4
4
 
5
5
  describe CoinsPaid::API, '.currencies_list' do
6
- endpoint = 'https://app.coinspaid.com/api/v2/currencies/list'
6
+ let(:endpoint) { 'https://app.coinspaid.com/api/v2/currencies/list' }
7
+ let(:request_body) { "{}" }
7
8
  include_context 'CoinsPaid API request'
8
9
 
9
10
  let(:expected_currencies) do
@@ -65,5 +66,5 @@ describe CoinsPaid::API, '.currencies_list' do
65
66
  expect(response).to match_array currencies
66
67
  end
67
68
 
68
- it_behaves_like 'CoinsPaid API error handling', endpoint: endpoint
69
+ it_behaves_like 'CoinsPaid API error handling'
69
70
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.shared_context 'CoinsPaid API request' do |request_data: {}|
3
+ RSpec.shared_context 'CoinsPaid API request' do
4
4
  let(:signature) { 'c01dc0ffee' }
5
5
  let(:request_signature_headers) do
6
6
  {
@@ -10,11 +10,11 @@ RSpec.shared_context 'CoinsPaid API request' do |request_data: {}|
10
10
  end
11
11
 
12
12
  before do
13
- allow(CoinsPaid::API::Signature).to receive(:generate).with(request_data.to_json).and_return signature
13
+ allow(CoinsPaid::API::Signature).to receive(:generate).with(request_body).and_return signature
14
14
  end
15
15
  end
16
16
 
17
- RSpec.shared_examples 'CoinsPaid API error handling' do |endpoint:, request_body: '{}'|
17
+ RSpec.shared_examples 'CoinsPaid API error handling' do
18
18
  context 'when coins paid responded with validation errors' do
19
19
  let(:response_data) do
20
20
  {
data/spec/spec_helper.rb CHANGED
@@ -10,3 +10,10 @@ require 'webmock/rspec'
10
10
  require 'pry'
11
11
  require 'coins_paid_api'
12
12
  Dir['./spec/support/**/*.rb'].each { |f| require f }
13
+
14
+ RSpec.configure do |config|
15
+ config.filter_run focus: true
16
+ config.alias_example_to :fit, focus: true
17
+ config.run_all_when_everything_filtered = true
18
+ config.example_status_persistence_file_path = 'spec/examples.txt'
19
+ end
@@ -3,43 +3,69 @@
3
3
  require_relative './request_examples'
4
4
 
5
5
  describe CoinsPaid::API, '.take_address' do
6
- endpoint = 'https://app.coinspaid.com/api/v2/addresses/take'
7
- request_data = {
8
- foreign_id: 'user-id:2048',
9
- currency: 'BTC',
10
- convert_to: 'EUR'
11
- }
12
- include_context 'CoinsPaid API request', request_data: request_data
13
-
14
- let(:expected_address_attributes) do
15
- {
16
- external_id: 1,
17
- address: '12983h13ro1hrt24it432t',
18
- tag: 'tag-123'
19
- }
6
+ let(:endpoint) { 'https://app.coinspaid.com/api/v2/addresses/take' }
7
+
8
+ let(:foreign_id) { 'user-id:2048' }
9
+ let(:currency) { 'BTC' }
10
+
11
+ let(:request_data) do
12
+ { foreign_id: foreign_id, currency: currency, convert_to: api_convert_to }.compact
20
13
  end
21
- subject(:take_address) { described_class.take_address(request_data) }
14
+ let(:request_body) { request_data.to_json }
15
+
16
+ include_context 'CoinsPaid API request'
22
17
 
23
18
  let(:response_data) do
24
19
  {
25
20
  'data' => {
26
21
  'id' => 1,
27
22
  'currency' => 'BTC',
28
- 'convert_to' => 'EUR',
23
+ 'convert_to' => api_convert_to,
29
24
  'address' => '12983h13ro1hrt24it432t',
30
- 'tag' => 'tag-123',
25
+ 'tag' => 123,
31
26
  'foreign_id' => 'user-id:2048'
32
- }
27
+ }.compact
33
28
  }
34
29
  end
35
30
 
36
- it 'returns valid response if successful' do
37
- stub_request(:post, endpoint)
38
- .with(body: request_data, headers: request_signature_headers)
39
- .to_return(status: 201, body: response_data.to_json)
31
+ let(:args) do
32
+ { foreign_id: 'user-id:2048', currency: 'BTC', convert_to: args_convert_to }.compact
33
+ end
34
+ subject(:take_address) { described_class.take_address(args) }
35
+
36
+ shared_examples 'successful request' do
37
+ it 'returns valid response' do
38
+ stub_request(:post, endpoint)
39
+ .with(body: request_body, headers: request_signature_headers)
40
+ .to_return(status: 201, body: response_data.to_json)
41
+
42
+ expected_address_attributes = {
43
+ external_id: 1,
44
+ address: '12983h13ro1hrt24it432t',
45
+ tag: '123'
46
+ }
47
+ expect(take_address).to be_struct_with_params(
48
+ CoinsPaid::API::TakeAddress::Response, expected_address_attributes
49
+ )
50
+ end
51
+ end
40
52
 
41
- expect(take_address).to be_struct_with_params(CoinsPaid::API::TakeAddress::Response, expected_address_attributes)
53
+ context 'with explicit convert_to not matching address currency' do
54
+ let(:args_convert_to) { 'EUR' }
55
+ let(:api_convert_to) { 'EUR' }
56
+ it_behaves_like 'successful request'
57
+ it_behaves_like 'CoinsPaid API error handling'
42
58
  end
43
59
 
44
- it_behaves_like 'CoinsPaid API error handling', endpoint: endpoint, request_body: request_data
60
+ context 'with explicit convert_to matching address currency' do
61
+ let(:args_convert_to) { 'BTC' }
62
+ let(:api_convert_to) { nil }
63
+ it_behaves_like 'successful request'
64
+ end
65
+
66
+ context 'with nil convert_to' do
67
+ let(:args_convert_to) { nil }
68
+ let(:api_convert_to) { nil }
69
+ it_behaves_like 'successful request'
70
+ end
45
71
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  require_relative './request_examples'
4
4
 
5
- RSpec.shared_examples 'CoinsPaid API withdrawal' do |request_data:|
6
- endpoint = 'https://app.coinspaid.com/api/v2/withdrawal/crypto'
5
+ RSpec.shared_examples 'CoinsPaid API withdrawal' do
6
+ let(:endpoint) { 'https://app.coinspaid.com/api/v2/withdrawal/crypto' }
7
7
 
8
- include_context 'CoinsPaid API request', request_data: request_data
8
+ include_context 'CoinsPaid API request'
9
9
 
10
10
  let(:response_data) do
11
11
  {
@@ -44,19 +44,24 @@ RSpec.shared_examples 'CoinsPaid API withdrawal' do |request_data:|
44
44
  end
45
45
 
46
46
  describe CoinsPaid::API, '.withdraw' do
47
- base_request_data = {
48
- foreign_id: 'user-id:2048',
49
- amount: '0.01',
50
- currency: 'EUR',
51
- convert_to: 'BTC',
52
- address: 'abc123'
53
- }
47
+ let(:base_request_data) do
48
+ {
49
+ foreign_id: 'user-id:2048',
50
+ amount: '0.01',
51
+ currency: 'EUR',
52
+ convert_to: 'BTC',
53
+ address: 'abc123'
54
+ }
55
+ end
56
+ let(:request_body) { request_data.to_json }
54
57
 
55
58
  context 'request includes tag parameter' do
56
- it_behaves_like 'CoinsPaid API withdrawal', request_data: base_request_data.merge(tag: 'thetag')
59
+ let(:request_data) { base_request_data.merge(tag: 'thetag') }
60
+ it_behaves_like 'CoinsPaid API withdrawal'
57
61
  end
58
62
 
59
63
  context 'request does not include tag parameter' do
60
- it_behaves_like 'CoinsPaid API withdrawal', request_data: base_request_data
64
+ let(:request_data) { base_request_data }
65
+ it_behaves_like 'CoinsPaid API withdrawal'
61
66
  end
62
67
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coins_paid_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Biserov(artembiserov)
8
8
  - Oleg Ivanov(morhekil)
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-24 00:00:00.000000000 Z
12
+ date: 2022-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-struct
@@ -81,8 +81,8 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '3.7'
84
- description:
85
- email:
84
+ description:
85
+ email:
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -90,6 +90,7 @@ files:
90
90
  - ".circleci/config.yml"
91
91
  - ".gitignore"
92
92
  - ".rspec"
93
+ - ".rubocop.yml"
93
94
  - Gemfile
94
95
  - coins_paid_api.gemspec
95
96
  - lib/coins_paid/api.rb
@@ -112,11 +113,11 @@ files:
112
113
  - spec/support/shared/data.rb
113
114
  - spec/take_address_spec.rb
114
115
  - spec/withdrawal_spec.rb
115
- homepage:
116
+ homepage:
116
117
  licenses:
117
118
  - MIT
118
119
  metadata: {}
119
- post_install_message:
120
+ post_install_message:
120
121
  rdoc_options: []
121
122
  require_paths:
122
123
  - lib
@@ -131,9 +132,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  - !ruby/object:Gem::Version
132
133
  version: '0'
133
134
  requirements: []
134
- rubyforge_project:
135
+ rubyforge_project:
135
136
  rubygems_version: 2.7.6
136
- signing_key:
137
+ signing_key:
137
138
  specification_version: 4
138
139
  summary: Coins Paid Integration
139
140
  test_files: []