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 +4 -4
- data/Gemfile.lock +2 -2
- data/bin/commonmeta +1 -1
- data/lib/commonmeta/cli.rb +5 -5
- data/lib/commonmeta/readers/json_feed_reader.rb +6 -5
- data/lib/commonmeta/utils.rb +15 -15
- data/lib/commonmeta/version.rb +1 -1
- data/spec/cli_spec.rb +6 -6
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/encode/by_id.yml +62 -0
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/{json_feed_unregistered/blog_post_uuid.yml → encode/by_id_unknown_uuid.yml} +11 -11
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_by_blog.yml +189 -1704
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_unregistered.yml +54 -1969
- data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_doi_prefix_for_blog/by_blog_post_id.yml +65 -0
- data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_doi_prefix_for_blog/by_blog_post_id_specific_prefix.yml +62 -0
- data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed/by_blog_id.yml +210 -518
- data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed/not_indexed_posts.yml +6 -1450
- data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed/unregistered_posts.yml +54 -8
- data/spec/readers/json_feed_reader_spec.rb +7 -7
- metadata +6 -5
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/blog_post.yml +0 -360
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/blog_post_uuid.yml +0 -980
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1959fba18a127e97c92b94c7e0e78d42c4538e3bccf6b9e6019035931e19d2f4
|
4
|
+
data.tar.gz: 190a4ddc0e6789c56f6f9a5a97355c8684e103abf121d2dfefdd5c1d816bd2d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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
|
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
|
data/lib/commonmeta/cli.rb
CHANGED
@@ -77,10 +77,10 @@ module Commonmeta
|
|
77
77
|
puts encode_doi(prefix)
|
78
78
|
end
|
79
79
|
|
80
|
-
desc "", "
|
80
|
+
desc "", "encode_by_id"
|
81
81
|
|
82
|
-
def
|
83
|
-
prefix =
|
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(
|
121
|
-
puts update_ghost_post_via_api(
|
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["
|
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.
|
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["
|
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
|
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 =
|
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
|
|
data/lib/commonmeta/utils.rb
CHANGED
@@ -1400,10 +1400,10 @@ module Commonmeta
|
|
1400
1400
|
"https://doi.org/#{prefix}/#{str}"
|
1401
1401
|
end
|
1402
1402
|
|
1403
|
-
def
|
1404
|
-
# look up prefix for rogue scholar blog associated with
|
1405
|
-
# returns nil if unknown
|
1406
|
-
|
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
|
1453
|
-
"https://rogue-scholar.org/api/posts/#{
|
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(
|
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
|
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 =
|
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("
|
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
|
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
|
-
|
1504
|
+
ghost_id = ghost_post.dig("id")
|
1505
1505
|
updated_at = ghost_post.dig("updated_at")
|
1506
1506
|
|
1507
|
-
return nil unless
|
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/#{
|
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 #{
|
1512
|
+
"#{response.status} DOI #{doi} added to post #{ghost_id}"
|
1513
1513
|
end
|
1514
1514
|
end
|
1515
1515
|
end
|
data/lib/commonmeta/version.rb
CHANGED
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 "
|
335
|
+
it "by_id" do
|
336
336
|
input = "2b22bbba-bcba-4072-94cc-3f88442fff88"
|
337
|
-
expect { subject.
|
337
|
+
expect { subject.encode_by_id input }.to output(/https:\/\/doi.org\/10.54900/).to_stdout
|
338
338
|
end
|
339
339
|
|
340
|
-
it "
|
340
|
+
it "by_id unknown uuid" do
|
341
341
|
input = "2b22bbba-bcba-4072-94cc-3f88442"
|
342
|
-
expect { subject.
|
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(/
|
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(/
|
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/
|
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:
|
19
|
-
message:
|
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
|
-
- '
|
26
|
+
- '28'
|
27
27
|
Content-Type:
|
28
28
|
- application/json; charset=utf-8
|
29
29
|
Date:
|
30
|
-
-
|
30
|
+
- Sun, 09 Jul 2023 11:52:35 GMT
|
31
31
|
Etag:
|
32
|
-
- '"
|
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/
|
38
|
+
- "/api/posts/[[...params]]"
|
39
39
|
X-Vercel-Cache:
|
40
40
|
- MISS
|
41
41
|
X-Vercel-Id:
|
42
|
-
- fra1::iad1::
|
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:
|
49
|
-
recorded_with: VCR 6.
|
47
|
+
string: '{"message":"Post not found"}'
|
48
|
+
recorded_at: Sun, 09 Jul 2023 11:52:35 GMT
|
49
|
+
recorded_with: VCR 6.2.0
|