coins_paid_rails 1.1.4 → 1.1.6

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: ca1acc712539224bd9600c8c093b27df63ff221cd6429b8e6ea9c7518a95b99f
4
- data.tar.gz: 0e78adb0b3a02f21d54cc66c81de396c7a2e8201c35ca692953055c66e011337
3
+ metadata.gz: df7e3a2b5d34d191761e465f1c8a82d4b7711d93b39bc03eebe9bfadccb339ec
4
+ data.tar.gz: 8dbf452034f18709317f11f0318b37e71cc32d8f3fcf7b936b1d0c0a754a34ae
5
5
  SHA512:
6
- metadata.gz: 3a75ccbe6564df90c140aa4bbf76039819a744cdb1181e27d4bfd83c14ec3b594273c85f411d0165e10537791a20c14bb89f947b2a451a94f0de3490be0721bc
7
- data.tar.gz: 420f371a7800e275c953a6dbd039b9e0a30509829139de1d0dfd0b229641d46b0fb1b704b0aaa3813deada9ecdd6f1d7cf2af7a80e7855c9d31748e8c6b85231
6
+ metadata.gz: 86fb4482d7847a7b2acdcc22a2d17857dc290e0a271095ba932489bff59f05466ac12568a364ccf6fdc02081e9e0e21d787f4b0829e36f58560f4d883b365543
7
+ data.tar.gz: 2d4ccb6c6cb43dc7d6392e34908b8349fa274fd6aef8ba8d92ec514eebe541f274fd6e52f40ba9d831e02d06a3e3ac0b053c41bef291eda513b2247aa316bf2e
data/Gemfile CHANGED
@@ -6,4 +6,5 @@ group :test do
6
6
  gem 'simplecov', require: false
7
7
  gem 'sqlite3'
8
8
  gem 'rspec-its'
9
+ gem 'rqrcode'
9
10
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coins_paid_rails (1.1.3)
4
+ coins_paid_rails (1.1.6)
5
5
  activerecord (>= 4.2.0)
6
6
  coins_paid_api (~> 1.0)
7
7
  dry-initializer (~> 3.0)
@@ -36,6 +36,7 @@ GEM
36
36
  tzinfo (~> 1.1)
37
37
  arel (9.0.0)
38
38
  builder (3.2.4)
39
+ chunky_png (1.4.0)
39
40
  coins_paid_api (1.0.5)
40
41
  dry-struct (~> 1.0)
41
42
  faraday (~> 0.12)
@@ -50,11 +51,11 @@ GEM
50
51
  dry-container (0.7.2)
51
52
  concurrent-ruby (~> 1.0)
52
53
  dry-configurable (~> 0.1, >= 0.1.3)
53
- dry-core (0.5.0)
54
+ dry-core (0.6.0)
54
55
  concurrent-ruby (~> 1.0)
55
56
  dry-inflector (0.2.0)
56
57
  dry-initializer (3.0.4)
57
- dry-logic (1.1.0)
58
+ dry-logic (1.2.0)
58
59
  concurrent-ruby (~> 1.0)
59
60
  dry-core (~> 0.5, >= 0.5)
60
61
  dry-struct (1.4.0)
@@ -102,6 +103,10 @@ GEM
102
103
  rake (>= 0.8.7)
103
104
  thor (>= 0.19.0, < 2.0)
104
105
  rake (13.0.1)
106
+ rqrcode (2.1.0)
107
+ chunky_png (~> 1.0)
108
+ rqrcode_core (~> 1.0)
109
+ rqrcode_core (1.2.0)
105
110
  rspec-core (3.10.0)
106
111
  rspec-support (~> 3.10.0)
107
112
  rspec-expectations (3.10.0)
@@ -138,6 +143,7 @@ PLATFORMS
138
143
 
139
144
  DEPENDENCIES
140
145
  coins_paid_rails!
146
+ rqrcode
141
147
  rspec-its
142
148
  rspec-rails
143
149
  simplecov
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'coins_paid_rails'
3
3
  s.authors = ['Artem Biserov(artembiserov)', 'Oleg Ivanov(morhekil)']
4
- s.version = '1.1.4'
4
+ s.version = '1.1.6'
5
5
  s.files = `git ls-files`.split("\n")
6
6
  s.summary = 'CoinsPaid Rails Integration'
7
7
  s.license = 'MIT'
@@ -10,15 +10,15 @@ module CoinsPaid
10
10
  end
11
11
 
12
12
  def url
13
- "#{token_type}:#{address}?label=#{encode(label)}&message=#{encode(message)}"
13
+ known_url? ? "#{token_type}:#{address.address}?label=#{encode(label)}&message=#{encode(message)}" : nil
14
14
  end
15
15
 
16
16
  def address
17
- @address ||= CoinsPaid.address(player_id, currency: currency).address
17
+ @address ||= CoinsPaid.address(player_id, currency: currency)
18
18
  end
19
19
 
20
20
  def svg
21
- RQRCode::QRCode.new(url).as_svg(
21
+ RQRCode::QRCode.new(url || address.address).as_svg(
22
22
  offset: 0,
23
23
  color: '000',
24
24
  shape_rendering: 'crispEdges',
@@ -30,11 +30,15 @@ module CoinsPaid
30
30
  private
31
31
 
32
32
  def token_type
33
- ADDRESS_PREFIXES.fetch(currency)
33
+ ADDRESS_PREFIXES[currency]
34
34
  end
35
35
 
36
36
  def encode(string)
37
37
  URI.encode_www_form_component(string)
38
38
  end
39
+
40
+ def known_url?
41
+ token_type.present?
42
+ end
39
43
  end
40
44
  end
data/spec/qr_code_spec.rb CHANGED
@@ -2,25 +2,58 @@
2
2
 
3
3
  describe CoinsPaid, '.qr_code' do
4
4
  let(:foreign_id) { 123 }
5
+ let(:currency) { 'BTC' }
6
+ let(:address) { 'abc123' }
5
7
  let(:coins_paid_address) do
6
8
  instance_double CoinsPaid::CoinsPaidAddress,
7
- currency: 'BTC',
8
- address: 'abc123'
9
+ currency: currency,
10
+ address: address
9
11
  end
10
12
  subject(:qr_code) do
11
13
  described_class.qr_code(
12
14
  foreign_id,
13
- currency: 'BTC',
15
+ currency: currency,
14
16
  label: 'RedStar deposit',
15
17
  message: 'Make a deposit to RedStar'
16
18
  )
17
19
  end
18
20
 
19
21
  before do
20
- allow(CoinsPaid).to receive(:address).with(foreign_id, currency: 'BTC').and_return(coins_paid_address)
22
+ allow(CoinsPaid).to receive(:address).with(foreign_id, currency: currency).and_return(coins_paid_address)
21
23
  end
22
24
 
23
- describe '#payment_url' do
24
- its(:url) { is_expected.to eq 'bitcoin:abc123?label=RedStar+deposit&message=Make+a+deposit+to+RedStar' }
25
+ context 'it is known how to build payment url for the currency' do
26
+ let(:currency) { 'BTC' }
27
+ let(:url) { "bitcoin:#{address}?label=RedStar+deposit&message=Make+a+deposit+to+RedStar" }
28
+
29
+ describe '#url' do
30
+ its(:url) { is_expected.to eq url }
31
+ end
32
+
33
+ describe '#svg' do
34
+ it 'encodes payment url' do
35
+ expect(RQRCode::QRCode).to receive(:new).with(url).and_call_original
36
+ qr_code.svg
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'it is not known how to build payment url for the currency' do
42
+ let(:currency) { 'BNB' }
43
+
44
+ describe '#url' do
45
+ its(:url) { is_expected.to be_nil }
46
+ end
47
+
48
+ describe '#svg' do
49
+ it 'encodes payment address' do
50
+ expect(RQRCode::QRCode).to receive(:new).with(address).and_call_original
51
+ qr_code.svg
52
+ end
53
+ end
54
+ end
55
+
56
+ context '#address' do
57
+ its(:address) { is_expected.to eq coins_paid_address }
25
58
  end
26
59
  end
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,7 @@ require 'active_record'
9
9
  require "active_record/railtie"
10
10
  require 'rspec/rails'
11
11
  require 'rspec/its'
12
+ require 'rqrcode'
12
13
 
13
14
  require 'coins_paid_rails'
14
15
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coins_paid_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.6
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-07-08 00:00:00.000000000 Z
12
+ date: 2021-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coins_paid_api
@@ -81,8 +81,8 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
- description:
85
- email:
84
+ description:
85
+ email:
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -107,11 +107,11 @@ files:
107
107
  - spec/qr_code_spec.rb
108
108
  - spec/spec_helper.rb
109
109
  - spec/support/database/create_table.rb
110
- homepage:
110
+ homepage:
111
111
  licenses:
112
112
  - MIT
113
113
  metadata: {}
114
- post_install_message:
114
+ post_install_message:
115
115
  rdoc_options: []
116
116
  require_paths:
117
117
  - lib
@@ -126,9 +126,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubyforge_project:
129
+ rubyforge_project:
130
130
  rubygems_version: 2.7.6
131
- signing_key:
131
+ signing_key:
132
132
  specification_version: 4
133
133
  summary: CoinsPaid Rails Integration
134
134
  test_files: []