lib/commonmeta/utils.rb in commonmeta-ruby-3.3.17 vs lib/commonmeta/utils.rb in commonmeta-ruby-3.3.18
- old
+ new
@@ -1094,18 +1094,18 @@
nil
end
# parsing of unix timestamps such as 1427846400
def get_datetime_from_unix_timestamp(unix_timestamp)
- strip_milliseconds(DateTime.strptime(unix_timestamp.to_s, '%s').iso8601)
+ strip_milliseconds(DateTime.strptime(unix_timestamp.to_s, "%s").iso8601)
rescue StandardError
nil
end
# parsing of unix timestamps such as 1427846400
def get_date_from_unix_timestamp(unix_timestamp)
- DateTime.strptime(unix_timestamp.to_s, '%s').strftime('%Y-%m-%d')
+ DateTime.strptime(unix_timestamp.to_s, "%s").strftime("%Y-%m-%d")
rescue StandardError
nil
end
# strip milliseconds if there is a time, as it interferes with edtc parsing
@@ -1465,13 +1465,15 @@
def json_feed_item_by_id_url(id)
"https://rogue-scholar.org/api/posts/#{id}"
end
- def generate_ghost_token(admin_api_key)
+ def generate_ghost_token(admin_api_key = ENV["API_KEY"])
# from https://ghost.org/docs/admin-api/
+ return nil unless admin_api_key.present?
+
# Split the key into ID and SECRET
id, secret = admin_api_key.split(":")
# Prepare header and payload
iat = Time.now.to_i
@@ -1520,10 +1522,10 @@
return nil unless ghost_id.present? && updated_at.present?
# update post canonical_url with new doi
ghost_url = "#{api_url}/ghost/api/admin/posts/#{ghost_id}/"
- 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 }] })
+ 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 }] })
"#{response.status} DOI #{doi} added to post #{ghost_id}"
end
end
end