baza.rb 0.3.0 → 0.4.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/README.md +4 -4
- data/lib/baza-rb/fake.rb +32 -1
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +85 -1
- data/test/test_baza-rb.rb +20 -0
- data/test/test_fake.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56c9306fec1c51c662d122a94bb3a04cb1bc1fca68e518fa43aa600dd93aac4e
|
4
|
+
data.tar.gz: c7ecb9b7213285cbea8302070bbbe0d43800e1c0f2a81cdf2747a50013b390a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97b304210bef6e1c94db070044dbcc248b2f42d3982a5561eec155bd0c7f0040a7258c73cfb62b3ac6a2cf402ef6de9ef644cd41fe6311a0d10241ab2e68f8e9
|
7
|
+
data.tar.gz: 0a28fccff243c7539117f37633607451c7efa94f13b93e2f2848f8e3e662ffa337a7fab4569ebcad9a6d96ccb4eca2cf5f0aed72112148439e0673759d985b6d
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Zerocracy API Ruby Client
|
2
2
|
|
3
|
-
[](https://www.rultor.com/p/zerocracy/baza.rb)
|
4
4
|
|
5
5
|
[](https://github.com/zerocracy/baza.rb/actions/workflows/rake.yml)
|
6
|
-
[](
|
6
|
+
[](https://www.0pdd.com/p?name=zerocracy/baza.rb)
|
7
|
+
[](https://badge.fury.io/rb/baza.rb)
|
8
8
|
[](https://codecov.io/github/zerocracy/baza.rb?branch=master)
|
9
|
-
[](https://rubydoc.info/github/zerocracy/baza.rb/master/frames)
|
10
10
|
[](https://hitsofcode.com/view/github/zerocracy/baza.rb)
|
11
11
|
[](https://github.com/zerocracy/baza.rb/blob/master/LICENSE.txt)
|
12
12
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fzerocracy%2Fbaza.rb?ref=badge_shield&issueType=license)
|
data/lib/baza-rb/fake.rb
CHANGED
@@ -16,6 +16,13 @@ require_relative 'version'
|
|
16
16
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
17
17
|
# License:: MIT
|
18
18
|
class BazaRb::Fake
|
19
|
+
# Get GitHub login name of the logged in user.
|
20
|
+
#
|
21
|
+
# @return [String] GitHub nickname
|
22
|
+
def whoami
|
23
|
+
'torvalds'
|
24
|
+
end
|
25
|
+
|
19
26
|
# Push factbase to the server.
|
20
27
|
#
|
21
28
|
# @param [String] name The name of the job on the server
|
@@ -155,19 +162,43 @@ class BazaRb::Fake
|
|
155
162
|
assert_owner(owner)
|
156
163
|
end
|
157
164
|
|
165
|
+
# Get current balance, in Ƶ.
|
166
|
+
#
|
167
|
+
# @return [Float] The balance, as float
|
168
|
+
def balance
|
169
|
+
3.14
|
170
|
+
end
|
171
|
+
|
158
172
|
# Transfer some funds to another user.
|
159
173
|
#
|
160
174
|
# @param [String] recipient GitHub name (e.g. "yegor256") of the recipient
|
161
175
|
# @param [Float] amount The amount in Z/USDT (not zents!)
|
162
176
|
# @param [String] summary The description of the payment
|
163
177
|
def transfer(recipient, amount, summary, *)
|
164
|
-
raise "The
|
178
|
+
raise "The recipient #{recipient.inspect} is not valid" unless recipient.match?(/^[a-zA-Z0-9-]+$/)
|
165
179
|
raise "The amount #{amount} must be a Float" unless amount.is_a?(Float)
|
166
180
|
raise "The amount #{amount} must be positive" unless amount.positive?
|
167
181
|
raise "The summary #{summary.inspect} is empty" if summary.empty?
|
168
182
|
42
|
169
183
|
end
|
170
184
|
|
185
|
+
# Pay fee, while working with a job.
|
186
|
+
#
|
187
|
+
# @param [String] tab The tab of the fee (use "unknown" if not sure)
|
188
|
+
# @param [Float] amount The amount in Z/USDT (not zents!)
|
189
|
+
# @param [String] summary The description of the payment
|
190
|
+
# @param [Integer] job The ID of the job
|
191
|
+
# @return [Integer] Receipt ID
|
192
|
+
def fee(tab, amount, summary, job)
|
193
|
+
raise 'The "tab" is nil' if tab.nil?
|
194
|
+
raise "The amount #{amount} must be a Float" unless amount.is_a?(Float)
|
195
|
+
raise "The amount #{amount} must be positive" unless amount.positive?
|
196
|
+
raise 'The "job" is nil' if job.nil?
|
197
|
+
raise 'The "job" must be Integer' unless job.is_a?(Integer)
|
198
|
+
raise 'The "summary" is nil' if summary.nil?
|
199
|
+
42
|
200
|
+
end
|
201
|
+
|
171
202
|
# Pop job from the server.
|
172
203
|
#
|
173
204
|
# @param [String] owner Who is acting (could be any text)
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
@@ -56,6 +56,48 @@ class BazaRb
|
|
56
56
|
@compress = compress
|
57
57
|
end
|
58
58
|
|
59
|
+
# Get GitHub login name of the logged in user.
|
60
|
+
#
|
61
|
+
# @return [String] GitHub nickname
|
62
|
+
def whoami
|
63
|
+
nick = nil
|
64
|
+
elapsed(@loog) do
|
65
|
+
ret =
|
66
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
67
|
+
checked(
|
68
|
+
Typhoeus::Request.get(
|
69
|
+
home.append('whoami').to_s,
|
70
|
+
headers:
|
71
|
+
)
|
72
|
+
)
|
73
|
+
end
|
74
|
+
nick = ret.body
|
75
|
+
throw :"I know that I am @#{nick}, at #{@host}"
|
76
|
+
end
|
77
|
+
nick
|
78
|
+
end
|
79
|
+
|
80
|
+
# Get current balance, in Ƶ.
|
81
|
+
#
|
82
|
+
# @return [Float] The balance, as float
|
83
|
+
def balance
|
84
|
+
z = nil
|
85
|
+
elapsed(@loog) do
|
86
|
+
ret =
|
87
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
88
|
+
checked(
|
89
|
+
Typhoeus::Request.get(
|
90
|
+
home.append('account').append('balance').to_s,
|
91
|
+
headers:
|
92
|
+
)
|
93
|
+
)
|
94
|
+
end
|
95
|
+
z = ret.body.to_f
|
96
|
+
throw :"The balance is Ƶ#{z}, at #{@host}"
|
97
|
+
end
|
98
|
+
z
|
99
|
+
end
|
100
|
+
|
59
101
|
# Push factbase to the server.
|
60
102
|
#
|
61
103
|
# @param [String] name The name of the job on the server
|
@@ -477,7 +519,7 @@ class BazaRb
|
|
477
519
|
body = {
|
478
520
|
'_csrf' => csrf,
|
479
521
|
'human' => recipient,
|
480
|
-
'amount' =>
|
522
|
+
'amount' => format('%0.6f', amount),
|
481
523
|
'summary' => summary
|
482
524
|
}
|
483
525
|
body['job'] = job unless job.nil?
|
@@ -501,6 +543,48 @@ class BazaRb
|
|
501
543
|
id
|
502
544
|
end
|
503
545
|
|
546
|
+
# Pay fee, while working with a job.
|
547
|
+
#
|
548
|
+
# @param [String] tab The tab of the fee (use "unknown" if not sure)
|
549
|
+
# @param [Float] amount The amount in Z/USDT (not zents!)
|
550
|
+
# @param [String] summary The description of the payment
|
551
|
+
# @param [Integer] job The ID of the job
|
552
|
+
# @return [Integer] Receipt ID
|
553
|
+
def fee(tab, amount, summary, job)
|
554
|
+
raise 'The "tab" is nil' if tab.nil?
|
555
|
+
raise 'The "amount" is nil' if amount.nil?
|
556
|
+
raise 'The "amount" must be Float' unless amount.is_a?(Float)
|
557
|
+
raise 'The "job" is nil' if job.nil?
|
558
|
+
raise 'The "job" must be Integer' unless job.is_a?(Integer)
|
559
|
+
raise 'The "summary" is nil' if summary.nil?
|
560
|
+
id = nil
|
561
|
+
body = {
|
562
|
+
'_csrf' => csrf,
|
563
|
+
'tab' => tab,
|
564
|
+
'amount' => format('%0.6f', amount),
|
565
|
+
'summary' => summary,
|
566
|
+
'job' => job.to_s
|
567
|
+
}
|
568
|
+
elapsed(@loog) do
|
569
|
+
ret =
|
570
|
+
with_retries(max_tries: @retries, rescue: TimedOut) do
|
571
|
+
checked(
|
572
|
+
Typhoeus::Request.post(
|
573
|
+
home.append('account').append('fee').to_s,
|
574
|
+
body:,
|
575
|
+
headers:,
|
576
|
+
connecttimeout: @timeout,
|
577
|
+
timeout: @timeout
|
578
|
+
),
|
579
|
+
302
|
580
|
+
)
|
581
|
+
end
|
582
|
+
id = ret.headers['X-Zerocracy-ReceiptId'].to_i
|
583
|
+
throw :"Fee ##{format('%.02f', amount)} paid at #{@host}"
|
584
|
+
end
|
585
|
+
id
|
586
|
+
end
|
587
|
+
|
504
588
|
# Pop job from the server.
|
505
589
|
#
|
506
590
|
# @param [String] owner Who is acting (could be any text)
|
data/test/test_baza-rb.rb
CHANGED
@@ -53,6 +53,26 @@ class TestBazaRb < Minitest::Test
|
|
53
53
|
refute_nil(LIVE.unlock(n, owner))
|
54
54
|
end
|
55
55
|
|
56
|
+
def test_live_whoami
|
57
|
+
WebMock.enable_net_connect!
|
58
|
+
skip('We are offline') unless we_are_online
|
59
|
+
refute_nil(LIVE.whoami)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_live_balance
|
63
|
+
WebMock.enable_net_connect!
|
64
|
+
skip('We are offline') unless we_are_online
|
65
|
+
z = LIVE.balance
|
66
|
+
refute_nil(z)
|
67
|
+
assert(z.to_f)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_live_fee_payment
|
71
|
+
WebMock.enable_net_connect!
|
72
|
+
skip('We are offline') unless we_are_online
|
73
|
+
refute_nil(LIVE.fee('unknown', 0.007, 'just for fun', 777))
|
74
|
+
end
|
75
|
+
|
56
76
|
def test_live_push_no_compression
|
57
77
|
WebMock.enable_net_connect!
|
58
78
|
skip('We are offline') unless we_are_online
|
data/test/test_fake.rb
CHANGED
@@ -11,6 +11,18 @@ require_relative '../lib/baza-rb/fake'
|
|
11
11
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
12
12
|
# License:: MIT
|
13
13
|
class TestFake < Minitest::Test
|
14
|
+
def test_whoami
|
15
|
+
baza = BazaRb::Fake.new
|
16
|
+
nick = baza.whoami
|
17
|
+
refute_nil(nick)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_balance
|
21
|
+
baza = BazaRb::Fake.new
|
22
|
+
z = baza.balance
|
23
|
+
refute_nil(z)
|
24
|
+
end
|
25
|
+
|
14
26
|
def test_pull
|
15
27
|
baza = BazaRb::Fake.new
|
16
28
|
bin = baza.pull(42)
|
@@ -82,6 +94,12 @@ class TestFake < Minitest::Test
|
|
82
94
|
assert_equal(42, receipt_id)
|
83
95
|
end
|
84
96
|
|
97
|
+
def test_pays_fee
|
98
|
+
baza = BazaRb::Fake.new
|
99
|
+
receipt_id = baza.fee('unknown', 43.0, 'for fun', 44)
|
100
|
+
assert_equal(42, receipt_id)
|
101
|
+
end
|
102
|
+
|
85
103
|
def test_pop
|
86
104
|
baza = BazaRb::Fake.new
|
87
105
|
Dir.mktmpdir do |tmp|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baza.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: backtrace
|