commonmeta-ruby 3.2.9 → 3.2.11

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: e05b0fedfc5074f16bf6b04dd73150dcae6f75d3392dd3abe82bd52eafea1531
4
- data.tar.gz: 12700c970a507ae36013334f0e942413f0092d6bf4735aa27b6709a12bc7d84e
3
+ metadata.gz: a0921f5f53d0f34c3828253a5b5bca784a18a5efdd956083e145c80efd479b9d
4
+ data.tar.gz: 90f16c47ef51a0e0136be4d16e1558db2c916e89cd99c71ca9dccaa394d67a67
5
5
  SHA512:
6
- metadata.gz: 74c86b93355c0337df66c15d519f51f5336f2f883924f1c6b2edad8b6460d509d2e3443653d8545b201004e6407afffe79a505044f8cae88bbeede9f25e16171
7
- data.tar.gz: 903e7a8af1ec1025f8e7125ed96eea07f0994ed71f1473c5111947e5d7c8c1e42c5dcbe2b0562e261f60515c374c5f23e1d593cf448b9a87962cd4f3c831e2a3
6
+ metadata.gz: ce11b5a931ac2c383b30a600bb5551e0451ad8221656f7235833c3cb724aabfca17afbfbd67f27fe6c0df457da13e2a812d73f57d4061bec7452b2e6e7f794bd
7
+ data.tar.gz: 6e35050730a313ffbdd37f88809d52da14e3d371efd52a24960adbe906d017a8a621479982e881359d129a10ef59bedae02e6d5383f5119d6d8b9be2fba29829
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- commonmeta-ruby (3.2.9)
4
+ commonmeta-ruby (3.2.11)
5
5
  activesupport (>= 4.2.5, < 8.0)
6
6
  addressable (~> 2.8.1, < 2.8.2)
7
- base32-url (>= 0.5.0, < 1)
7
+ base32-url (>= 0.7.0, < 1)
8
8
  bibtex-ruby (~> 6.0)
9
9
  builder (~> 3.2, >= 3.2.4)
10
10
  citeproc-ruby (~> 2.0)
@@ -34,7 +34,8 @@ GEM
34
34
  addressable (2.8.1)
35
35
  public_suffix (>= 2.0.2, < 6.0)
36
36
  ast (2.4.2)
37
- base32-url (0.6.0)
37
+ base32-url (0.7.0)
38
+ uuidtools (~> 2.1, >= 2.1.5)
38
39
  bibtex-ruby (6.0.0)
39
40
  latex-decode (~> 0.0)
40
41
  builder (3.2.4)
@@ -241,6 +242,7 @@ GEM
241
242
  unf_ext (0.0.8.2)
242
243
  unicode-display_width (2.4.2)
243
244
  unicode-types (1.8.0)
245
+ uuidtools (2.2.0)
244
246
  vcr (6.1.0)
245
247
  webmock (3.18.1)
246
248
  addressable (>= 2.8.0)
data/commonmeta.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  # Declare dependencies here, rather than in the Gemfile
21
21
  s.add_dependency 'activesupport', '>= 4.2.5', '< 8.0'
22
22
  s.add_dependency 'addressable', '~> 2.8.1', '< 2.8.2'
23
- s.add_dependency 'base32-url', '>= 0.5.0', '< 1'
23
+ s.add_dependency 'base32-url', '>= 0.7.0', '< 1'
24
24
  s.add_dependency 'bibtex-ruby', '~> 6.0'
25
25
  s.add_dependency 'builder', '~> 3.2', '>= 3.2.4'
26
26
  s.add_dependency 'citeproc-ruby', '~> 2.0'
@@ -86,6 +86,12 @@ module Commonmeta
86
86
  puts get_json_feed_unregistered
87
87
  end
88
88
 
89
+ desc "", "json_feed"
90
+
91
+ def json_feed_by_blog(id)
92
+ puts get_json_feed_by_blog(id)
93
+ end
94
+
89
95
  default_task :convert
90
96
  end
91
97
  end
@@ -264,8 +264,8 @@ module Commonmeta
264
264
  "item_number_type" => alternate_identifier["alternateIdentifierType"] ? alternate_identifier["alternateIdentifierType"].downcase : nil,
265
265
  }.compact
266
266
 
267
- # remove dashes from UUIDs, as item_number can only be 32 characters long
268
- alternate_identifier["alternateIdentifier"].gsub!("-", "") if alternate_identifier["alternateIdentifierType"] == "UUID"
267
+ # convert UUIDs into base32 encoded strings, as item_number can only be 32 characters long (UUIDv4 is 36 characters long)
268
+ alternate_identifier["alternateIdentifier"] = Base32::URL.encode_uuid(alternate_identifier["alternateIdentifier"], split: 7, checksum: true) if alternate_identifier["alternateIdentifierType"] == "UUID"
269
269
 
270
270
  xml.item_number(alternate_identifier["alternateIdentifier"], attributes)
271
271
  end
@@ -109,6 +109,17 @@ module Commonmeta
109
109
  posts = JSON.parse(response.body.to_s)
110
110
  posts.map { |post| post["uuid"] }.first
111
111
  end
112
+
113
+ def get_json_feed_by_blog(blog_id)
114
+ # get all JSON Feed items from a particular blog
115
+
116
+ url = json_feed_by_blog_url(blog_id)
117
+ response = HTTP.get(url)
118
+ return { "string" => nil, "state" => "not_found" } unless response.status.success?
119
+
120
+ blog = JSON.parse(response.body.to_s)
121
+ blog["items"].map { |item| item["uuid"] }.join('\n')
122
+ end
112
123
  end
113
124
  end
114
125
  end
@@ -1367,19 +1367,27 @@ module Commonmeta
1367
1367
  end
1368
1368
  end
1369
1369
 
1370
- def encode_doi(prefix)
1370
+ def encode_doi(prefix, options = {})
1371
1371
  # DOI suffix is a generated from a random number, encoded in base32
1372
1372
  # suffix has 8 digits plus two checksum digits. With base32 there are
1373
1373
  # 32 possible digits, so 8 digits gives 32^8 possible combinations
1374
- random_int = SecureRandom.random_number(32 ** 7..(32 ** 8) - 1)
1375
- suffix = Base32::URL.encode(random_int, checksum: true)
1376
- str = "#{suffix[0, 5]}-#{suffix[5, 10]}"
1374
+ if options[:uuid]
1375
+ str = Base32::URL.encode_uuid(options[:uuid], split: 7, checksum: true)
1376
+ else
1377
+ random_int = SecureRandom.random_number(32 ** 7..(32 ** 8) - 1)
1378
+ suffix = Base32::URL.encode(random_int, checksum: true)
1379
+ str = "#{suffix[0, 5]}-#{suffix[5, 10]}"
1380
+ end
1377
1381
  "https://doi.org/#{prefix}/#{str}"
1378
1382
  end
1379
1383
 
1380
- def decode_doi(doi)
1384
+ def decode_doi(doi, options = {})
1381
1385
  suffix = doi.split("/", 5).last
1382
- Base32::URL.decode(suffix)
1386
+ if options[:uuid]
1387
+ Base32::URL.decode_uuid(suffix)
1388
+ else
1389
+ Base32::URL.decode(suffix)
1390
+ end
1383
1391
  end
1384
1392
 
1385
1393
  def encode_container_id
@@ -1396,5 +1404,9 @@ module Commonmeta
1396
1404
  def json_feed_unregistered_url
1397
1405
  "https://rogue-scholar.org/api/posts/unregistered"
1398
1406
  end
1407
+
1408
+ def json_feed_by_blog_url(blog_id)
1409
+ "https://rogue-scholar.org/api/blogs/#{blog_id}"
1410
+ end
1399
1411
  end
1400
1412
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmeta
4
- VERSION = '3.2.9'
4
+ VERSION = '3.2.11'
5
5
  end
data/spec/cli_spec.rb CHANGED
@@ -341,9 +341,10 @@ describe Commonmeta::CLI do
341
341
  end
342
342
  end
343
343
 
344
- # describe "json_feed_unregistered", vcr: true do
345
- # it "blog post uuid" do
346
- # expect { subject.json_feed_unregistered }.to output(/e4872b3e-cd15-407d-8406-33642c1a98b0\n/).to_stdout
347
- # end
348
- # end
344
+ describe "json_feed", vcr: true do
345
+ it "json_feed_by_blog" do
346
+ input = "tyfqw20"
347
+ expect { subject.json_feed_by_blog input }.to output(/3e1278f6-e7c0-43e1-bb54-6829e1344c0d/).to_stdout
348
+ end
349
+ end
349
350
  end
@@ -207,5 +207,11 @@ describe Commonmeta::Metadata, vcr: true do
207
207
  response = subject.get_json_feed_unregistered
208
208
  expect(response).to eq("ca2a7df4-f3b9-487c-82e9-27f54de75ea8")
209
209
  end
210
+
211
+ it 'by blog_id' do
212
+ response = subject.get_json_feed_by_blog('tyfqw20').split('\n')
213
+ expect(response.length).to eq(25)
214
+ expect(response.first).to eq("3e1278f6-e7c0-43e1-bb54-6829e1344c0d")
215
+ end
210
216
  end
211
217
  end
data/spec/utils_spec.rb CHANGED
@@ -650,6 +650,14 @@ describe Commonmeta::Metadata, vcr: true do
650
650
  expect(response.length).to eq(36)
651
651
  end
652
652
 
653
+ it "encode doi from uuid" do
654
+ prefix = "10.53731"
655
+ uuid = "c3095752-2af0-40a4-a229-3ceb7424bce2"
656
+ response = subject.encode_doi(prefix, uuid: uuid)
657
+ expect(response).to match(%r{#{prefix}/[a-z0-9]+})
658
+ expect(response.length).to eq(56)
659
+ end
660
+
653
661
  it "decode doi" do
654
662
  doi = "https://doi.org/10.53731/revzwnv-rpd913d-8drwz"
655
663
  response = subject.decode_doi(doi)
@@ -661,6 +669,12 @@ describe Commonmeta::Metadata, vcr: true do
661
669
  response = subject.decode_doi(doi)
662
670
  expect(response).to eq(30_198_793_950_250_854_133_601_922_433)
663
671
  end
672
+
673
+ it "decode doi to uuid" do
674
+ doi = "https://doi.org/10.53731/6315bn4-aqg82ja-4a9wxdt-29f7279"
675
+ response = subject.decode_doi(doi, uuid: true)
676
+ expect(response).to eq('255d48ab-c102-9288-a4f3-add092f388e9')
677
+ end
664
678
  end
665
679
 
666
680
  context "random id" do
@@ -191,6 +191,7 @@ describe Commonmeta::Metadata, vcr: true do
191
191
  "person_name")).first).to eq("ORCID" => "https://orcid.org/0000-0001-9165-2757", "contributor_role" => "author", "given_name" => "Esha", "sequence" => "first", "surname" => "Datta")
192
192
  expect(crossref_xml.dig("titles",
193
193
  "title")).to eq("Attempts at automating journal subject classification")
194
+ expect(crossref_xml.dig('item_number')).to eq("__content__"=>"2x2kzts-edc9rgb-vg6s4j6-z9t0d56", "item_number_type"=>"uuid")
194
195
  end
195
196
 
196
197
  it "json_feed_item with references" do
@@ -218,7 +219,7 @@ describe Commonmeta::Metadata, vcr: true do
218
219
  "title")).to eq("The Research Software Alliance (ReSA)")
219
220
  expect(crossref_xml.dig("citation_list", "citation").length).to eq(11)
220
221
  expect(crossref_xml.dig("citation_list", "citation").last).to eq("doi"=>"10.5281/zenodo.3699950", "key"=>"ref11")
221
- expect(crossref_xml.dig('item_number')).to eq("__content__"=>"954f81380ecd409087c5cef1297f1470", "item_number_type"=>"uuid")
222
+ expect(crossref_xml.dig('item_number')).to eq("__content__"=>"4n9y0kg-3pd8288-fheey4m-qy53g93", "item_number_type"=>"uuid")
222
223
  end
223
224
 
224
225
  it "json_feed_item from rogue scholar with doi" do
@@ -242,6 +243,7 @@ describe Commonmeta::Metadata, vcr: true do
242
243
  "person_name")).first).to eq("ORCID"=>"https://orcid.org/0000-0003-3334-2771", "contributor_role"=>"author", "given_name"=>"Heinz", "sequence"=>"first", "surname"=>"Pampel")
243
244
  expect(crossref_xml.dig("titles",
244
245
  "title")).to eq("EU-Mitgliedstaaten betonen die Rolle von wissenschaftsgeleiteten Open-Access-Modellen jenseits von APCs")
246
+ expect(crossref_xml.dig('item_number')).to eq("__content__"=>"way2ng-4s48j9v-hbw4rjf-aqh9f33", "item_number_type"=>"uuid")
245
247
  end
246
248
  end
247
249
  end
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.2.9
4
+ version: 3.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
@@ -56,7 +56,7 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.5.0
59
+ version: 0.7.0
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '1'
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 0.5.0
69
+ version: 0.7.0
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '1'