commonmeta-ruby 3.3.4 → 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: 64e45cd8a5e13c62d97cf71bfa6806a85dc12548b221207eb7938f1285635a6c
4
- data.tar.gz: 2890b683526f5013b6ffd4c95c6b6bbdf2d1b148150e0662ed2ff915260aaf49
3
+ metadata.gz: edf931672f4de5668583515c8d61aff5b4538cf86b929d961866691dc56c0850
4
+ data.tar.gz: fcd58d117198ee30dd0387bd96ff38ad4c82d1b67b538fcf997661ed3d2019e6
5
5
  SHA512:
6
- metadata.gz: 5bf8c06824328fee1aa671735c52c52ae1f15506855febdcf63f8b4bd68e4282fe232501c437cbbf2fd60034773e47e763f056bcb0eb087c1218bac8c026e360
7
- data.tar.gz: dd4bb2c23711c452d562036458664bf757c1e53bbdc013c8c6276e00806aa4fca7c29b6e43957605b9937b0b6cebcd1d0fdb3cd94b035ae3ba4e6a2237de33e3
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.4)
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)
@@ -22,7 +22,7 @@ PATH
22
22
  postrank-uri (~> 1.1)
23
23
  rdf-rdfxml (~> 3.2)
24
24
  rdf-turtle (~> 3.2)
25
- thor (~> 1.1, >= 1.1.0)
25
+ thor (~> 1.2, >= 1.2.2)
26
26
 
27
27
  GEM
28
28
  remote: https://rubygems.org/
data/commonmeta.gemspec CHANGED
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.add_dependency 'postrank-uri', '~> 1.1'
39
39
  s.add_dependency 'rdf-rdfxml', '~> 3.2'
40
40
  s.add_dependency 'rdf-turtle', '~> 3.2'
41
- s.add_dependency 'thor', '~> 1.1', '>= 1.1.0'
41
+ s.add_dependency 'thor', '~> 1.2', '>= 1.2.2'
42
42
  s.add_development_dependency 'bundler', '~> 2.3', '>= 2.3.1'
43
43
  s.add_development_dependency 'code-scanning-rubocop', '~> 0.6.1'
44
44
  s.add_development_dependency 'hashdiff', '~> 1.0.1'
@@ -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.4'
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.4
4
+ version: 3.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
@@ -344,20 +344,20 @@ dependencies:
344
344
  requirements:
345
345
  - - "~>"
346
346
  - !ruby/object:Gem::Version
347
- version: '1.1'
347
+ version: '1.2'
348
348
  - - ">="
349
349
  - !ruby/object:Gem::Version
350
- version: 1.1.0
350
+ version: 1.2.2
351
351
  type: :runtime
352
352
  prerelease: false
353
353
  version_requirements: !ruby/object:Gem::Requirement
354
354
  requirements:
355
355
  - - "~>"
356
356
  - !ruby/object:Gem::Version
357
- version: '1.1'
357
+ version: '1.2'
358
358
  - - ">="
359
359
  - !ruby/object:Gem::Version
360
- version: 1.1.0
360
+ version: 1.2.2
361
361
  - !ruby/object:Gem::Dependency
362
362
  name: bundler
363
363
  requirement: !ruby/object:Gem::Requirement