commonmeta-ruby 3.3 → 3.3.2
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/Gemfile.lock +1 -1
- data/lib/commonmeta/cli.rb +3 -0
- data/lib/commonmeta/readers/json_feed_reader.rb +4 -4
- data/lib/commonmeta/utils.rb +3 -0
- data/lib/commonmeta/version.rb +1 -1
- data/spec/cli_spec.rb +16 -1
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/encode/by_blog_unknown_blog_id.yml +49 -0
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/encode/by_uuid_unknown_uuid.yml +49 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ece0c59f3993f3ca9e94df678c97093e785135f431592850dd5505d3f910f72
|
4
|
+
data.tar.gz: 948128ccbdb265d677531b68f7dd939e8e7723b5bb0b5bf8f751e606d4d58232
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca2bf7e8edca004aa35c3009cda657a544db8f420546e067d86a7c4bfe5e8819373e341efc0f4b7490a74867e8e4b38e96423f8257100cf720513d1d49e92655
|
7
|
+
data.tar.gz: 5c68deb59478f2b1c108bf42eaf24bd70b3218fecf4e76da731a6d4717997c75a037af55a36c6d0c4d4c1f270c0fed5efc24bd9dab5e7e25bc7c8855fc1b4c11
|
data/Gemfile.lock
CHANGED
data/lib/commonmeta/cli.rb
CHANGED
@@ -59,6 +59,7 @@ module Commonmeta
|
|
59
59
|
desc "", "encode"
|
60
60
|
|
61
61
|
def encode(prefix)
|
62
|
+
return nil unless validate_prefix(prefix).present?
|
62
63
|
puts encode_doi(prefix)
|
63
64
|
end
|
64
65
|
|
@@ -72,6 +73,7 @@ module Commonmeta
|
|
72
73
|
|
73
74
|
def encode_by_blog(blog_id)
|
74
75
|
prefix = get_doi_prefix_by_blog_id(blog_id)
|
76
|
+
return nil unless prefix.present?
|
75
77
|
puts encode_doi(prefix)
|
76
78
|
end
|
77
79
|
|
@@ -79,6 +81,7 @@ module Commonmeta
|
|
79
81
|
|
80
82
|
def encode_by_uuid(uuid)
|
81
83
|
prefix = get_doi_prefix_by_json_feed_item_uuid(uuid)
|
84
|
+
return nil unless prefix.present?
|
82
85
|
puts encode_doi(prefix)
|
83
86
|
end
|
84
87
|
|
@@ -132,10 +132,10 @@ module Commonmeta
|
|
132
132
|
|
133
133
|
url = json_feed_by_blog_url(blog_id)
|
134
134
|
response = HTTP.get(url)
|
135
|
-
return
|
135
|
+
return nil unless response.status.success?
|
136
136
|
|
137
137
|
post = JSON.parse(response.body.to_s)
|
138
|
-
post.dig('prefix')
|
138
|
+
post.to_h.dig('prefix')
|
139
139
|
end
|
140
140
|
|
141
141
|
def get_doi_prefix_by_json_feed_item_uuid(uuid)
|
@@ -143,10 +143,10 @@ module Commonmeta
|
|
143
143
|
|
144
144
|
url = json_feed_item_by_uuid_url(uuid)
|
145
145
|
response = HTTP.get(url)
|
146
|
-
return
|
146
|
+
return nil unless response.status.success?
|
147
147
|
|
148
148
|
post = JSON.parse(response.body.to_s)
|
149
|
-
post.dig('blog', 'prefix')
|
149
|
+
post.to_h.dig('blog', 'prefix')
|
150
150
|
end
|
151
151
|
end
|
152
152
|
end
|
data/lib/commonmeta/utils.rb
CHANGED
@@ -1384,11 +1384,14 @@ module Commonmeta
|
|
1384
1384
|
end
|
1385
1385
|
|
1386
1386
|
def encode_doi(prefix, options = {})
|
1387
|
+
return nil unless prefix.present?
|
1388
|
+
|
1387
1389
|
# DOI suffix is a generated from a random number, encoded in base32
|
1388
1390
|
# suffix has 8 digits plus two checksum digits. With base32 there are
|
1389
1391
|
# 32 possible digits, so 8 digits gives 32^8 possible combinations
|
1390
1392
|
if options[:uuid]
|
1391
1393
|
str = Base32::URL.encode_uuid(options[:uuid], split: 7, checksum: true)
|
1394
|
+
return nil unless str.present?
|
1392
1395
|
else
|
1393
1396
|
random_int = SecureRandom.random_number(32 ** 7..(32 ** 8) - 1)
|
1394
1397
|
suffix = Base32::URL.encode(random_int, checksum: true)
|
data/lib/commonmeta/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -312,20 +312,35 @@ describe Commonmeta::CLI do
|
|
312
312
|
end
|
313
313
|
|
314
314
|
describe "encode", vcr: true do
|
315
|
-
it "
|
315
|
+
it "valid doi prefix" do
|
316
316
|
input = "10.53731"
|
317
317
|
expect { subject.encode input }.to output(/https:\/\/doi.org\/10.53731/).to_stdout
|
318
318
|
end
|
319
319
|
|
320
|
+
it "invalid doi prefix" do
|
321
|
+
input = "11.1234"
|
322
|
+
expect { subject.encode input }.to output("").to_stdout
|
323
|
+
end
|
324
|
+
|
320
325
|
it "by_blog" do
|
321
326
|
input = "tyfqw20"
|
322
327
|
expect { subject.encode_by_blog input }.to output(/https:\/\/doi.org\/10.59350/).to_stdout
|
323
328
|
end
|
324
329
|
|
330
|
+
it "by_blog unknown blog_id" do
|
331
|
+
input = "tyfqw"
|
332
|
+
expect { subject.encode_by_blog input }.to output("").to_stdout
|
333
|
+
end
|
334
|
+
|
325
335
|
it "by_uuid" do
|
326
336
|
input = "2b22bbba-bcba-4072-94cc-3f88442fff88"
|
327
337
|
expect { subject.encode_by_uuid input }.to output(/https:\/\/doi.org\/10.54900/).to_stdout
|
328
338
|
end
|
339
|
+
|
340
|
+
it "by_uuid unknown uuid" do
|
341
|
+
input = "2b22bbba-bcba-4072-94cc-3f88442"
|
342
|
+
expect { subject.encode_by_uuid input }.to output("").to_stdout
|
343
|
+
end
|
329
344
|
end
|
330
345
|
|
331
346
|
describe "decode" do
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://rogue-scholar.org/api/blogs/tyfqw
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Connection:
|
11
|
+
- close
|
12
|
+
Host:
|
13
|
+
- rogue-scholar.org
|
14
|
+
User-Agent:
|
15
|
+
- http.rb/5.1.1
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Age:
|
22
|
+
- '0'
|
23
|
+
Cache-Control:
|
24
|
+
- public, max-age=0, must-revalidate
|
25
|
+
Content-Length:
|
26
|
+
- '4'
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Date:
|
30
|
+
- Sun, 18 Jun 2023 07:50:43 GMT
|
31
|
+
Etag:
|
32
|
+
- '"wm6yxsynvh4"'
|
33
|
+
Server:
|
34
|
+
- Vercel
|
35
|
+
Strict-Transport-Security:
|
36
|
+
- max-age=63072000
|
37
|
+
X-Matched-Path:
|
38
|
+
- "/api/blogs/[slug]"
|
39
|
+
X-Vercel-Cache:
|
40
|
+
- MISS
|
41
|
+
X-Vercel-Id:
|
42
|
+
- fra1::iad1::98kz8-1687074643292-5d2c6967ccd1
|
43
|
+
Connection:
|
44
|
+
- close
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: 'null'
|
48
|
+
recorded_at: Sun, 18 Jun 2023 07:50:44 GMT
|
49
|
+
recorded_with: VCR 6.1.0
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://rogue-scholar.org/api/posts/2b22bbba-bcba-4072-94cc-3f88442
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Connection:
|
11
|
+
- close
|
12
|
+
Host:
|
13
|
+
- rogue-scholar.org
|
14
|
+
User-Agent:
|
15
|
+
- http.rb/5.1.1
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Age:
|
22
|
+
- '0'
|
23
|
+
Cache-Control:
|
24
|
+
- public, max-age=0, must-revalidate
|
25
|
+
Content-Length:
|
26
|
+
- '4'
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Date:
|
30
|
+
- Sun, 18 Jun 2023 07:50:45 GMT
|
31
|
+
Etag:
|
32
|
+
- '"wm6yxsynvh4"'
|
33
|
+
Server:
|
34
|
+
- Vercel
|
35
|
+
Strict-Transport-Security:
|
36
|
+
- max-age=63072000
|
37
|
+
X-Matched-Path:
|
38
|
+
- "/api/posts/[slug]"
|
39
|
+
X-Vercel-Cache:
|
40
|
+
- MISS
|
41
|
+
X-Vercel-Id:
|
42
|
+
- fra1::iad1::vcxmh-1687074645282-662f2f07ee79
|
43
|
+
Connection:
|
44
|
+
- close
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: 'null'
|
48
|
+
recorded_at: Sun, 18 Jun 2023 07:50:45 GMT
|
49
|
+
recorded_with: VCR 6.1.0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonmeta-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Fenner
|
@@ -1074,7 +1074,9 @@ files:
|
|
1074
1074
|
- spec/fixtures/vcr_cassettes/Commonmeta_CLI/doi_prefix/doi_prefix_by_blog.yml
|
1075
1075
|
- spec/fixtures/vcr_cassettes/Commonmeta_CLI/doi_prefix/doi_prefix_by_uuid.yml
|
1076
1076
|
- spec/fixtures/vcr_cassettes/Commonmeta_CLI/encode/by_blog.yml
|
1077
|
+
- spec/fixtures/vcr_cassettes/Commonmeta_CLI/encode/by_blog_unknown_blog_id.yml
|
1077
1078
|
- spec/fixtures/vcr_cassettes/Commonmeta_CLI/encode/by_uuid.yml
|
1079
|
+
- spec/fixtures/vcr_cassettes/Commonmeta_CLI/encode/by_uuid_unknown_uuid.yml
|
1078
1080
|
- spec/fixtures/vcr_cassettes/Commonmeta_CLI/find_from_format_by_id/crossref.yml
|
1079
1081
|
- spec/fixtures/vcr_cassettes/Commonmeta_CLI/find_from_format_by_id/datacite.yml
|
1080
1082
|
- spec/fixtures/vcr_cassettes/Commonmeta_CLI/find_from_format_by_id/jalc.yml
|