zold-ruby-sdk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d5f77cfaa341fc53d966cdc048bfbb2f4a9ec4ca7c3bd5cc407413bd5460ffe2
4
+ data.tar.gz: 6fe60f88eae2fb341d128771a20721d63667b9e8907b0cd5acfd4444953f0f35
5
+ SHA512:
6
+ metadata.gz: e706d2c9dc7c180ca92ccbaa60405055338075bc296acbd35ee706418d8c8b594ea6f262e0895c5a3e91a9b5ff9fd2ed9d88d900be7a40fb8430a1cf981990cf
7
+ data.tar.gz: 15f24cde6757b62815507deda97af55f12818f2cb66c8353c34c5ae72f81bbf5ad5a221d943d2d54fae243226fbb2af76f7ed8dfea9af59560177319ea308f57
data/.0pdd.yml ADDED
@@ -0,0 +1,9 @@
1
+ errors:
2
+ - yegor256@gmail.com
3
+ # alerts:
4
+ # github:
5
+ # - yegor256
6
+
7
+ tags:
8
+ - pdd
9
+ - bug
data/.gitattributes ADDED
@@ -0,0 +1,9 @@
1
+ # Check out all text files in UNIX format, with LF as end of line
2
+ # Don't change this file. If you have any ideas about it, please
3
+ # submit a separate issue about it and we'll discuss.
4
+
5
+ * text=auto eol=lf
6
+ *.rb ident
7
+ *.xml ident
8
+ *.png binary
9
+ *.pdf binary
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ coverage/
2
+ .idea/
3
+ *.gem
4
+ .bundle/
5
+ .DS_Store
6
+ rdoc/
7
+ Gemfile.lock
8
+ tmp/
9
+ lib/score_suffix
data/.pdd ADDED
@@ -0,0 +1,7 @@
1
+ --source=.
2
+ --verbose
3
+ --exclude target/**/*
4
+ --exclude coverage/**/*
5
+ --rule min-words:20
6
+ --rule min-estimate:15
7
+ --rule max-estimate:90
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.5
4
+
5
+ Layout/EmptyLineAfterGuardClause:
6
+ Enabled: false
7
+ Layout/EndOfLine:
8
+ EnforcedStyle: lf
9
+ Metrics/AbcSize:
10
+ Max: 45
11
+ Metrics/BlockLength:
12
+ Max: 30
13
+ Metrics/MethodLength:
14
+ Max: 40
15
+ Metrics/ClassLength:
16
+ Max: 180
17
+ Metrics/ParameterLists:
18
+ Max: 7
19
+ Layout/AlignParameters:
20
+ Enabled: false
21
+ Metrics/CyclomaticComplexity:
22
+ Max: 20
23
+ Metrics/PerceivedComplexity:
24
+ Max: 20
data/.rultor.yml ADDED
@@ -0,0 +1,26 @@
1
+ assets:
2
+ rubygems.yml: zerocracy/home#assets/rubygems.yml
3
+ install: |-
4
+ export GEM_HOME=~/.ruby
5
+ export GEM_PATH=$GEM_HOME:$GEM_PATH
6
+ release:
7
+ script: |-
8
+ bundle install
9
+ rake
10
+ rm -rf *.gem
11
+ sed -i "s/0\.0\.0/${tag}/g" zold-ruby-sdk.gemspec
12
+ git add zold-ruby-sdk.gemspec
13
+ git commit -m "Version set to ${tag}"
14
+ gem build zold-ruby-sdk.gemspec
15
+ chmod 0600 ../rubygems.yml
16
+ gem push *.gem --config-file ../rubygems.yml
17
+ commanders:
18
+ - yegor256
19
+ architect:
20
+ - yegor256
21
+ merge:
22
+ commanders: []
23
+ script: |-
24
+ bundle install
25
+ rake
26
+ deploy: {}
data/.simplecov ADDED
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ if Gem.win_platform? then
24
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
25
+ SimpleCov::Formatter::HTMLFormatter
26
+ ]
27
+ SimpleCov.start do
28
+ add_filter "/test/"
29
+ add_filter "/features/"
30
+ end
31
+ else
32
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
33
+ [SimpleCov::Formatter::HTMLFormatter]
34
+ )
35
+ SimpleCov.start do
36
+ add_filter "/test/"
37
+ add_filter "/features/"
38
+ # minimum_coverage 30
39
+ end
40
+ end
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.3.3
5
+ - 2.4.5
6
+ cache: bundler
7
+ branches:
8
+ only:
9
+ - master
10
+ install:
11
+ - travis_retry bundle update
12
+ - gem install pdd
13
+ - sudo apt-get install cppcheck
14
+ script:
15
+ - pdd -f /dev/null
16
+ - cppcheck --enable=all --quiet --suppress=unusedFunction .
17
+ - export RUBYOPT="-W0"
18
+ - rake --quiet
19
+ after_success:
20
+ - "bash <(curl -s https://codecov.io/bash)"
data/Gemfile ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ source 'https://rubygems.org'
24
+ ruby '2.6.0'
25
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2018-2019 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ <img src="http://www.zold.io/logo.svg" width="92px" height="92px"/>
2
+
3
+ [![Donate via Zerocracy](https://www.0crat.com/contrib-badge/CAZPZR9FS.svg)](https://www.0crat.com/contrib/CAZPZR9FS)
4
+
5
+ [![EO principles respected here](http://www.elegantobjects.org/badge.svg)](http://www.elegantobjects.org)
6
+ [![Managed by Zerocracy](https://www.0crat.com/badge/CAZPZR9FS.svg)](https://www.0crat.com/p/CAZPZR9FS)
7
+ [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/zold)](http://www.rultor.com/p/yegor256/zold)
8
+ [![We recommend RubyMine](http://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
9
+
10
+ [![Build Status](https://travis-ci.org/zold-io/zold-ruby-sdk.svg)](https://travis-ci.org/zold-io/zold-ruby-sdk)
11
+ [![PDD status](http://www.0pdd.com/svg?name=zold-io/zold-ruby-sdk)](http://www.0pdd.com/p?name=zold-io/zold-ruby-sdk)
12
+ [![Gem Version](https://badge.fury.io/rb/zold-ruby-sdk.svg)](http://badge.fury.io/rb/zold-ruby-sdk)
13
+ [![Test Coverage](https://img.shields.io/codecov/c/github/zold-io/zold-ruby-sdk.svg)](https://codecov.io/github/zold-io/zold-ruby-sdk?branch=master)
14
+
15
+ Here is the [White Paper](https://papers.zold.io/wp.pdf).
16
+
17
+ Join our [Telegram group](https://t.me/zold_io) to discuss it all live.
18
+
19
+ The license is [MIT](https://github.com/zold-io/zold-ruby-sdk/blob/master/LICENSE.txt).
20
+
21
+ This is a simple Ruby SDK for making payments, checking balances, and finding transactions in
22
+ Zold wallets via [WTS](https://wts.zold.io) system.
23
+
24
+ First, you install it:
25
+
26
+ ```
27
+ gem install zold-ruby-sdk
28
+ ```
29
+
30
+ Then, you get your API key [here](https://wts.zold.io/api).
31
+
32
+ The, you make an instance of class `Zold::WTS`:
33
+
34
+ ```ruby
35
+ require 'zold/wts'
36
+ wts = Zold::WTS.new(key)
37
+ ```
38
+
39
+ Now you can pull your wallet and then check its balance:
40
+
41
+ ```ruby
42
+ job = wts.pull # Initiate PULL and returns the unique ID of the job
43
+ wts.wait(job) # Wait for the job to finish
44
+ b = wts.balance # Retrieve the balance as an instance of Zold::Amount
45
+ puts b
46
+ ```
47
+
48
+ To make a payment you will need to know your
49
+ [keygap](https://blog.zold.io/2018/07/18/keygap.html):
50
+
51
+ ```ruby
52
+ job = wts.pay(keygap, 'yegor256', '19.95', 'For pizza') # Initiate a payment request
53
+ wts.wait(job) # Wait for the job to finish
54
+ ```
55
+
56
+ To find a payment in your wallet, you do this (don't forget to `pull` first):
57
+
58
+ ```ruby
59
+ # Finds all payments that match this query and returns
60
+ # an array of Zold::Txn objects.
61
+ txns = wts.find(id: '123', details: /pizza/)
62
+ ```
63
+
64
+ That's it.
65
+
66
+ # How to contribute
67
+
68
+ Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
69
+ Make sure you build is green before you contribute
70
+ your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
71
+ [Bundler](https://bundler.io/) installed. Then:
72
+
73
+ ```
74
+ $ bundle update
75
+ $ rake
76
+ ```
77
+
78
+ If it's clean and you don't see any error messages, submit your pull request.
data/Rakefile ADDED
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'rubygems'
24
+ require 'rake'
25
+ require 'rdoc'
26
+ require 'rake/clean'
27
+
28
+ def name
29
+ @name ||= File.basename(Dir['*.gemspec'].first, '.*')
30
+ end
31
+
32
+ def version
33
+ Gem::Specification.load(Dir['*.gemspec'].first).version
34
+ end
35
+
36
+ task default: %i[clean test rubocop copyright]
37
+
38
+ require 'rake/testtask'
39
+ desc 'Run all unit tests'
40
+ Rake::TestTask.new(:test) do |test|
41
+ ENV['TEST_QUIET_LOG'] = 'true' if ARGV.include?('--quiet')
42
+ Rake::Cleaner.cleanup_files(['coverage'])
43
+ test.libs << 'lib' << 'test'
44
+ test.pattern = 'test/**/test_*.rb'
45
+ test.verbose = true
46
+ test.warning = false
47
+ end
48
+
49
+ require 'rdoc/task'
50
+ desc 'Build RDoc documentation'
51
+ Rake::RDocTask.new do |rdoc|
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "#{name} #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
57
+
58
+ require 'rubocop/rake_task'
59
+ desc 'Run RuboCop on all directories'
60
+ RuboCop::RakeTask.new(:rubocop) do |task|
61
+ task.fail_on_error = true
62
+ task.requires << 'rubocop-rspec'
63
+ end
64
+
65
+ task :copyright do
66
+ sh "grep -q -r '2018-#{Date.today.strftime('%Y')}' \
67
+ --include '*.rb' \
68
+ --include '*.txt' \
69
+ --include 'Rakefile' \
70
+ ."
71
+ end
data/lib/zold/wts.rb ADDED
@@ -0,0 +1,199 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'typhoeus'
24
+ require 'cgi'
25
+ require 'zold/age'
26
+ require 'zold/amount'
27
+ require 'zold/id'
28
+ require 'zold/txn'
29
+
30
+ # WTS gateway.
31
+ #
32
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
+ # Copyright:: Copyright (c) 2018-2019 Yegor Bugayenko
34
+ # License:: MIT
35
+ module Zold
36
+ # WTS
37
+ class WTS
38
+ # Makes a new object of the class. The <tt>key</tt> you are supposed
39
+ # to obtain at this page: https://wts.zold.io/api. You will have to login
40
+ # and confirm your account first. Keep this key secret, to avoid
41
+ # information lost. However, even knowing the secret no payments can
42
+ # be sent without they keygap.
43
+ def initialize(key, log: STDOUT)
44
+ raise 'Key can\'t be nil' if key.nil?
45
+ @key = key
46
+ raise 'Log can\'t be nil' if log.nil?
47
+ @log = log
48
+ end
49
+
50
+ # Initiate PULL request. The server will pull your wallet form the network,
51
+ # and make it ready for future requests. Without this operation you won't
52
+ # be able to perform <tt>find()</tt> or <tt>balance()</tt> requests.
53
+ #
54
+ # The method returns the job ID, which you should wait for completion
55
+ # using the method <tt>wait()</tt>.
56
+ def pull
57
+ start = Time.now
58
+ job = job_of(
59
+ clean(
60
+ Typhoeus::Request.get(
61
+ 'https://wts.zold.io/pull',
62
+ headers: headers
63
+ )
64
+ )
65
+ )
66
+ debug("PULL job #{job} started in #{Zold::Age.new(start)}")
67
+ job
68
+ end
69
+
70
+ # Get wallet balance.
71
+ def balance
72
+ start = Time.now
73
+ http = clean(
74
+ Typhoeus::Request.get(
75
+ 'https://wts.zold.io/balance',
76
+ headers: headers
77
+ )
78
+ )
79
+ balance = Zold::Amount.new(zents: http.body.to_i)
80
+ debug("Wallet balance #{balance} retrieved in #{Zold::Age.new(start)}")
81
+ balance
82
+ end
83
+
84
+ # Get wallet ID.
85
+ def id
86
+ start = Time.now
87
+ http = clean(
88
+ Typhoeus::Request.get(
89
+ 'https://wts.zold.io/id',
90
+ headers: headers
91
+ )
92
+ )
93
+ id = Zold::Id.new(http.body.to_s)
94
+ debug("Wallet ID #{id} retrieved in #{Zold::Age.new(start)}")
95
+ id
96
+ end
97
+
98
+ # Initiate PAY request. The <tt>keygap</tt> is a string you get
99
+ # when you confirm the account. The <tt>bnf</tt> is the name of the
100
+ # GitHub account, the wallet ID or the invoice (up to you). The
101
+ # <tt>amount</tt> is the amount in ZLD, e.g. "19.99". The <tt>details</tt>
102
+ # is the text to add to the transaction.
103
+ #
104
+ # The method returns the job ID, which you should wait for completion
105
+ # using the method <tt>wait()</tt>.
106
+ def pay(keygap, bnf, amount, details)
107
+ start = Time.now
108
+ job = job_of(
109
+ clean(
110
+ Typhoeus::Request.post(
111
+ 'https://wts.zold.io/do-pay',
112
+ headers: headers,
113
+ body: { keygap: keygap, bnf: bnf, amount: amount, details: details }
114
+ )
115
+ )
116
+ )
117
+ debug("PAY job #{job} started in #{Zold::Age.new(start)}")
118
+ job
119
+ end
120
+
121
+ # Find transactions by the criteria. All criterias are regular expressions
122
+ # and their summary result is concatenated by OR. For example, this request
123
+ # will return all transactions that have "pizza" in details OR which
124
+ # are coming from the root wallet:
125
+ #
126
+ # find(details: /pizza/, bnf: '0000000000000000')
127
+ #
128
+ # The method returns an array of Zold::Txn objects.
129
+ def find(query)
130
+ start = Time.now
131
+ http = clean(
132
+ Typhoeus::Request.get(
133
+ 'https://wts.zold.io/find?' + query.map do |k, v|
134
+ "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
135
+ end.join('&'),
136
+ headers: headers
137
+ )
138
+ )
139
+ txns = http.body.split("\n").map { |t| Zold::Txn.parse(t) }
140
+ debug("#{txns.count} transactions found in #{Zold::Age.new(start)}")
141
+ txns
142
+ end
143
+
144
+ # Wait for the job to complete. If the job completes successfully, the
145
+ # method returns 'OK' in a few seconds (up to a few minutes). If the
146
+ # is some error, the exception will be raised.
147
+ def wait(job, time: 5 * 60)
148
+ start = Time.now
149
+ loop do
150
+ if Time.now - start > time
151
+ raise "Can't wait any longer for the job #{job} to complete"
152
+ end
153
+ http = Typhoeus::Request.get(
154
+ 'https://wts.zold.io/job?id=' + job,
155
+ headers: headers
156
+ )
157
+ raise "Job #{job} not found on the server" if http.code == 404
158
+ raise "Unpredictable response code #{http.code}" unless http.code == 200
159
+ next if http.body == 'Running'
160
+ raise http.body unless http.body == 'OK'
161
+ debug("Job #{job} completed, in #{Zold::Age.new(start)}")
162
+ return http.body
163
+ end
164
+ end
165
+
166
+ private
167
+
168
+ def headers
169
+ {
170
+ 'X-Zold-WTS': @key,
171
+ 'User-Agent': 'zold-ruby-sdk'
172
+ }
173
+ end
174
+
175
+ def job_of(http)
176
+ job = http.headers['X-Zold-Job']
177
+ raise 'Job ID is not returned, for some reason' if job.nil?
178
+ job
179
+ end
180
+
181
+ def clean(http)
182
+ error = http.headers['X-Zold-Error']
183
+ raise error unless error.nil?
184
+ unless http.code == 200 || http.code == 302
185
+ debug(http.body)
186
+ raise "Unexpected response code #{http.code}"
187
+ end
188
+ http
189
+ end
190
+
191
+ def debug(msg)
192
+ if @log.respond_to?(:debug)
193
+ @log.debug(msg)
194
+ elsif @log.respond_to?(:puts)
195
+ @log.puts(msg)
196
+ end
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require_relative '../../lib/zold/wts'
25
+
26
+ # WTS test.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2018-2019 Yegor Bugayenko
29
+ # License:: MIT
30
+ class TestWTS < Minitest::Test
31
+ KEY = '8HNxjYuEFp0....LYOWxsEaC3rQ=='
32
+
33
+ def test_pulls
34
+ skip if KEY.length < 50
35
+ wts = Zold::WTS.new(KEY)
36
+ job = wts.pull
37
+ wts.wait(job)
38
+ assert(!job.nil?)
39
+ end
40
+
41
+ def test_finds_transactions
42
+ skip if KEY.length < 50
43
+ wts = Zold::WTS.new(KEY)
44
+ job = wts.pull
45
+ wts.wait(job)
46
+ assert_equal(1, wts.find(details: /^for hosting$/).count)
47
+ end
48
+
49
+ def test_retrieves_wallet_id
50
+ skip if KEY.length < 50
51
+ wts = Zold::WTS.new(KEY)
52
+ assert(!wts.id.nil?)
53
+ end
54
+
55
+ def test_retrieves_balance
56
+ skip if KEY.length < 50
57
+ wts = Zold::WTS.new(KEY)
58
+ job = wts.pull
59
+ wts.wait(job)
60
+ assert(!wts.balance.zero?)
61
+ end
62
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'English'
24
+ Gem::Specification.new do |s|
25
+ s.specification_version = 2 if s.respond_to? :specification_version=
26
+ if s.respond_to? :required_rubygems_version=
27
+ s.required_rubygems_version = Gem::Requirement.new('>= 0')
28
+ end
29
+ s.rubygems_version = '2.2'
30
+ s.required_ruby_version = '>=2.5'
31
+ s.name = 'zold-ruby-sdk'
32
+ s.version = '0.1.0'
33
+ s.license = 'MIT'
34
+ s.summary = 'Zold score'
35
+ s.description = 'Ruby SDK for Zold online wallets management system (WTS)'
36
+ s.authors = ['Yegor Bugayenko']
37
+ s.email = 'yegor256@gmail.com'
38
+ s.homepage = 'http://github.com/zold-io/zold-ruby-sdk'
39
+ s.files = `git ls-files`.split($RS)
40
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
41
+ s.test_files = s.files.grep(%r{^(test|features)/})
42
+ s.rdoc_options = ['--charset=UTF-8']
43
+ s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
44
+ s.add_runtime_dependency 'typhoeus', '1.3.1'
45
+ s.add_runtime_dependency 'zold', '0.21.4'
46
+ s.add_development_dependency 'codecov', '0.1.14'
47
+ s.add_development_dependency 'minitest', '5.11.3'
48
+ s.add_development_dependency 'minitest-hooks', '1.5.0'
49
+ s.add_development_dependency 'rake-compiler', '1.0.4'
50
+ s.add_development_dependency 'rdoc', '4.3.0'
51
+ s.add_development_dependency 'rspec-rails', '3.8.1'
52
+ s.add_development_dependency 'rubocop', '0.62.0'
53
+ s.add_development_dependency 'rubocop-rspec', '1.31.0'
54
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zold-ruby-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yegor Bugayenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: zold
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.21.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.21.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: codecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.14
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.14
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 5.11.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 5.11.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-hooks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.5.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.5.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake-compiler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: rdoc
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 4.3.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 4.3.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 3.8.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 3.8.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 0.62.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 0.62.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.31.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.31.0
153
+ description: Ruby SDK for Zold online wallets management system (WTS)
154
+ email: yegor256@gmail.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files:
158
+ - README.md
159
+ - LICENSE.txt
160
+ files:
161
+ - ".0pdd.yml"
162
+ - ".gitattributes"
163
+ - ".gitignore"
164
+ - ".pdd"
165
+ - ".rubocop.yml"
166
+ - ".rultor.yml"
167
+ - ".simplecov"
168
+ - ".travis.yml"
169
+ - Gemfile
170
+ - LICENSE.txt
171
+ - README.md
172
+ - Rakefile
173
+ - lib/zold/wts.rb
174
+ - test/zold/test_wts.rb
175
+ - zold-ruby-sdk.gemspec
176
+ homepage: http://github.com/zold-io/zold-ruby-sdk
177
+ licenses:
178
+ - MIT
179
+ metadata: {}
180
+ post_install_message:
181
+ rdoc_options:
182
+ - "--charset=UTF-8"
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '2.5'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubygems_version: 3.0.1
197
+ signing_key:
198
+ specification_version: 2
199
+ summary: Zold score
200
+ test_files:
201
+ - test/zold/test_wts.rb