pawoo_api_client.rb: convert tabs to spaces.

This commit is contained in:
evazion
2017-06-10 14:48:26 -05:00
parent f2e451c851
commit 77c78430db

View File

@@ -1,81 +1,81 @@
class PawooApiClient class PawooApiClient
extend Memoist extend Memoist
class MissingConfigurationError < Exception ; end class MissingConfigurationError < Exception ; end
class Account class Account
attr_reader :json attr_reader :json
def self.is_match?(url) def self.is_match?(url)
url =~ %r!https?://pawoo.net/web/accounts/(\d+)! url =~ %r!https?://pawoo.net/web/accounts/(\d+)!
$1 $1
end end
def initialize(json) def initialize(json)
@json = get @json = get
end end
def profile_url def profile_url
json["url"] json["url"]
end end
end end
class Status class Status
attr_reader :json attr_reader :json
def self.is_match?(url) def self.is_match?(url)
url =~ %r!https?://pawoo.net/web/statuses/(\d+)! || url =~ %r!https?://pawoo.net/@.+?/(\d+)! url =~ %r!https?://pawoo.net/web/statuses/(\d+)! || url =~ %r!https?://pawoo.net/@.+?/(\d+)!
$1 $1
end end
def initialize(json) def initialize(json)
@json = json @json = json
end end
def account_profile_url def account_profile_url
json["account"]["url"] json["account"]["url"]
end end
def account_name def account_name
json["account"]["username"] json["account"]["username"]
end end
def image_url def image_url
image_urls.first image_urls.first
end end
def image_urls def image_urls
json["media_attachments"].map {|x| x["url"]} json["media_attachments"].map {|x| x["url"]}
end end
end end
def get_status(url) def get_status(url)
if id = Status.is_match?(url) if id = Status.is_match?(url)
Status.new(JSON.parse(access_token.get("/api/v1/statuses/#{id}").body)) Status.new(JSON.parse(access_token.get("/api/v1/statuses/#{id}").body))
else else
nil nil
end end
end end
private private
def fetch_access_token def fetch_access_token
raise MissingConfigurationError.new("missing pawoo client id") if Danbooru.config.pawoo_client_id.nil? raise MissingConfigurationError.new("missing pawoo client id") if Danbooru.config.pawoo_client_id.nil?
raise MissingConfigurationError.new("missing pawoo client secret") if Danbooru.config.pawoo_client_secret.nil? raise MissingConfigurationError.new("missing pawoo client secret") if Danbooru.config.pawoo_client_secret.nil?
Rails.cache.fetch("pawoo-token") do Cache.get("pawoo-token") do
result = client.client_credentials.get_token result = client.client_credentials.get_token
result.token result.token
end end
end end
def access_token def access_token
OAuth2::AccessToken.new(client, fetch_access_token) OAuth2::AccessToken.new(client, fetch_access_token)
end end
def client def client
OAuth2::Client.new(Danbooru.config.pawoo_client_id, Danbooru.config.pawoo_client_secret, :site => "https://pawoo.net") OAuth2::Client.new(Danbooru.config.pawoo_client_id, Danbooru.config.pawoo_client_secret, :site => "https://pawoo.net")
end end
memoize :client memoize :client
end end