Class: Net::Flickr::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/net/flickr/auth.rb

Overview

Implements the Flickr authentication API. Please see flickr.com/services/api/auth.spec.html for details on how to use this API in your application.

Don’t instantiate this class yourself. Instead, create an instance of the Flickr class and then user Flickr.auth to access this class, like so:

require 'net/flickr'

flickr = Net::Flickr.new('524266cbd9d3c2xa2679fee8b337fip2',
    '835hae5d6j0sd47a')

puts flickr.auth.url_desktop

Constant Summary collapse

PERM_NONE =
:none
PERM_READ =
:read
PERM_WRITE =
:write
PERM_DELETE =
:delete

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flickr) ⇒ Auth

Returns a new instance of Auth.



54
55
56
57
58
59
60
61
62
63
# File 'lib/net/flickr/auth.rb', line 54

def initialize(flickr)
  @flickr = flickr

  @frob          = nil
  @perms         = PERM_NONE
  @token         = nil
  @user_id       = nil
  @user_name     = nil
  @user_fullname = nil
end

Instance Attribute Details

#frobObject (readonly)

Returns the value of attribute frob.



52
53
54
# File 'lib/net/flickr/auth.rb', line 52

def frob
  @frob
end

#permsObject (readonly)

Returns the value of attribute perms.



52
53
54
# File 'lib/net/flickr/auth.rb', line 52

def perms
  @perms
end

#tokenObject (readonly)

Returns the value of attribute token.



52
53
54
# File 'lib/net/flickr/auth.rb', line 52

def token
  @token
end

#user_fullnameObject (readonly)

Returns the value of attribute user_fullname.



52
53
54
# File 'lib/net/flickr/auth.rb', line 52

def user_fullname
  @user_fullname
end

#user_idObject (readonly)

Returns the value of attribute user_id.



52
53
54
# File 'lib/net/flickr/auth.rb', line 52

def user_id
  @user_id
end

#user_nameObject (readonly)

Returns the value of attribute user_name.



52
53
54
# File 'lib/net/flickr/auth.rb', line 52

def user_name
  @user_name
end

Instance Method Details

#check_token(token = @token) ⇒ Object

Updates this Auth object with the credentials attached to the specified authentication token. If the token is not valid, an APIError will be raised.



72
73
74
75
76
# File 'lib/net/flickr/auth.rb', line 72

def check_token(token = @token)
  update_auth(@flickr.request('flickr.auth.checkToken',
      'auth_token' => token))
  return true
end

#full_token(mini_token) ⇒ Object

Gets the full authentication token for the specified mini_token.



79
80
81
82
83
# File 'lib/net/flickr/auth.rb', line 79

def full_token(mini_token)
  update_auth(@flickr.request('flickr.auth.getFullToken',
      'mini_token' => mini_token))
  return @token
end

#get_frobObject

Gets a frob to be used during authentication.



86
87
88
89
# File 'lib/net/flickr/auth.rb', line 86

def get_frob
  response = @flickr.request('flickr.auth.getFrob').at('frob')
  return @frob = response.inner_text
end

#get_token(frob = @frob) ⇒ Object

Updates this Auth object with the credentials for the specified frob and returns an auth token. If the frob is not valid, an APIError will be raised.



94
95
96
97
# File 'lib/net/flickr/auth.rb', line 94

def get_token(frob = @frob)
  update_auth(@flickr.request('flickr.auth.getToken', 'frob' => frob))
  return @token
end

#url_desktop(perms) ⇒ Object

Gets a signed URL that can by used by a desktop application to show the user a Flickr authentication screen. Once the user has visited this URL and authorized your application, you can call get_token to authenticate.



102
103
104
105
106
107
108
# File 'lib/net/flickr/auth.rb', line 102

def url_desktop(perms)
  get_frob if @frob.nil?
  url = Flickr::AUTH_URL +
      "?api_key=#{@flickr.api_key}&perms=#{perms}&frob=#{@frob}"
  
  return @flickr.sign_url(url)
end

#url_webapp(perms) ⇒ Object

Gets a signed URL that can be used by a web application to show the user a Flickr authentication screen. Once the user has visited this URL and authorized your application, you can call get_token with the frob provided by Flickr to authenticate.



114
115
116
117
# File 'lib/net/flickr/auth.rb', line 114

def url_webapp(perms)
  return @flickr.sign_url(Flickr::AUTH_URL +
      "?api_key=#{@flickr.api_key}&perms=#{perms}")
end