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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cce77aa997b52aa12e81e987f14ea774684fb51dd90fe059202f4beb3c83a2bf
4
- data.tar.gz: 6902fadfdae00f8f60b074a954067a5068f4bc4dcfccd03aa43e721d1ccc2840
3
+ metadata.gz: edf931672f4de5668583515c8d61aff5b4538cf86b929d961866691dc56c0850
4
+ data.tar.gz: fcd58d117198ee30dd0387bd96ff38ad4c82d1b67b538fcf997661ed3d2019e6
5
5
  SHA512:
6
- metadata.gz: c672bdf54f0b78306eb3022f9a9e6cbbff066349bd38c8b09d45508eeecb36eae7a9d4cf0d69f724ddcf2fac7654fcd00844dc5cd480a4ad6c09c61c01f85b57
7
- data.tar.gz: d8a729f63506c8bd3a6ae66bffd4561ebd7d958583b8d95d954bf46c3097171b028c1356f25a0f7f2937acae61dc43069a280e42923c675265369bc5e4e17b87
6
+ metadata.gz: 466b00b27e4382baeccab8c5bc82adb516e9a68a2651ba4cb9bbeb6f3e5cc7d6665a25fcf07142dc19fa5ef1dabf4ab273c4c6a75d8377070ea5f54f96af3e5e
7
+ data.tar.gz: 07634a0d50aed5280e6536cafa0a68fbe267d5d4b1065039aa1d433b305cfd220379e8fb9eab66385b2aa15eea01afb02c974643eb98d6aeb12e399eb9d03b60
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- commonmeta-ruby (3.3.5)
4
+ commonmeta-ruby (3.3.6)
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)
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(ARGV)
8
+ Commonmeta::CLI.start
9
9
  end
@@ -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: uuid, api_key: options[:api_key], api_url: options[:api_url], doi: options[:doi])
121
+ puts update_ghost_post(uuid)
126
122
  end
127
123
 
128
124
  default_task :convert
@@ -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: nil, **options)
1477
- return nil unless uuid.present? && options[:api_key].present? && options[:api_url].present? && options[:doi].present?
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(options[:api_key])
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
- return nil unless url.present?
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 = "#{options[:api_url]}/ghost/api/admin/posts/slug/#{slug}/"
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 = "#{options[:api_url]}/ghost/api/admin/posts/#{id}/"
1506
- response = HTTP.auth("Ghost #{ghost_jwt}").headers('Content-Type' => "application/json", 'Accept-Version' => 'v5').put(ghost_url, :json => { 'posts' => [{ 'canonical_url' => options[:doi], 'updated_at' => updated_at }] })
1507
- "#{response.status} DOI #{options[:doi]} updated for post #{uuid}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmeta
4
- VERSION = '3.3.5'
4
+ VERSION = '3.3.6'
5
5
  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.3.5
4
+ version: 3.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner