coins_paid_api 1.0.5 → 1.1.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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +64 -0
- data/coins_paid_api.gemspec +1 -1
- data/lib/coins_paid/api/take_address.rb +7 -2
- data/lib/coins_paid/api/withdrawal.rb +1 -0
- data/lib/coins_paid/api.rb +3 -6
- data/spec/currencies_list_spec.rb +3 -2
- data/spec/request_examples.rb +3 -3
- data/spec/spec_helper.rb +7 -0
- data/spec/take_address_spec.rb +50 -24
- data/spec/withdrawal_spec.rb +27 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccc1bf1ca520dd1c060f67d7cafbbb031d361afa643bed0018f600ea34e4af69
|
4
|
+
data.tar.gz: fbf3c4991c2906cf6071c27e1896c0d97b2439392ef8a2672e5da114301af951
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12a086063c8d671e6c9efbfc186e801bb3e099116adc02ee98eed280a82b675c836acf817dccf660ef772ee66d4420ebc9e9717bf1c693b971e4b1d2509e29af
|
7
|
+
data.tar.gz: ce88ae1135b1bd64bb809311072e899b357c31634de096a11e14ca2d39427c71b4769ba47e620a5c693f9e204ed9d4bcf210b2c98d28d32164cd7c227d2f5020
|
data/.gitignore
CHANGED
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/**/*'
|
data/coins_paid_api.gemspec
CHANGED
@@ -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
|
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,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'
|
data/lib/coins_paid/api.rb
CHANGED
@@ -35,18 +35,15 @@ 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
42
|
)
|
43
43
|
end
|
44
44
|
|
45
|
-
def withdraw(
|
46
|
-
Requester.call(
|
47
|
-
Withdrawal,
|
48
|
-
foreign_id: foreign_id, amount: amount, currency: currency, convert_to: convert_to, address: address
|
49
|
-
)
|
45
|
+
def withdraw(data)
|
46
|
+
Requester.call(Withdrawal, data)
|
50
47
|
end
|
51
48
|
|
52
49
|
def currencies_list
|
@@ -3,7 +3,8 @@
|
|
3
3
|
require_relative './request_examples'
|
4
4
|
|
5
5
|
describe CoinsPaid::API, '.currencies_list' do
|
6
|
-
endpoint
|
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'
|
69
|
+
it_behaves_like 'CoinsPaid API error handling'
|
69
70
|
end
|
data/spec/request_examples.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.shared_context 'CoinsPaid API request' do
|
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(
|
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
|
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
|
data/spec/take_address_spec.rb
CHANGED
@@ -3,43 +3,69 @@
|
|
3
3
|
require_relative './request_examples'
|
4
4
|
|
5
5
|
describe CoinsPaid::API, '.take_address' do
|
6
|
-
endpoint
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
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' =>
|
23
|
+
'convert_to' => api_convert_to,
|
29
24
|
'address' => '12983h13ro1hrt24it432t',
|
30
|
-
'tag' =>
|
25
|
+
'tag' => 123,
|
31
26
|
'foreign_id' => 'user-id:2048'
|
32
|
-
}
|
27
|
+
}.compact
|
33
28
|
}
|
34
29
|
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
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
|
-
|
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
|
data/spec/withdrawal_spec.rb
CHANGED
@@ -2,16 +2,10 @@
|
|
2
2
|
|
3
3
|
require_relative './request_examples'
|
4
4
|
|
5
|
-
|
6
|
-
endpoint
|
7
|
-
|
8
|
-
|
9
|
-
amount: '0.01',
|
10
|
-
currency: 'EUR',
|
11
|
-
convert_to: 'BTC',
|
12
|
-
address: 'abc123'
|
13
|
-
}
|
14
|
-
include_context 'CoinsPaid API request', request_data: request_data
|
5
|
+
RSpec.shared_examples 'CoinsPaid API withdrawal' do
|
6
|
+
let(:endpoint) { 'https://app.coinspaid.com/api/v2/withdrawal/crypto' }
|
7
|
+
|
8
|
+
include_context 'CoinsPaid API request'
|
15
9
|
|
16
10
|
let(:response_data) do
|
17
11
|
{
|
@@ -48,3 +42,26 @@ describe CoinsPaid::API, '.withdraw' do
|
|
48
42
|
end
|
49
43
|
end
|
50
44
|
end
|
45
|
+
|
46
|
+
describe CoinsPaid::API, '.withdraw' do
|
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 }
|
57
|
+
|
58
|
+
context 'request includes tag parameter' do
|
59
|
+
let(:request_data) { base_request_data.merge(tag: 'thetag') }
|
60
|
+
it_behaves_like 'CoinsPaid API withdrawal'
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'request does not include tag parameter' do
|
64
|
+
let(:request_data) { base_request_data }
|
65
|
+
it_behaves_like 'CoinsPaid API withdrawal'
|
66
|
+
end
|
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
|
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:
|
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
|