module Flickr::OAuth

Interface for authenticating through OAuth.

Example:

request_token = Flickr::OAuth.get_request_token
request_token.authorize_url

# ... user visits the authorize URL, and gets the verifier ...

access_token = request_token.get_access_token(verifier)

access_token.key       # "..."
access_token.secret    # "..."
access_token.user_info # {username: "...", nsid: "...", ...}

Public Instance Methods

get_access_token(oauth_verifier, request_token) click to toggle source

@param oauth_verifier [String] The code provided by Flickr after visiting

the authorize URL.

@param request_token [RequestToken, Array(String, String)]

@return [Flickr::OAuth::AccessToken]

# File lib/flickr/oauth.rb, line 46
def get_access_token(oauth_verifier, request_token)
  params = {oauth_verifier: oauth_verifier}
  response = client(request_token.to_a).get_access_token(params)
  AccessToken.new(response[:oauth_token], response[:oauth_token_secret],
    response.reject { |key, value| [:oauth_token, :oauth_token_secret].include?(key) })
end
get_request_token(params = {}) click to toggle source

@param params [Hash] @option params [String] :callback_url If the user is being authorized

through another web application, this parameter can be used to redirect
the user back to that application.

@return [Flickr::OAuth::RequestToken]

# File lib/flickr/oauth.rb, line 33
def get_request_token(params = {})
  params[:oauth_callback] = params.delete(:callback_url)
  response = client.get_request_token(params)
  RequestToken.new(response[:oauth_token], response[:oauth_token_secret])
end

Private Instance Methods

client(request_token = nil) click to toggle source
# File lib/flickr/oauth.rb, line 118
def client(request_token = nil)
  Flickr::Client::OAuth.new(request_token)
end