Skip to content

Commit

Permalink
remove blog_id and consistently use blog_slug
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Dec 25, 2023
1 parent 10de079 commit af4deee
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 26 deletions.
23 changes: 12 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bin/commonmeta
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/commonmeta/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions lib/commonmeta/readers/json_feed_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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?

Expand Down
2 changes: 1 addition & 1 deletion lib/commonmeta/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Commonmeta
VERSION = '3.7.2'
VERSION = '3.7.3'
end
4 changes: 2 additions & 2 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/readers/json_feed_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit af4deee

Please sign in to comment.