Fix #5162: NoMethodError in MastodonApiClient#commentary without credentials set

This commit is contained in:
evazion
2022-05-11 00:17:49 -05:00
parent 7573c6dfc9
commit bb461d82b6

View File

@@ -5,22 +5,18 @@
# @see https://docs.joinmastodon.org/api # @see https://docs.joinmastodon.org/api
class MastodonApiClient class MastodonApiClient
extend Memoist extend Memoist
attr_reader :json attr_reader :json, :id
def initialize(site_name, id) def initialize(site_name, id)
@site_name = site_name @site_name = site_name
@id = id
end
return if access_token.blank? def json
return {} if id.blank? || access_token.blank?
if id.blank? JSON.parse(access_token.get("/api/v1/statuses/#{id}").body)
@json = {} rescue
else {}
begin
@json = JSON.parse(access_token.get("/api/v1/statuses/#{id}").body)
rescue StandardError
@json = {}
end
end
end end
def profile_url def profile_url
@@ -89,5 +85,5 @@ class MastodonApiClient
OAuth2::Client.new(client_id, client_secret, :site => "https://#{@site_name}") OAuth2::Client.new(client_id, client_secret, :site => "https://#{@site_name}")
end end
memoize :client memoize :client, :json
end end