coins_paid_api 1.0.7 → 1.1.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: ccc1bf1ca520dd1c060f67d7cafbbb031d361afa643bed0018f600ea34e4af69
4
+ data.tar.gz: fbf3c4991c2906cf6071c27e1896c0d97b2439392ef8a2672e5da114301af951
5
5
  SHA512:
6
- metadata.gz: 5d5ffcbb104c5b277f4196328cafc70392606541b6c840493f1896b0a35436e2338e049e4811da19f13daca8071b7a60b0b0d7a3192397096ace769fa05cb960
7
- data.tar.gz: 13191a7d05cf3bd1cb8e0ef1d4e3fa005c4485b23233b080be73e1ae9481fda68ac262b761edc795d31039ec6c70d2605b96a4b8295a6ea040c3722e544ee663
6
+ metadata.gz: 12a086063c8d671e6c9efbfc186e801bb3e099116adc02ee98eed280a82b675c836acf817dccf660ef772ee66d4420ebc9e9717bf1c693b971e4b1d2509e29af
7
+ data.tar.gz: ce88ae1135b1bd64bb809311072e899b357c31634de096a11e14ca2d39427c71b4769ba47e620a5c693f9e204ed9d4bcf210b2c98d28d32164cd7c227d2f5020
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.1.0'
5
5
  s.files = `git ls-files`.split("\n")
6
6
  s.summary = 'Coins Paid Integration'
7
7
  s.license = 'MIT'
@@ -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
@@ -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
@@ -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,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,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.1.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-03-30 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