class Kuva::Authorizer

Attributes

out[R]

Public Class Methods

authorize() click to toggle source
# File lib/kuva/authorizer.rb, line 6
def self.authorize
  new.authorize
end
new() click to toggle source
# File lib/kuva/authorizer.rb, line 10
def initialize
  FlickRaw.api_key       = Kuva.api_key
  FlickRaw.shared_secret = Kuva.shared_secret
end

Public Instance Methods

authorize() click to toggle source
# File lib/kuva/authorizer.rb, line 15
def authorize
  puts I18n.t("kuva.authentication.url", url: authentication_url)
  puts I18n.t("kuva.authentication.code")

  begin
    flickr.get_access_token oauth_token, oauth_token_secret, authorization_code
    puts I18n.t("kuva.authentication.success", account: flickr.test.login.username, api_key: Kuva.api_key, shared_secret: Kuva.shared_secret, access_token: flickr.access_token, access_secret: flickr.access_secret)
  rescue FlickRaw::OAuthClient::FailedResponse => error
    puts I18n.t("kuva.authentication.error", message: error)
  end
end

Private Instance Methods

authentication_url() click to toggle source
# File lib/kuva/authorizer.rb, line 33
def authentication_url
  flickr.get_authorize_url oauth_token, perms: "read"
end
authorization_code() click to toggle source
# File lib/kuva/authorizer.rb, line 29
def authorization_code
  STDIN.gets.strip
end
oauth_token() click to toggle source
# File lib/kuva/authorizer.rb, line 37
def oauth_token
  token["oauth_token"]
end
oauth_token_secret() click to toggle source
# File lib/kuva/authorizer.rb, line 41
def oauth_token_secret
  token["oauth_token_secret"]
end
token() click to toggle source
# File lib/kuva/authorizer.rb, line 45
def token
  @token ||= flickr.get_request_token
end