baza.rb 0.3.0 → 0.5.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/.github/workflows/copyrights.yml +1 -1
- data/.github/workflows/markdown-lint.yml +1 -1
- data/.github/workflows/typos.yml +19 -0
- data/.gitignore +3 -2
- data/.rubocop.yml +1 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +22 -23
- data/README.md +5 -5
- data/REUSE.toml +7 -7
- data/Rakefile +10 -6
- data/lib/baza-rb/fake.rb +72 -30
- data/lib/baza-rb/version.rb +2 -2
- data/lib/baza-rb.rb +200 -67
- data/test/test__helper.rb +20 -6
- data/test/test_baza-rb.rb +292 -21
- data/test/test_fake.rb +19 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4fb6929da01d8ec60b802d9bd8c3300456ff66144723496bbe60a11b1f67fad
|
4
|
+
data.tar.gz: 29db7120d95c442fcb529e9f1f1d8f3c7145baca1cf829cd011bdf6b6d6918bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0212eb14782da74ea7ecbfa855e3a075e4639577f512ea12f98549451a7000a820a0bbb918f909f0eacde8c62593bc62910b7829a759ee989a2844e5def8fb20
|
7
|
+
data.tar.gz: 883fb08a189555e8abdb1800c2ab2d08229833945b11809930412d5da82890b23856122c9e2fe6c44f369db007a0dee4ebb3b51991a7ba4eedca261ec135b934
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
2
|
+
# SPDX-License-Identifier: MIT
|
3
|
+
---
|
4
|
+
# yamllint disable rule:line-length
|
5
|
+
name: typos
|
6
|
+
'on':
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
pull_request:
|
11
|
+
branches:
|
12
|
+
- master
|
13
|
+
jobs:
|
14
|
+
typos:
|
15
|
+
timeout-minutes: 15
|
16
|
+
runs-on: ubuntu-24.04
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v4
|
19
|
+
- uses: crate-ci/typos@v1.32.0
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -10,7 +10,6 @@ gem 'base64', '>0', require: false
|
|
10
10
|
gem 'factbase', '>0', require: false
|
11
11
|
gem 'minitest', '~>5.25', require: false
|
12
12
|
gem 'minitest-reporters', '~>1.7', require: false
|
13
|
-
gem 'net-ping', '~>2.0', require: false
|
14
13
|
gem 'os', '>0', require: false
|
15
14
|
gem 'qbash', '>0', require: false
|
16
15
|
gem 'rake', '~>13.2', require: false
|
data/Gemfile.lock
CHANGED
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
tago (> 0)
|
36
36
|
ethon (0.16.0)
|
37
37
|
ffi (>= 1.15.0)
|
38
|
-
factbase (0.
|
38
|
+
factbase (0.10.2)
|
39
39
|
backtrace (~> 0.4)
|
40
40
|
decoor (~> 0.0)
|
41
41
|
json (~> 2.7)
|
@@ -45,7 +45,7 @@ GEM
|
|
45
45
|
others (~> 0.0)
|
46
46
|
tago (~> 0.0)
|
47
47
|
yaml (~> 0.3)
|
48
|
-
faraday (2.
|
48
|
+
faraday (2.13.1)
|
49
49
|
faraday-net_http (>= 2.0, < 3.5)
|
50
50
|
json
|
51
51
|
logger
|
@@ -55,19 +55,20 @@ GEM
|
|
55
55
|
multipart-post (~> 2.0)
|
56
56
|
faraday-net_http (3.4.0)
|
57
57
|
net-http (>= 0.5.0)
|
58
|
-
faraday-retry (2.3.
|
58
|
+
faraday-retry (2.3.1)
|
59
59
|
faraday (~> 2.0)
|
60
|
-
ffi (1.17.
|
61
|
-
ffi (1.17.
|
62
|
-
ffi (1.17.
|
63
|
-
ffi (1.17.
|
64
|
-
hashdiff (1.
|
60
|
+
ffi (1.17.2-arm64-darwin)
|
61
|
+
ffi (1.17.2-x64-mingw-ucrt)
|
62
|
+
ffi (1.17.2-x86_64-darwin)
|
63
|
+
ffi (1.17.2-x86_64-linux-gnu)
|
64
|
+
hashdiff (1.2.0)
|
65
65
|
iri (0.10.0)
|
66
|
-
json (2.
|
67
|
-
language_server-protocol (3.17.0.
|
66
|
+
json (2.12.2)
|
67
|
+
language_server-protocol (3.17.0.5)
|
68
68
|
lint_roller (1.1.0)
|
69
69
|
logger (1.7.0)
|
70
|
-
loog (0.6.
|
70
|
+
loog (0.6.1)
|
71
|
+
logger (~> 1.0)
|
71
72
|
minitest (5.25.5)
|
72
73
|
minitest-reporters (1.7.1)
|
73
74
|
ansi
|
@@ -77,24 +78,23 @@ GEM
|
|
77
78
|
multipart-post (2.4.1)
|
78
79
|
net-http (0.6.0)
|
79
80
|
uri
|
80
|
-
|
81
|
-
nokogiri (1.18.7-arm64-darwin)
|
81
|
+
nokogiri (1.18.8-arm64-darwin)
|
82
82
|
racc (~> 1.4)
|
83
|
-
nokogiri (1.18.
|
83
|
+
nokogiri (1.18.8-x64-mingw-ucrt)
|
84
84
|
racc (~> 1.4)
|
85
|
-
nokogiri (1.18.
|
85
|
+
nokogiri (1.18.8-x86_64-darwin)
|
86
86
|
racc (~> 1.4)
|
87
|
-
nokogiri (1.18.
|
87
|
+
nokogiri (1.18.8-x86_64-linux-gnu)
|
88
88
|
racc (~> 1.4)
|
89
89
|
os (1.1.4)
|
90
90
|
others (0.0.3)
|
91
|
-
parallel (1.
|
92
|
-
parser (3.3.
|
91
|
+
parallel (1.27.0)
|
92
|
+
parser (3.3.8.0)
|
93
93
|
ast (~> 2.4.1)
|
94
94
|
racc
|
95
95
|
prism (1.4.0)
|
96
|
-
public_suffix (6.0.
|
97
|
-
qbash (0.4.
|
96
|
+
public_suffix (6.0.2)
|
97
|
+
qbash (0.4.5)
|
98
98
|
backtrace (> 0)
|
99
99
|
elapsed (> 0)
|
100
100
|
loog (> 0)
|
@@ -107,7 +107,7 @@ GEM
|
|
107
107
|
regexp_parser (2.10.0)
|
108
108
|
retries (0.0.5)
|
109
109
|
rexml (3.4.1)
|
110
|
-
rubocop (1.75.
|
110
|
+
rubocop (1.75.7)
|
111
111
|
json (~> 2.3)
|
112
112
|
language_server-protocol (~> 3.17.0.2)
|
113
113
|
lint_roller (~> 1.1.0)
|
@@ -118,7 +118,7 @@ GEM
|
|
118
118
|
rubocop-ast (>= 1.44.0, < 2.0)
|
119
119
|
ruby-progressbar (~> 1.7)
|
120
120
|
unicode-display_width (>= 2.4.0, < 4.0)
|
121
|
-
rubocop-ast (1.44.
|
121
|
+
rubocop-ast (1.44.1)
|
122
122
|
parser (>= 3.3.7.2)
|
123
123
|
prism (~> 1.4)
|
124
124
|
rubocop-minitest (0.38.0)
|
@@ -173,7 +173,6 @@ DEPENDENCIES
|
|
173
173
|
factbase (> 0)
|
174
174
|
minitest (~> 5.25)
|
175
175
|
minitest-reporters (~> 1.7)
|
176
|
-
net-ping (~> 2.0)
|
177
176
|
os (> 0)
|
178
177
|
qbash (> 0)
|
179
178
|
rake (~> 13.2)
|
data/README.md
CHANGED
@@ -1,17 +1,17 @@
|
|
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)
|
13
13
|
|
14
|
-
It's
|
14
|
+
It's a client for [Zerocracy API](https://www.zerocracy.com), in Ruby.
|
15
15
|
|
16
16
|
## How to contribute
|
17
17
|
|
data/REUSE.toml
CHANGED
@@ -4,9 +4,16 @@
|
|
4
4
|
version = 1
|
5
5
|
[[annotations]]
|
6
6
|
path = [
|
7
|
+
".DS_Store",
|
8
|
+
".gitattributes",
|
9
|
+
".gitignore",
|
10
|
+
".pdd",
|
7
11
|
"**.json",
|
8
12
|
"**.md",
|
9
13
|
"**.txt",
|
14
|
+
"**/.DS_Store",
|
15
|
+
"**/.gitignore",
|
16
|
+
"**/.pdd",
|
10
17
|
"**/*.csv",
|
11
18
|
"**/*.jpg",
|
12
19
|
"**/*.json",
|
@@ -16,15 +23,8 @@ path = [
|
|
16
23
|
"**/*.svg",
|
17
24
|
"**/*.txt",
|
18
25
|
"**/*.vm",
|
19
|
-
"**/.DS_Store",
|
20
|
-
"**/.gitignore",
|
21
|
-
"**/.pdd",
|
22
26
|
"**/CNAME",
|
23
27
|
"**/Gemfile.lock",
|
24
|
-
".DS_Store",
|
25
|
-
".gitattributes",
|
26
|
-
".gitignore",
|
27
|
-
".pdd",
|
28
28
|
"Gemfile.lock",
|
29
29
|
"README.md",
|
30
30
|
"renovate.json",
|
data/Rakefile
CHANGED
@@ -24,19 +24,23 @@ task default: %i[clean test picks rubocop yard]
|
|
24
24
|
|
25
25
|
require 'rake/testtask'
|
26
26
|
desc 'Run all unit tests'
|
27
|
-
Rake::TestTask.new(:test) do |
|
27
|
+
Rake::TestTask.new(:test) do |t|
|
28
28
|
Rake::Cleaner.cleanup_files(['coverage'])
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
t.libs << 'lib' << 'test'
|
30
|
+
t.pattern = 'test/**/test_*.rb'
|
31
|
+
t.warning = true
|
32
|
+
t.verbose = false
|
33
|
+
t.options = ARGV.join(' ').match(/(?:^| )(-- .*)$/)
|
33
34
|
end
|
34
35
|
|
35
36
|
desc 'Run them via Ruby, one by one'
|
36
37
|
task :picks do
|
37
38
|
next if OS.windows?
|
38
39
|
(Dir['test/**/*.rb'] + Dir['lib/**/*.rb']).each do |f|
|
39
|
-
qbash(
|
40
|
+
qbash(
|
41
|
+
"bundle exec ruby #{Shellwords.escape(f)} -- --offline",
|
42
|
+
log: $stdout, env: { 'RACK_ENV' => 'picks' }
|
43
|
+
)
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
data/lib/baza-rb/fake.rb
CHANGED
@@ -7,21 +7,34 @@ require 'factbase'
|
|
7
7
|
require_relative '../baza-rb'
|
8
8
|
require_relative 'version'
|
9
9
|
|
10
|
-
# Fake
|
10
|
+
# Fake implementation of the Zerocracy API client for testing.
|
11
11
|
#
|
12
12
|
# This class implements the same public interface as BazaRb but doesn't
|
13
|
-
# make any network connections,
|
13
|
+
# make any network connections. Instead, it returns predefined fake values
|
14
|
+
# and validates inputs to help catch errors during testing.
|
15
|
+
#
|
16
|
+
# @example Using in tests
|
17
|
+
# baza = BazaRb::Fake.new
|
18
|
+
# assert_equal 'torvalds', baza.whoami
|
19
|
+
# assert_equal 42, baza.push('test-job', 'data', [])
|
14
20
|
#
|
15
21
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
16
22
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
17
23
|
# License:: MIT
|
18
24
|
class BazaRb::Fake
|
25
|
+
# Get GitHub login name of the logged in user.
|
26
|
+
#
|
27
|
+
# @return [String] Always returns 'torvalds' for testing
|
28
|
+
def whoami
|
29
|
+
'torvalds'
|
30
|
+
end
|
31
|
+
|
19
32
|
# Push factbase to the server.
|
20
33
|
#
|
21
|
-
# @param [String] name The name of the job on the server
|
22
|
-
# @param [
|
23
|
-
# @param [Array<String>] meta List of
|
24
|
-
# @return [Integer]
|
34
|
+
# @param [String] name The unique name of the job on the server
|
35
|
+
# @param [String] data The binary data to push to the server
|
36
|
+
# @param [Array<String>] meta List of metadata strings to attach to the job
|
37
|
+
# @return [Integer] Always returns 42 as the fake job ID
|
25
38
|
def push(name, data, meta)
|
26
39
|
assert_name(name)
|
27
40
|
raise 'The data must be non-empty' if data.empty?
|
@@ -32,16 +45,16 @@ class BazaRb::Fake
|
|
32
45
|
# Pull factbase from the server.
|
33
46
|
#
|
34
47
|
# @param [Integer] id The ID of the job on the server
|
35
|
-
# @return [
|
48
|
+
# @return [String] Returns an empty factbase export for testing
|
36
49
|
def pull(id)
|
37
50
|
assert_id(id)
|
38
51
|
Factbase.new.export
|
39
52
|
end
|
40
53
|
|
41
|
-
#
|
54
|
+
# Check if the job with this ID is finished already.
|
42
55
|
#
|
43
56
|
# @param [Integer] id The ID of the job on the server
|
44
|
-
# @return [Boolean]
|
57
|
+
# @return [Boolean] Always returns TRUE for testing
|
45
58
|
def finished?(id)
|
46
59
|
assert_id(id)
|
47
60
|
true
|
@@ -110,13 +123,15 @@ class BazaRb::Fake
|
|
110
123
|
true
|
111
124
|
end
|
112
125
|
|
113
|
-
# Place a single durable.
|
126
|
+
# Place a single durable file on the server.
|
114
127
|
#
|
115
128
|
# @param [String] jname The name of the job on the server
|
116
|
-
# @param [String] file The file
|
129
|
+
# @param [String] file The path to the file to upload
|
130
|
+
# @return [Integer] Always returns 42 as the fake durable ID
|
117
131
|
def durable_place(jname, file)
|
118
132
|
assert_name(jname)
|
119
133
|
assert_file(file)
|
134
|
+
42
|
120
135
|
end
|
121
136
|
|
122
137
|
# Save a single durable from local file to server.
|
@@ -155,24 +170,49 @@ class BazaRb::Fake
|
|
155
170
|
assert_owner(owner)
|
156
171
|
end
|
157
172
|
|
158
|
-
#
|
173
|
+
# Get current balance of the authenticated user.
|
174
|
+
#
|
175
|
+
# @return [Float] Always returns 3.14 zents for testing
|
176
|
+
def balance
|
177
|
+
3.14
|
178
|
+
end
|
179
|
+
|
180
|
+
# Transfer funds to another user.
|
159
181
|
#
|
160
|
-
# @param [String] recipient GitHub
|
161
|
-
# @param [Float] amount The amount in
|
162
|
-
# @param [String] summary The description
|
182
|
+
# @param [String] recipient GitHub username of the recipient
|
183
|
+
# @param [Float] amount The amount to transfer in ƶ (zents)
|
184
|
+
# @param [String] summary The description/reason for the payment
|
185
|
+
# @return [Integer] Always returns 42 as the fake receipt ID
|
163
186
|
def transfer(recipient, amount, summary, *)
|
164
|
-
raise "The
|
187
|
+
raise "The recipient #{recipient.inspect} is not valid" unless recipient.match?(/^[a-zA-Z0-9-]+$/)
|
165
188
|
raise "The amount #{amount} must be a Float" unless amount.is_a?(Float)
|
166
189
|
raise "The amount #{amount} must be positive" unless amount.positive?
|
167
190
|
raise "The summary #{summary.inspect} is empty" if summary.empty?
|
168
191
|
42
|
169
192
|
end
|
170
193
|
|
171
|
-
#
|
194
|
+
# Pay a fee associated with a job.
|
172
195
|
#
|
173
|
-
# @param [String]
|
174
|
-
# @param [
|
175
|
-
# @
|
196
|
+
# @param [String] tab The category/type of the fee
|
197
|
+
# @param [Float] amount The fee amount in ƶ (zents)
|
198
|
+
# @param [String] summary The description/reason for the fee
|
199
|
+
# @param [Integer] job The ID of the job this fee is for
|
200
|
+
# @return [Integer] Always returns 42 as the fake receipt ID
|
201
|
+
def fee(tab, amount, summary, job)
|
202
|
+
raise 'The "tab" is nil' if tab.nil?
|
203
|
+
raise "The amount #{amount} must be a Float" unless amount.is_a?(Float)
|
204
|
+
raise "The amount #{amount} must be positive" unless amount.positive?
|
205
|
+
raise 'The "job" is nil' if job.nil?
|
206
|
+
raise 'The "job" must be Integer' unless job.is_a?(Integer)
|
207
|
+
raise 'The "summary" is nil' if summary.nil?
|
208
|
+
42
|
209
|
+
end
|
210
|
+
|
211
|
+
# Pop the next available job from the server's queue.
|
212
|
+
#
|
213
|
+
# @param [String] owner Identifier of who is taking the job
|
214
|
+
# @param [String] zip The local file path where the job's ZIP will be saved
|
215
|
+
# @return [Boolean] Always returns TRUE and creates an empty file
|
176
216
|
def pop(owner, zip)
|
177
217
|
assert_owner(owner)
|
178
218
|
FileUtils.mkdir_p(File.dirname(zip))
|
@@ -180,22 +220,23 @@ class BazaRb::Fake
|
|
180
220
|
true
|
181
221
|
end
|
182
222
|
|
183
|
-
# Submit a ZIP archive to finish a job.
|
223
|
+
# Submit a ZIP archive to finish a previously popped job.
|
184
224
|
#
|
185
|
-
# @param [Integer] id The ID of the job
|
186
|
-
# @param [String] zip The path to the ZIP file
|
225
|
+
# @param [Integer] id The ID of the job to finish
|
226
|
+
# @param [String] zip The path to the ZIP file containing job results
|
187
227
|
def finish(id, zip)
|
188
228
|
assert_id(id)
|
189
229
|
assert_file(zip)
|
190
230
|
end
|
191
231
|
|
192
|
-
# Enter a valve.
|
232
|
+
# Enter a valve to cache or retrieve a computation result.
|
193
233
|
#
|
194
234
|
# @param [String] name Name of the job
|
195
|
-
# @param [String] badge Unique
|
196
|
-
# @param [String] why The reason
|
197
|
-
# @param [nil|Integer] job
|
198
|
-
# @
|
235
|
+
# @param [String] badge Unique identifier for this valve
|
236
|
+
# @param [String] why The reason/description for entering this valve
|
237
|
+
# @param [nil|Integer] job Optional job ID to associate with this valve
|
238
|
+
# @yield Block that computes the result
|
239
|
+
# @return [String] Always executes and returns the block's result
|
199
240
|
def enter(name, badge, why, job)
|
200
241
|
assert_name(name)
|
201
242
|
raise "The badge '#{badge}' is not valid" unless badge.match?(/^[a-zA-Z0-9_-]+$/)
|
@@ -204,8 +245,9 @@ class BazaRb::Fake
|
|
204
245
|
yield
|
205
246
|
end
|
206
247
|
|
207
|
-
# Get CSRF token from the server.
|
208
|
-
#
|
248
|
+
# Get CSRF token from the server for authenticated requests.
|
249
|
+
#
|
250
|
+
# @return [String] Always returns 'fake-csrf-token' for testing
|
209
251
|
def csrf
|
210
252
|
'fake-csrf-token'
|
211
253
|
end
|
data/lib/baza-rb/version.rb
CHANGED
@@ -10,8 +10,8 @@
|
|
10
10
|
# other packages (thus failing the build).
|
11
11
|
#
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
13
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
14
|
# License:: MIT
|
15
15
|
class BazaRb
|
16
|
-
VERSION = '0.
|
16
|
+
VERSION = '0.5.0'
|
17
17
|
end
|