From af4deeef8780e542edfad20a10f6eab51a808670 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 25 Dec 2023 11:41:06 +0100 Subject: [PATCH] remove blog_id and consistently use blog_slug --- Gemfile.lock | 23 +++--- bin/commonmeta | 2 +- lib/commonmeta/cli.rb | 10 +-- lib/commonmeta/readers/json_feed_reader.rb | 8 +-- lib/commonmeta/version.rb | 2 +- spec/cli_spec.rb | 4 +- .../json_feed/json_feed_blog_slug.yml | 71 +++++++++++++++++++ spec/readers/json_feed_reader_spec.rb | 4 +- 8 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_blog_slug.yml diff --git a/Gemfile.lock b/Gemfile.lock index 617a614b..6a38a82b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - commonmeta-ruby (3.7.2) + commonmeta-ruby (3.7.3) activesupport (>= 4.2.5, < 8.0) addressable (~> 2.8.1, < 2.8.2) base32-url (>= 0.7.0, < 1) @@ -46,7 +46,7 @@ GEM bcp47_spec (0.2.1) bibtex-ruby (6.0.0) latex-decode (~> 0.0) - bigdecimal (3.1.4) + bigdecimal (3.1.5) builder (3.2.4) citeproc (1.0.10) namae (~> 1.0) @@ -70,11 +70,11 @@ GEM domain_name (0.6.20231109) drb (2.2.0) ruby2_keywords - ebnf (2.4.0) + ebnf (2.5.0) htmlentities (~> 4.3) rdf (~> 3.3) scanf (~> 1.0) - sxp (~> 1.3) + sxp (~> 2.0) unicode-types (~> 1.8) edtf (3.1.1) activesupport (>= 3.0, < 8.0) @@ -137,9 +137,10 @@ GEM namae (1.1.1) nokogiri (1.15.5-arm64-darwin) racc (~> 1.4) - oj (3.16.1) + oj (3.16.3) + bigdecimal (>= 3.0) optimist (3.1.0) - parallel (1.23.0) + parallel (1.24.0) parser (3.2.2.4) ast (~> 2.4.1) racc @@ -188,7 +189,7 @@ GEM rspec-xsd (0.1.0) nokogiri (~> 1.6) rspec (~> 3) - rubocop (1.58.0) + rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -205,9 +206,9 @@ GEM rubocop (~> 1.41) rubocop-factory_bot (2.24.0) rubocop (~> 1.33) - rubocop-performance (1.19.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) + rubocop-performance (1.20.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) rubocop-rake (0.6.0) rubocop (~> 1.0) rubocop-rspec (2.25.0) @@ -226,7 +227,7 @@ GEM simplecov_json_formatter (0.1.4) simpleidn (0.2.1) unf (~> 0.1.4) - sxp (1.3.0) + sxp (2.0.0) matrix (~> 0.4) rdf (~> 3.3) textutils (1.4.0) diff --git a/bin/commonmeta b/bin/commonmeta index 747587df..5b2200a3 100755 --- a/bin/commonmeta +++ b/bin/commonmeta @@ -2,7 +2,7 @@ require File.expand_path("../../lib/commonmeta", __FILE__) -if (ARGV & %w(--version -v help --help encode decode encode_id decode_id encode_by_blog encode_by_id json_feed_updated json_feed_unregistered json_feed_by_blog json_feed_blog_id update_ghost_post generate_ghost_api_token)).empty? +if (ARGV & %w(--version -v help --help encode decode encode_id decode_id encode_by_blog encode_by_id json_feed_updated json_feed_unregistered json_feed_by_blog json_feed_blog_slug update_ghost_post generate_ghost_api_token)).empty? Commonmeta::CLI.start(ARGV.dup.unshift("convert")) else Commonmeta::CLI.start diff --git a/lib/commonmeta/cli.rb b/lib/commonmeta/cli.rb index b3d57f5b..455cc250 100644 --- a/lib/commonmeta/cli.rb +++ b/lib/commonmeta/cli.rb @@ -71,8 +71,8 @@ def encode_id desc "", "encode_by_blog" - def encode_by_blog(blog_id) - prefix = get_doi_prefix_by_blog_id(blog_id) + def encode_by_blog(blog_slug) + prefix = get_doi_prefix_by_blog_slug(blog_slug) return nil unless prefix.present? puts encode_doi(prefix) end @@ -115,10 +115,10 @@ def json_feed_by_blog(id) puts get_json_feed_by_blog(id) end - desc "", "json_feed_blog_id" + desc "", "json_feed_blog_slug" - def json_feed_blog_id(id) - puts get_json_feed_blog_id(id) + def json_feed_blog_slug(slug) + puts get_json_feed_blog_slug(slug) end desc "", "update_ghost_post" diff --git a/lib/commonmeta/readers/json_feed_reader.rb b/lib/commonmeta/readers/json_feed_reader.rb index aee8e3a4..93e70d7d 100644 --- a/lib/commonmeta/readers/json_feed_reader.rb +++ b/lib/commonmeta/readers/json_feed_reader.rb @@ -212,8 +212,8 @@ def get_json_feed_by_blog(blog_id) blog["items"].map { |item| item["id"] }.first end - def get_json_feed_blog_id(id) - # get JSON Feed item by id and return blog id + def get_json_feed_blog_slug(id) + # get JSON Feed item by id and return blog slug url = json_feed_item_by_id_url(id) response = HTTP.get(url) @@ -223,10 +223,10 @@ def get_json_feed_blog_id(id) post.to_h.dig("blog", "slug") end - def get_doi_prefix_by_blog_id(blog_id) + def get_doi_prefix_by_blog_slug(blog_slug) # for generating a random DOI. - url = json_feed_by_blog_url(blog_id) + url = json_feed_by_blog_url(blog_slug) response = HTTP.get(url) return nil unless response.status.success? diff --git a/lib/commonmeta/version.rb b/lib/commonmeta/version.rb index 21b6a0ff..6c61fda1 100644 --- a/lib/commonmeta/version.rb +++ b/lib/commonmeta/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Commonmeta - VERSION = '3.7.2' + VERSION = '3.7.3' end diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 47fe405a..e2ef0b28 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -379,9 +379,9 @@ expect { subject.json_feed_by_blog input }.to output(/3749f8c4-1ba7-4e51-9dd6-9d9551ad451a/).to_stdout end - it "json_feed_blog_id" do + it "json_feed_blog_slug" do input = "01a92f9a-f8e0-442b-86e2-11530d9d5635" - expect { subject.json_feed_blog_id input }.to output(/eve/).to_stdout + expect { subject.json_feed_blog_slug input }.to output(/eve/).to_stdout end end end diff --git a/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_blog_slug.yml b/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_blog_slug.yml new file mode 100644 index 00000000..c39bf0dd --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_blog_slug.yml @@ -0,0 +1,71 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.rogue-scholar.org/posts/01a92f9a-f8e0-442b-86e2-11530d9d5635 + body: + encoding: ASCII-8BIT + string: '' + headers: + Connection: + - close + Host: + - api.rogue-scholar.org + User-Agent: + - http.rb/5.1.1 + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Content-Length: + - '3313' + Ratelimit-Limit: + - '15' + Ratelimit-Remaining: + - '14' + Ratelimit-Reset: + - '3' + Date: + - Mon, 25 Dec 2023 10:38:50 GMT + Server: + - Fly/9e37a80f (2023-12-22) + Via: + - 1.1 fly.io + Fly-Request-Id: + - 01HJG8WMFGNRM35PXT9HSQJYJH-fra + body: + encoding: UTF-8 + string: '{"archive_url":"https://wayback.archive-it.org/22123/20231101171300/https://eve.gd/2017/05/07/an-important-note-if-you-have-a-lenovo-g580","authors":[{"name":"Martin + Paul Eve","url":"https://orcid.org/0000-0002-5589-8511"}],"blog":{"api":false,"archive_prefix":"https://wayback.archive-it.org/22123/20231101171300/","authors":[{"name":"Martin + Paul Eve","url":null}],"backlog":0,"canonical_url":null,"category":"languagesAndLiterature","created_at":1690329600,"current_feed_url":"https://eve.gd/feed/feed.atom","description":null,"favicon":"https://eve.gd/favicon.png","feed_format":"application/atom+xml","feed_url":"https://eve.gd/feed_all.xml","filter":null,"funding":null,"generator":"Jekyll","generator_raw":"Jekyll","home_page_url":"https://eve.gd","id":"z4b9d78","indexed":false,"issn":null,"language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","plan":"Team","prefix":"10.59348","relative_url":"blog","secure":true,"slug":"eve","status":"active","title":"Martin + Paul Eve","updated_at":1702425600,"use_api":null,"use_mastodon":false,"user_id":"eb3f6a26-3e38-42ad-b752-250eb2c0bf89","version":"https://jsonfeed.org/version/1.1"},"blog_name":"Martin + Paul Eve","blog_slug":"eve","content_text":"The Lenovo G580 comes with Windows + 8. It is possible to permanently lock\nyourself out of the operating system + if you begin with a Microsoft\naccount and migrate this to a local account. + Further, you won''t be able\nto rescue the system since *it is impossible + to enter the BIOS setup in\nthe machine''s default state if you cannot login + to Windows*.\n\nTo fix this:\n\n1. Disable \"fast boot\" mode in Windows + 8. You can do this in \"Power\n Settings\". If you don''t do this, you + can''t modify the Windows disk\n partition when booting from a recovery + USB.\n2. [Update your\n BIOS](https://download.lenovo.com/consumer/mobiles/62cn97ww_64.exe).\n Do + it now or you won''t be able to unless you can still login to\n Windows + 8.\n3. Go into the BIOS (shutdown the machine then press the small button\n next + to the power button and select \"BIOS setup\"). Then, set an\n administrator + password in the BIOS settings. Then, \"disable secure\n boot\". This will + allow you to boot from a recovery USB stick such as\n Kali or Ubuntu.\n\nUrgh. + A Catch-22 where Microsoft Windows corrupted a login (thanks,\nMicrosoft) + and a hardware defect stops you booting into a recovery\nmedium (thanks, Lenovo).\n\n[An + important note if you have a Lenovo\nG580](https://eve.gd/2017/05/07/an-important-note-if-you-have-a-lenovo-g580/)\nwas + originally published by Martin Paul Eve at [Martin Paul\nEve](https://eve.gd) + on May 07, 2017.\n","doi":"https://doi.org/10.59348/dmq66-f5d26","guid":"https://eve.gd/2017/05/07/an-important-note-if-you-have-a-lenovo-g580","id":"01a92f9a-f8e0-442b-86e2-11530d9d5635","image":null,"indexed_at":1696162656,"language":"en","published_at":1494172558,"reference":[],"relationships":[],"summary":"The + Lenovo G580 comes with Windows 8. It is possible to permanently lock yourself + out of the operating system if you begin with a Microsoft account and migrate + this to a local account.\n","tags":[],"title":"An important note if you have + a Lenovo G580","updated_at":1494115200,"url":"https://eve.gd/2017/05/07/an-important-note-if-you-have-a-lenovo-g580"} + + ' + recorded_at: Mon, 25 Dec 2023 10:38:50 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/readers/json_feed_reader_spec.rb b/spec/readers/json_feed_reader_spec.rb index edd35072..33ae05df 100644 --- a/spec/readers/json_feed_reader_spec.rb +++ b/spec/readers/json_feed_reader_spec.rb @@ -528,7 +528,7 @@ context "get doi_prefix for blog", vcr: true do it "by blog_id" do - response = subject.get_doi_prefix_by_blog_id("iphylo") + response = subject.get_doi_prefix_by_blog_slug("iphylo") expect(response).to eq("10.59350") end @@ -545,7 +545,7 @@ context "get blog_id for json_feed item id", vcr: true do it "by blog post id" do - response = subject.get_json_feed_blog_id("1898d2d7-4d87-4487-96c4-3073cf99e9a5") + response = subject.get_json_feed_blog_slug("1898d2d7-4d87-4487-96c4-3073cf99e9a5") expect(response).to eq("sfmatheson") end