From bb461d82b66aa27b254b4b9c5293847e3f4865de Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 11 May 2022 00:17:49 -0500 Subject: [PATCH] Fix #5162: NoMethodError in MastodonApiClient#commentary without credentials set --- app/logical/mastodon_api_client.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/logical/mastodon_api_client.rb b/app/logical/mastodon_api_client.rb index a2de2c6a7..ed26a1da7 100644 --- a/app/logical/mastodon_api_client.rb +++ b/app/logical/mastodon_api_client.rb @@ -5,22 +5,18 @@ # @see https://docs.joinmastodon.org/api class MastodonApiClient extend Memoist - attr_reader :json + attr_reader :json, :id def initialize(site_name, id) @site_name = site_name + @id = id + end - return if access_token.blank? - - if id.blank? - @json = {} - else - begin - @json = JSON.parse(access_token.get("/api/v1/statuses/#{id}").body) - rescue StandardError - @json = {} - end - end + def json + return {} if id.blank? || access_token.blank? + JSON.parse(access_token.get("/api/v1/statuses/#{id}").body) + rescue + {} end def profile_url @@ -89,5 +85,5 @@ class MastodonApiClient OAuth2::Client.new(client_id, client_secret, :site => "https://#{@site_name}") end - memoize :client + memoize :client, :json end