commonmeta-ruby 3.3.14 → 3.3.16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ee69e57863623e144f88a33b390d82e7091e164251e18126dc91506aa1dbb46
4
- data.tar.gz: 18a2dbf7ca68ab099441811fae3535164f9ecd32257a75b06327c2978adb2d86
3
+ metadata.gz: 1959fba18a127e97c92b94c7e0e78d42c4538e3bccf6b9e6019035931e19d2f4
4
+ data.tar.gz: 190a4ddc0e6789c56f6f9a5a97355c8684e103abf121d2dfefdd5c1d816bd2d2
5
5
  SHA512:
6
- metadata.gz: ece7f1c165c734f8654329f809b2163013d6e837fc29a4b50e17f449e0754b6fa0ef3a6afd22c1601c0cd27c7659f068d1d59a9f166a7bc44b67e6d227a75366
7
- data.tar.gz: 3eada0a28b0ccc7ea570b7ca45ee07c2a614725b0d55ca8fd6964c67579d27e9c538a51bc1e76e30c6faccff871e93959063702062df9f8a1cc25d9ae4468ba4
6
+ metadata.gz: d5994587ca3efda69c8f1e4efca204a89db31d9e4b48a4b683e0312e32209c720f3a24506026152dd69d6ee49895919d72ee4d3aea6557da2b972a1fdb94092a
7
+ data.tar.gz: 56b4e03114cff5155c502f08f953afb3f2ba13c82bdefecfed73b752131b6b718cd21460eaa8d6506b7b50ded9655330e7c040c833a81c5feeb105c489306ab9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- commonmeta-ruby (3.3.14)
4
+ commonmeta-ruby (3.3.16)
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)
@@ -127,7 +127,7 @@ GEM
127
127
  minitest (5.18.1)
128
128
  multi_json (1.15.0)
129
129
  namae (1.1.1)
130
- nokogiri (1.15.2-arm64-darwin)
130
+ nokogiri (1.15.3-arm64-darwin)
131
131
  racc (~> 1.4)
132
132
  oj (3.15.0)
133
133
  optimist (3.0.1)
data/bin/commonmeta CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require File.expand_path("../../lib/commonmeta", __FILE__)
4
4
 
5
- if (ARGV & %w(--version -v help --help encode decode encode_id decode_id encode_by_blog encode_by_uuid json_feed_not_indexed json_feed_unregistered json_feed_by_blog update_ghost_post)).empty?
5
+ if (ARGV & %w(--version -v help --help encode decode encode_id decode_id encode_by_blog encode_by_id json_feed_not_indexed json_feed_unregistered json_feed_by_blog update_ghost_post)).empty?
6
6
  Commonmeta::CLI.start(ARGV.dup.unshift("convert"))
7
7
  else
8
8
  Commonmeta::CLI.start
@@ -77,10 +77,10 @@ module Commonmeta
77
77
  puts encode_doi(prefix)
78
78
  end
79
79
 
80
- desc "", "encode_by_uuid"
80
+ desc "", "encode_by_id"
81
81
 
82
- def encode_by_uuid(uuid)
83
- prefix = get_doi_prefix_by_json_feed_item_uuid(uuid)
82
+ def encode_by_id(id)
83
+ prefix = get_doi_prefix_by_json_feed_item_id(id)
84
84
  return nil unless prefix.present?
85
85
  puts encode_doi(prefix)
86
86
  end
@@ -117,8 +117,8 @@ module Commonmeta
117
117
 
118
118
  desc "", "update_ghost_post"
119
119
 
120
- def update_ghost_post(uuid)
121
- puts update_ghost_post_via_api(uuid)
120
+ def update_ghost_post(id)
121
+ puts update_ghost_post_via_api(id)
122
122
  end
123
123
 
124
124
  default_task :convert
@@ -111,7 +111,7 @@ module Commonmeta
111
111
  return { "string" => nil, "state" => "not_found" } unless response.status.success?
112
112
 
113
113
  posts = JSON.parse(response.body.to_s)
114
- posts.map { |post| post["uuid"] }.first
114
+ posts.map { |post| post["id"] }.first
115
115
  end
116
116
 
117
117
  def get_json_feed_not_indexed
@@ -122,7 +122,8 @@ module Commonmeta
122
122
  return { "string" => nil, "state" => "not_found" } unless response.status.success?
123
123
 
124
124
  posts = JSON.parse(response.body.to_s)
125
- posts.map { |post| post["uuid"] }.first
125
+ puts posts.inspect
126
+ posts.map { |post| post["id"] }.first
126
127
  end
127
128
 
128
129
  def get_json_feed_by_blog(blog_id)
@@ -133,7 +134,7 @@ module Commonmeta
133
134
  return { "string" => nil, "state" => "not_found" } unless response.status.success?
134
135
 
135
136
  blog = JSON.parse(response.body.to_s)
136
- blog["items"].map { |item| item["uuid"] }.first
137
+ blog["items"].map { |item| item["id"] }.first
137
138
  end
138
139
 
139
140
  def get_doi_prefix_by_blog_id(blog_id)
@@ -147,10 +148,10 @@ module Commonmeta
147
148
  post.to_h.dig("prefix")
148
149
  end
149
150
 
150
- def get_doi_prefix_by_json_feed_item_uuid(uuid)
151
+ def get_doi_prefix_by_json_feed_item_id(id)
151
152
  # for generating a random DOI. Prefix is based on the blog id.
152
153
 
153
- url = json_feed_item_by_uuid_url(uuid)
154
+ url = json_feed_item_by_id_url(id)
154
155
  response = HTTP.get(url)
155
156
  return nil unless response.status.success?
156
157
 
@@ -1400,10 +1400,10 @@ module Commonmeta
1400
1400
  "https://doi.org/#{prefix}/#{str}"
1401
1401
  end
1402
1402
 
1403
- def encode_doi_for_uuid(uuid, options = {})
1404
- # look up prefix for rogue scholar blog associated with uuid
1405
- # returns nil if unknown uuid or doi registration is not enabled for blog
1406
- json_feed_by_uuid(uuid)
1403
+ def encode_doi_for_id(id, options = {})
1404
+ # look up prefix for rogue scholar blog associated with id
1405
+ # returns nil if unknown id or doi registration is not enabled for blog
1406
+ json_feed_by_id(id)
1407
1407
  # DOI suffix is a generated from a random number, encoded in base32
1408
1408
  # suffix has 8 digits plus two checksum digits. With base32 there are
1409
1409
  # 32 possible digits, so 8 digits gives 32^8 possible combinations
@@ -1449,8 +1449,8 @@ module Commonmeta
1449
1449
  "https://rogue-scholar.org/api/blogs/#{blog_id}"
1450
1450
  end
1451
1451
 
1452
- def json_feed_item_by_uuid_url(uuid)
1453
- "https://rogue-scholar.org/api/posts/#{uuid}"
1452
+ def json_feed_item_by_id_url(id)
1453
+ "https://rogue-scholar.org/api/posts/#{id}"
1454
1454
  end
1455
1455
 
1456
1456
  def generate_ghost_token(admin_api_key)
@@ -1473,43 +1473,43 @@ module Commonmeta
1473
1473
  JWT.encode payload, [secret].pack("H*"), "HS256", header
1474
1474
  end
1475
1475
 
1476
- def update_ghost_post_via_api(uuid)
1476
+ def update_ghost_post_via_api(id)
1477
1477
  api_key = ENV["API_KEY"]
1478
1478
  api_url = ENV["API_URL"]
1479
1479
 
1480
- return nil unless uuid.present? && api_key.present? && api_url.present?
1480
+ return nil unless id.present? && api_key.present? && api_url.present?
1481
1481
 
1482
1482
  # generate short lived jwt for ghost admin api
1483
1483
  ghost_jwt = generate_ghost_token(api_key)
1484
1484
 
1485
1485
  # get post url and doi from Rogue Scholar API
1486
- url = json_feed_item_by_uuid_url(uuid)
1486
+ url = json_feed_item_by_id_url(id)
1487
1487
  response = HTTP.get(url)
1488
1488
  return nil unless response.status.success?
1489
1489
 
1490
1490
  post = JSON.parse(response.body.to_s)
1491
1491
  url = post.to_h.dig("url")
1492
- doi = validate_doi(post.to_h.dig("id"))
1492
+ doi = validate_doi(post.to_h.dig("doi"))
1493
1493
  doi = doi_as_url(doi)
1494
1494
 
1495
1495
  return nil unless url.present? && doi.present?
1496
1496
 
1497
- # get id and updated_at from ghost api
1497
+ # get post_id and updated_at from ghost api
1498
1498
  slug = url.chomp("/").split("/").last
1499
1499
  ghost_url = "#{api_url}/ghost/api/admin/posts/slug/#{slug}/"
1500
1500
  response = HTTP.auth("Ghost #{ghost_jwt}").get(ghost_url)
1501
1501
  return nil unless response.status.success?
1502
1502
 
1503
1503
  ghost_post = JSON.parse(response.body.to_s).dig("posts").first
1504
- id = ghost_post.dig("id")
1504
+ ghost_id = ghost_post.dig("id")
1505
1505
  updated_at = ghost_post.dig("updated_at")
1506
1506
 
1507
- return nil unless id.present? && updated_at.present?
1507
+ return nil unless ghost_id.present? && updated_at.present?
1508
1508
 
1509
1509
  # update post canonical_url with new doi
1510
- ghost_url = "#{api_url}/ghost/api/admin/posts/#{id}/"
1510
+ ghost_url = "#{api_url}/ghost/api/admin/posts/#{ghost_id}/"
1511
1511
  response = HTTP.auth("Ghost #{ghost_jwt}").headers('Content-Type' => "application/json", 'Accept-Version' => 'v5').put(ghost_url, :json => { 'posts' => [{ 'canonical_url' => doi, 'updated_at' => updated_at }] })
1512
- "#{response.status} DOI #{doi} added to post #{uuid}"
1512
+ "#{response.status} DOI #{doi} added to post #{ghost_id}"
1513
1513
  end
1514
1514
  end
1515
1515
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmeta
4
- VERSION = '3.3.14'
4
+ VERSION = '3.3.16'
5
5
  end
data/spec/cli_spec.rb CHANGED
@@ -332,14 +332,14 @@ describe Commonmeta::CLI do
332
332
  expect { subject.encode_by_blog input }.to output("").to_stdout
333
333
  end
334
334
 
335
- it "by_uuid" do
335
+ it "by_id" do
336
336
  input = "2b22bbba-bcba-4072-94cc-3f88442fff88"
337
- expect { subject.encode_by_uuid input }.to output(/https:\/\/doi.org\/10.54900/).to_stdout
337
+ expect { subject.encode_by_id input }.to output(/https:\/\/doi.org\/10.54900/).to_stdout
338
338
  end
339
339
 
340
- it "by_uuid unknown uuid" do
340
+ it "by_id unknown uuid" do
341
341
  input = "2b22bbba-bcba-4072-94cc-3f88442"
342
- expect { subject.encode_by_uuid input }.to output("").to_stdout
342
+ expect { subject.encode_by_id input }.to output("").to_stdout
343
343
  end
344
344
  end
345
345
 
@@ -367,7 +367,7 @@ describe Commonmeta::CLI do
367
367
 
368
368
  describe "json_feed", vcr: true do
369
369
  it "json_feed_unregistered" do
370
- expect { subject.json_feed_unregistered }.to output(/031faba3-3a6e-49d1-a540-26523be2fd09/).to_stdout
370
+ expect { subject.json_feed_unregistered }.to output(/3023e24a-817d-452e-bb6e-ddadecce94c6/).to_stdout
371
371
  end
372
372
 
373
373
  it "json_feed_not_indexed" do
@@ -376,7 +376,7 @@ describe Commonmeta::CLI do
376
376
 
377
377
  it "json_feed_by_blog" do
378
378
  input = "tyfqw20"
379
- expect { subject.json_feed_by_blog input }.to output(/3e1278f6-e7c0-43e1-bb54-6829e1344c0d/).to_stdout
379
+ expect { subject.json_feed_by_blog input }.to output(/37538c38-66e6-4ac4-ab5c-679684622ade/).to_stdout
380
380
  end
381
381
  end
382
382
  end
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://rogue-scholar.org/api/posts/2b22bbba-bcba-4072-94cc-3f88442fff88
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
+ - '1894'
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Date:
30
+ - Sun, 09 Jul 2023 11:52:35 GMT
31
+ Etag:
32
+ - '"15o6g3vltsa1gm"'
33
+ Server:
34
+ - Vercel
35
+ Strict-Transport-Security:
36
+ - max-age=63072000
37
+ X-Matched-Path:
38
+ - "/api/posts/[[...params]]"
39
+ X-Vercel-Cache:
40
+ - MISS
41
+ X-Vercel-Id:
42
+ - fra1::iad1::flst9-1688903555530-c16d7c4324cc
43
+ Connection:
44
+ - close
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"id":"2b22bbba-bcba-4072-94cc-3f88442fff88","doi":"https://doi.org/10.54900/6p6re-xyj61","url":"https://upstream.force11.org/an-initial-scholarly-ai-taxonomy","title":"An
48
+ Initial Scholarly AI Taxonomy","summary":"Although advances in artificial
49
+ intelligence (AI)1 have been unfolding for over decades, the progress in the
50
+ last six months has come faster than anyone expected. The public release of
51
+ ChatGPT in November 2022, in particular, has opened up new possibilities and
52
+ heightened awareness of AI''s potential role in various aspects of our work
53
+ and life.It follows that in the context of the publishing industry, AI also
54
+ holds the promise of transforming multiple facets of the publishing process2.
55
+ In this...","date_published":"2023-04-11T08:00:34+00:00","date_modified":"2023-04-11T15:29:38+00:00","date_indexed":"2023-06-27T10:51:38.566+00:00","authors":[{"url":null,"name":"Adam
56
+ Hyde"},{"url":"https://orcid.org/0000-0002-7378-2408","name":"John Chodacki"},{"url":null,"name":"Paul
57
+ Shannon"}],"image":"https://upstream.force11.org/content/images/2023/04/1-1.png","tags":["Thought
58
+ Pieces"],"language":"en","references":[],"blog_id":"pm0p222","blog":{"id":"pm0p222","title":"Upstream","description":"The
59
+ community blog for all things Open Research.","language":"en","favicon":"https://upstream.force11.org/favicon.png","feed_url":"https://upstream.force11.org/atom-complete/","home_page_url":"https://upstream.force11.org","user_id":"8498eaf6-8c58-4b58-bc15-27eda292b1aa","created_at":"2023-05-31T07:23:49+00:00","indexed_at":"2023-01-13","feed_format":"application/atom+xml","license":"https://creativecommons.org/licenses/by/4.0/legalcode","generator":"Ghost
60
+ 5.25","category":"Humanities","prefix":"10.54900","modified_at":"2023-07-04T21:15:51+00:00","version":"https://jsonfeed.org/version/1.1","backlog":false,"current_feed_url":"https://upstream.force11.org/atom/","expired":null}}'
61
+ recorded_at: Sun, 09 Jul 2023 11:52:35 GMT
62
+ recorded_with: VCR 6.2.0
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://rogue-scholar.org/api/posts/unregistered
5
+ uri: https://rogue-scholar.org/api/posts/2b22bbba-bcba-4072-94cc-3f88442
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: ''
@@ -15,35 +15,35 @@ http_interactions:
15
15
  - http.rb/5.1.1
16
16
  response:
17
17
  status:
18
- code: 200
19
- message: OK
18
+ code: 404
19
+ message: Not Found
20
20
  headers:
21
21
  Age:
22
22
  - '0'
23
23
  Cache-Control:
24
24
  - public, max-age=0, must-revalidate
25
25
  Content-Length:
26
- - '2'
26
+ - '28'
27
27
  Content-Type:
28
28
  - application/json; charset=utf-8
29
29
  Date:
30
- - Sat, 10 Jun 2023 08:41:01 GMT
30
+ - Sun, 09 Jul 2023 11:52:35 GMT
31
31
  Etag:
32
- - '"38jmpejbxv2"'
32
+ - '"jtxxi9yf69s"'
33
33
  Server:
34
34
  - Vercel
35
35
  Strict-Transport-Security:
36
36
  - max-age=63072000
37
37
  X-Matched-Path:
38
- - "/api/posts/unregistered"
38
+ - "/api/posts/[[...params]]"
39
39
  X-Vercel-Cache:
40
40
  - MISS
41
41
  X-Vercel-Id:
42
- - fra1::iad1::zmnzt-1686386457205-d9f9a0745c33
42
+ - fra1::iad1::r2jnr-1688903554372-bc572f9c2183
43
43
  Connection:
44
44
  - close
45
45
  body:
46
46
  encoding: UTF-8
47
- string: "[]"
48
- recorded_at: Sat, 10 Jun 2023 08:41:01 GMT
49
- recorded_with: VCR 6.1.0
47
+ string: '{"message":"Post not found"}'
48
+ recorded_at: Sun, 09 Jul 2023 11:52:35 GMT
49
+ recorded_with: VCR 6.2.0