coins_paid_api 1.0.7 → 1.3.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: 344f70ed054fc21fbd7b99ab74a2be43af3c18faf178b8dc0e507bb8787c5361
4
- data.tar.gz: 67d6cec032e4ee37950ae18f25e3319fbe64cd55aa7403116a93463197d4d52f
3
+ metadata.gz: 37ab167accc89938d66af72334820f588f3eb25c27394b648ddac3b98ab90ef1
4
+ data.tar.gz: 0efb54ff9fb942ad1c689ed350a5d8bef491f963181dba8918b6240cf1259a85
5
5
  SHA512:
6
- metadata.gz: 5d5ffcbb104c5b277f4196328cafc70392606541b6c840493f1896b0a35436e2338e049e4811da19f13daca8071b7a60b0b0d7a3192397096ace769fa05cb960
7
- data.tar.gz: 13191a7d05cf3bd1cb8e0ef1d4e3fa005c4485b23233b080be73e1ae9481fda68ac262b761edc795d31039ec6c70d2605b96a4b8295a6ea040c3722e544ee663
6
+ metadata.gz: df5a0d70589d54e6fc919da11bbdf37bcf1ca8ec4df40a80f2f14d424c0e2c56a73169fe6bf23a9bd142a0f1e7160ad5ada5b455292441722e2a455107c0f925
7
+ data.tar.gz: 0b0a112f21a5d88455af67b2be4aeefc0e45a7d125c1d341cafd3f4b1785d486864a6bdf73b19ee57c2600713ffbf2e1cddd3144e1108e6632babcdad416e58c
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.7'
4
+ s.version = '1.3.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,7 +6,12 @@ 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
@@ -7,8 +7,8 @@ module CoinsPaid
7
7
  attribute :foreign_id, Types::Coercible::String
8
8
  attribute :amount, Types::Coercible::String
9
9
  attribute :currency, Types::String
10
- attribute :convert_to, Types::String
11
10
  attribute :address, Types::String
11
+ attribute? :convert_to, Types::String
12
12
  attribute? :tag, Types::String
13
13
  end
14
14
 
@@ -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: '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
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,28 @@ 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: 'BTC',
52
+ address: 'abc123'
53
+ }
54
+ end
55
+ let(:request_body) { request_data.to_json }
56
+
57
+ context 'request does not include tag parameter or convert_to' do
58
+ let(:request_data) { base_request_data }
59
+ it_behaves_like 'CoinsPaid API withdrawal'
60
+ end
54
61
 
55
62
  context 'request includes tag parameter' do
56
- it_behaves_like 'CoinsPaid API withdrawal', request_data: base_request_data.merge(tag: 'thetag')
63
+ let(:request_data) { base_request_data.merge(tag: 'thetag') }
64
+ it_behaves_like 'CoinsPaid API withdrawal'
57
65
  end
58
66
 
59
- context 'request does not include tag parameter' do
60
- it_behaves_like 'CoinsPaid API withdrawal', request_data: base_request_data
67
+ context 'request includes convert_to' do
68
+ let(:request_data) { base_request_data.merge(currency: 'EUR', convert_to: 'BTC') }
69
+ it_behaves_like 'CoinsPaid API withdrawal'
61
70
  end
62
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coins_paid_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Biserov(artembiserov)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-27 00:00:00.000000000 Z
12
+ date: 2022-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-struct
@@ -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