commonmeta-ruby 3.3 → 3.3.1

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: dde90e2b65c0eabd771cda34b2b5054fbe6bf80b573444fe0bcdde14c8392429
4
- data.tar.gz: 487ffa495c4ffae32184c0a6e11ef68a5f9e82ea18bfe4183d851cb4558d5f81
3
+ metadata.gz: 1a5ad35cfa39e4b1aadd232585375001d87f0a14c5f5638b6574c6982bb130a6
4
+ data.tar.gz: d7104f032539d68ee797c35e6f86d69fd8514691babec286ab3024fa49bac0cf
5
5
  SHA512:
6
- metadata.gz: 468b8f5ffc67f878cf97a39b0733e01ee9a56c1a2fd82874feba18fb9de6876b2d835ab11b2dd40021139dff988152d66fe25af0adde1e5884884017435dc711
7
- data.tar.gz: 1126af3e7ae9b0cbb25d9d2f4497e894ae33e2a34bb9cc975924233fcf48f8cd0527b67f7983aeee375d4e98f7d58005a913e5301a848aca2da92ce051b93732
6
+ metadata.gz: 86c9391a579504409de79cd3a2d449a7725a0b46014cde46e5ef5506b51e0595f5aa4a2404ac49fca20c8d8673b8b895234127e42ddf9314dd52214a7bdb9973
7
+ data.tar.gz: 26d1153f74db838c65c99b5229f2031c0ddb90b907fc3f7f51210bd177cf78e8417814437284378e38a86fb829bf36ccb1c6d5b3a7ac6d35678d870fac918e93
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- commonmeta-ruby (3.3)
4
+ commonmeta-ruby (3.3.1)
5
5
  activesupport (>= 4.2.5, < 8.0)
6
6
  addressable (~> 2.8.1, < 2.8.2)
7
7
  base32-url (>= 0.7.0, < 1)
@@ -59,6 +59,7 @@ module Commonmeta
59
59
  desc "", "encode"
60
60
 
61
61
  def encode(prefix)
62
+ return nil unless 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 { "string" => nil, "state" => "not_found" } unless response.status.success?
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 { "string" => nil, "state" => "not_found" } unless response.status.success?
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
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmeta
4
- VERSION = '3.3'
4
+ VERSION = '3.3.1'
5
5
  end
data/spec/cli_spec.rb CHANGED
@@ -317,15 +317,30 @@ describe Commonmeta::CLI do
317
317
  expect { subject.encode input }.to output(/https:\/\/doi.org\/10.53731/).to_stdout
318
318
  end
319
319
 
320
+ it "blog prefix missing" do
321
+ input = ""
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: '3.3'
4
+ version: 3.3.1
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