commonmeta-ruby 3.3.15 → 3.3.17

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/commonmeta/readers/json_feed_reader.rb +8 -8
  4. data/lib/commonmeta/utils.rb +14 -0
  5. data/lib/commonmeta/version.rb +1 -1
  6. data/spec/cli_spec.rb +2 -2
  7. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_by_blog.yml +189 -1704
  8. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_unregistered.yml +54 -1969
  9. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed/by_blog_id.yml +210 -518
  10. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed/not_indexed_posts.yml +6 -1450
  11. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed/unregistered_posts.yml +54 -8
  12. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/blog_post_with_non-url_id.yml +18 -88
  13. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/blogger_post.yml +11 -50
  14. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/ghost_post_with_author_name_suffix.yml +64 -173
  15. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/ghost_post_with_doi.yml +13 -75
  16. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/ghost_post_with_institutional_author.yml +15 -11
  17. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/ghost_post_with_organizational_author.yml +15 -46
  18. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/ghost_post_without_doi.yml +17 -155
  19. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/jekyll_post.yml +14 -45
  20. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/jekyll_post_with_anonymous_author.yml +13 -16
  21. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/substack_post_with_broken_reference.yml +938 -1865
  22. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/syldavia_gazette_post_with_references.yml +128 -267
  23. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/upstream_post_with_references.yml +570 -1279
  24. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/wordpress_post.yml +12 -119
  25. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/wordpress_post_with_many_references.yml +4095 -5759
  26. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/wordpress_post_with_references.yml +24 -220
  27. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/wordpress_post_with_tracking_code_on_url.yml +13 -12
  28. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_feed_item_from_rogue_scholar_with_anonymous_author.yml +13 -16
  29. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_feed_item_from_rogue_scholar_with_doi.yml +12 -119
  30. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_feed_item_from_rogue_scholar_with_organizational_author.yml +15 -46
  31. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_feed_item_from_upstream_blog.yml +13 -201
  32. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_feed_item_with_references.yml +104 -813
  33. data/spec/readers/json_feed_reader_spec.rb +22 -24
  34. data/spec/utils_spec.rb +40 -0
  35. data/spec/writers/crossref_xml_writer_spec.rb +4 -4
  36. metadata +2 -5
  37. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/blog_post.yml +0 -360
  38. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/blog_post_uuid.yml +0 -980
  39. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed_unregistered/blog_post_uuid.yml +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7f58c5181ad8210359b3e6cb897e6a7c0b66d6065f2dda0836998e1a59939af
4
- data.tar.gz: 780639668c9bc7b2fec43061818db60e3c05d4c6e430e6d03349d02ae781eacd
3
+ metadata.gz: 3d9089eaa55c76c89411f0b252418860d40c498b77ad5e07ff6937d26364fff4
4
+ data.tar.gz: b251346f6fd8fe1714632587ee46196b00c3c4bb8c4ba7bf0fe6decd54c5a9e3
5
5
  SHA512:
6
- metadata.gz: 65ab7d09ed4a84c4ba153a94f142de3a4878899832135883d83123b6bfdfa48b7c21f47b87ae6f385a158d874316ebed4236d531bd8f9921ce2a4802561b2015
7
- data.tar.gz: b3970a10d049bcce65a9ac9a2f357b5569422335b2cc317877821aa7dddb3a0aa29070c2ab196dcccdfbd02f670f827d9515083c480f94c2686c34b3ceb5b524
6
+ metadata.gz: 87733ee7cf23b71317df6c8ef7ad2eea099db43a6291a948f93b18220aeff5f3cf72e8ec9a9b0e36b3f243fe7b651d1b7d401341d0cf0524d0a6c3ea0db1bc7f
7
+ data.tar.gz: 131dbb14b63cca5c62acce085746f0dc13ef99252bd9243a84c0565a5e671e45c613cc12903df297e4c9df8bd0f5a6d69b645d18e622dd895c0d120e0d7b7f46
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- commonmeta-ruby (3.3.15)
4
+ commonmeta-ruby (3.3.17)
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)
@@ -21,7 +21,7 @@ module Commonmeta
21
21
  meta = string.present? ? JSON.parse(string) : {}
22
22
 
23
23
  url = normalize_url(meta.fetch("url", nil))
24
- id = options[:doi] ? normalize_doi(options[:doi]) : normalize_id(meta.fetch("id", nil))
24
+ id = options[:doi] ? normalize_doi(options[:doi]) : normalize_id(meta.fetch("doi", nil))
25
25
  id = url if id.blank? && url.present?
26
26
 
27
27
  type = "Article"
@@ -34,8 +34,8 @@ module Commonmeta
34
34
  publisher = { "name" => meta.dig("blog", "title") }
35
35
 
36
36
  date = {}
37
- date["published"] = get_iso8601_date(meta.dig("date_published")) if meta.dig("date_published").present?
38
- date["updated"] = get_iso8601_date(meta.dig("date_modified")) if meta.dig("date_modified").present?
37
+ date["published"] = get_date_from_unix_timestamp(meta.dig("published_at")) if meta.dig("published_at").present?
38
+ date["updated"] = get_date_from_unix_timestamp(meta.dig("updated_at")) if meta.dig("updated_at").present?
39
39
 
40
40
  license = if meta.dig("blog", "license").present?
41
41
  hsh_to_spdx("rightsURI" => meta.dig("blog", "license"))
@@ -62,7 +62,7 @@ module Commonmeta
62
62
  sum
63
63
  end
64
64
  references = get_references(meta)
65
- alternate_identifiers = [{ "alternateIdentifier" => meta["uuid"], "alternateIdentifierType" => "UUID" }]
65
+ alternate_identifiers = [{ "alternateIdentifier" => meta["id"], "alternateIdentifierType" => "UUID" }]
66
66
 
67
67
  { "id" => id,
68
68
  "type" => type,
@@ -83,7 +83,7 @@ module Commonmeta
83
83
 
84
84
  def get_references(meta)
85
85
  # check that references resolve
86
- Array.wrap(meta["references"]).reduce([]) do |sum, reference|
86
+ Array.wrap(meta["reference"]).reduce([]) do |sum, reference|
87
87
  begin
88
88
  if reference["doi"] && validate_doi(reference["doi"])
89
89
  response = HTTP.follow
@@ -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,7 @@ 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
+ posts.map { |post| post["id"] }.first
126
126
  end
127
127
 
128
128
  def get_json_feed_by_blog(blog_id)
@@ -133,7 +133,7 @@ module Commonmeta
133
133
  return { "string" => nil, "state" => "not_found" } unless response.status.success?
134
134
 
135
135
  blog = JSON.parse(response.body.to_s)
136
- blog["items"].map { |item| item["uuid"] }.first
136
+ blog["items"].map { |item| item["id"] }.first
137
137
  end
138
138
 
139
139
  def get_doi_prefix_by_blog_id(blog_id)
@@ -1094,6 +1094,20 @@ module Commonmeta
1094
1094
  nil
1095
1095
  end
1096
1096
 
1097
+ # parsing of unix timestamps such as 1427846400
1098
+ def get_datetime_from_unix_timestamp(unix_timestamp)
1099
+ strip_milliseconds(DateTime.strptime(unix_timestamp.to_s, '%s').iso8601)
1100
+ rescue StandardError
1101
+ nil
1102
+ end
1103
+
1104
+ # parsing of unix timestamps such as 1427846400
1105
+ def get_date_from_unix_timestamp(unix_timestamp)
1106
+ DateTime.strptime(unix_timestamp.to_s, '%s').strftime('%Y-%m-%d')
1107
+ rescue StandardError
1108
+ nil
1109
+ end
1110
+
1097
1111
  # strip milliseconds if there is a time, as it interferes with edtc parsing
1098
1112
  # keep dates unchanged
1099
1113
  def strip_milliseconds(iso8601_time)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmeta
4
- VERSION = '3.3.15'
4
+ VERSION = '3.3.17'
5
5
  end
data/spec/cli_spec.rb CHANGED
@@ -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