commonmeta-ruby 3.3.5 → 3.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/commonmeta +1 -1
- data/lib/commonmeta/cli.rb +1 -5
- data/lib/commonmeta/utils.rb +15 -10
- data/lib/commonmeta/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edf931672f4de5668583515c8d61aff5b4538cf86b929d961866691dc56c0850
|
4
|
+
data.tar.gz: fcd58d117198ee30dd0387bd96ff38ad4c82d1b67b538fcf997661ed3d2019e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 466b00b27e4382baeccab8c5bc82adb516e9a68a2651ba4cb9bbeb6f3e5cc7d6665a25fcf07142dc19fa5ef1dabf4ab273c4c6a75d8377070ea5f54f96af3e5e
|
7
|
+
data.tar.gz: 07634a0d50aed5280e6536cafa0a68fbe267d5d4b1065039aa1d433b305cfd220379e8fb9eab66385b2aa15eea01afb02c974643eb98d6aeb12e399eb9d03b60
|
data/Gemfile.lock
CHANGED
data/bin/commonmeta
CHANGED
@@ -5,5 +5,5 @@ require File.expand_path("../../lib/commonmeta", __FILE__)
|
|
5
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?
|
6
6
|
Commonmeta::CLI.start(ARGV.dup.unshift("convert"))
|
7
7
|
else
|
8
|
-
Commonmeta::CLI.start
|
8
|
+
Commonmeta::CLI.start
|
9
9
|
end
|
data/lib/commonmeta/cli.rb
CHANGED
@@ -117,12 +117,8 @@ module Commonmeta
|
|
117
117
|
|
118
118
|
desc "", "update_ghost_post"
|
119
119
|
|
120
|
-
method_option :api_key, required: true
|
121
|
-
method_option :api_url, required: true
|
122
|
-
method_option :doi, required: true
|
123
|
-
|
124
120
|
def update_ghost_post(uuid)
|
125
|
-
puts update_ghost_post(uuid
|
121
|
+
puts update_ghost_post(uuid)
|
126
122
|
end
|
127
123
|
|
128
124
|
default_task :convert
|
data/lib/commonmeta/utils.rb
CHANGED
@@ -1473,25 +1473,30 @@ module Commonmeta
|
|
1473
1473
|
JWT.encode payload, [secret].pack("H*"), "HS256", header
|
1474
1474
|
end
|
1475
1475
|
|
1476
|
-
def update_ghost_post(uuid
|
1477
|
-
|
1476
|
+
def update_ghost_post(uuid)
|
1477
|
+
api_key = ENV["API_KEY"]
|
1478
|
+
api_url = ENV["API_URL"]
|
1479
|
+
|
1480
|
+
return nil unless uuid.present? && api_key.present? && api_url.present?
|
1478
1481
|
|
1479
1482
|
# generate short lived jwt for ghost admin api
|
1480
|
-
ghost_jwt = generate_ghost_token(
|
1483
|
+
ghost_jwt = generate_ghost_token(api_key)
|
1481
1484
|
|
1482
|
-
# get post url from Rogue Scholar API
|
1485
|
+
# get post url and doi from Rogue Scholar API
|
1483
1486
|
url = json_feed_item_by_uuid_url(uuid)
|
1484
1487
|
response = HTTP.get(url)
|
1485
1488
|
return nil unless response.status.success?
|
1486
1489
|
|
1487
1490
|
post = JSON.parse(response.body.to_s)
|
1488
1491
|
url = post.to_h.dig("url")
|
1489
|
-
|
1490
|
-
|
1492
|
+
doi = validate_doi(post.to_h.dig("id"))
|
1493
|
+
doi = doi_as_url(doi)
|
1494
|
+
|
1495
|
+
return nil unless url.present? && doi.present?
|
1491
1496
|
|
1492
1497
|
# get id and updated_at from ghost api
|
1493
1498
|
slug = url.chomp("/").split("/").last
|
1494
|
-
ghost_url = "#{
|
1499
|
+
ghost_url = "#{api_url}/ghost/api/admin/posts/slug/#{slug}/"
|
1495
1500
|
response = HTTP.auth("Ghost #{ghost_jwt}").get(ghost_url)
|
1496
1501
|
return nil unless response.status.success?
|
1497
1502
|
|
@@ -1502,9 +1507,9 @@ module Commonmeta
|
|
1502
1507
|
return nil unless id.present? && updated_at.present?
|
1503
1508
|
|
1504
1509
|
# update post canonical_url with new doi
|
1505
|
-
ghost_url = "#{
|
1506
|
-
response = HTTP.auth("Ghost #{ghost_jwt}").headers('Content-Type' => "application/json", 'Accept-Version' => 'v5').put(ghost_url, :json => { 'posts' => [{ 'canonical_url' =>
|
1507
|
-
"#{response.status} DOI #{
|
1510
|
+
ghost_url = "#{api_url}/ghost/api/admin/posts/#{id}/"
|
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}"
|
1508
1513
|
end
|
1509
1514
|
end
|
1510
1515
|
end
|
data/lib/commonmeta/version.rb
CHANGED