twitter: don't fail when api key isn't configured.
This commit is contained in:
@@ -22,6 +22,12 @@ module Sources
|
||||
false
|
||||
end
|
||||
|
||||
# Should return true if all prerequisites for using the strategy are met.
|
||||
# Return false if the strategy requires api keys that have not been configured.
|
||||
def self.enabled?
|
||||
true
|
||||
end
|
||||
|
||||
# * <tt>url</tt> - Should point to a resource suitable for
|
||||
# downloading. This may sometimes point to the binary file.
|
||||
# It may also point to the artist's profile page, in cases
|
||||
|
||||
@@ -13,6 +13,10 @@ module Sources::Strategies
|
||||
urls.compact.any? { |x| x =~ PAGE || x =~ ASSET}
|
||||
end
|
||||
|
||||
def self.enabled?
|
||||
TwitterService.new.enabled?
|
||||
end
|
||||
|
||||
# https://twitter.com/i/web/status/943446161586733056
|
||||
# https://twitter.com/motty08111213/status/943446161586733056
|
||||
def self.status_id_from_url(url)
|
||||
@@ -135,6 +139,7 @@ module Sources::Strategies
|
||||
memoize :service
|
||||
|
||||
def api_response
|
||||
return {} if !service.enabled?
|
||||
service.status(status_id, tweet_mode: "extended")
|
||||
rescue ::Twitter::Error::NotFound
|
||||
{}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
class TwitterService
|
||||
class Error < Exception ; end
|
||||
extend Memoist
|
||||
|
||||
def enabled?
|
||||
Danbooru.config.twitter_api_key.present? && Danbooru.config.twitter_api_secret.present?
|
||||
end
|
||||
|
||||
def client
|
||||
raise "Twitter API keys not set" if Danbooru.config.twitter_api_key.nil?
|
||||
raise Error, "Twitter API keys not set" if !enabled?
|
||||
|
||||
rest_client = ::Twitter::REST::Client.new do |config|
|
||||
config.consumer_key = Danbooru.config.twitter_api_key
|
||||
|
||||
Reference in New Issue
Block a user