Class: Flickr::Auth

Inherits:
Base show all
Defined in:
lib/flickr/auth.rb

Constant Summary

Constants inherited from Base

Base::AUTH_ENDPOINT, Base::REST_ENDPOINT

Instance Attribute Summary

Attributes inherited from Base

#api_key, #api_secret, #token_cache

Instance Method Summary collapse

Methods inherited from Base

#auth, #photos, #send_request, #sign_request

Constructor Details

#initialize(flickr) ⇒ Auth

Returns a new instance of Auth.



2
3
4
# File 'lib/flickr/auth.rb', line 2

def initialize(flickr)
  @flickr = flickr
end

Instance Method Details

#cache_token(filename = @flickr.token_cache) ⇒ Object

saves the current token to the cache file if token exists

Param

  • filename (Optional)

    filename of the cache file. defaults to the file passed into Flickr.new
    


42
43
44
45
46
47
48
49
50
51
# File 'lib/flickr/auth.rb', line 42

def cache_token(filename = @flickr.token_cache)
  if filename and self.token
    cache_file = File.open(filename, 'w+')
    cache_file.print self.token
    cache_file.close
    true
  else
    false
  end
end

#frobObject

get or return a frob to use for authentication



7
8
9
# File 'lib/flickr/auth.rb', line 7

def frob
  @frob ||= get_frob
end

#token(pass_through = true) ⇒ Object

gets the token for the current frob

Params

  • pass_through (Optional)

    Boolean value that determines if a call will be made to flickr to find a taken for the current frob if empty
    


32
33
34
# File 'lib/flickr/auth.rb', line 32

def token(pass_through = true)
  @token ||= get_token(pass_through) rescue nil
end

#url(perms = :read) ⇒ Object

generates the authorization url to allow access to a flickr account.

Params

  • perms (Optional)

    sets the permision level to grant on the flickr account.
      :read - permission to read private information (DEFAULT)
      :write - permission to add, edit and delete photo metadata (includes 'read')
      :delete - permission to delete photos (includes 'write' and 'read')
    


20
21
22
23
24
# File 'lib/flickr/auth.rb', line 20

def url(perms = :read)
  options = {:api_key => @flickr.api_key, :perms => perms, :frob => self.frob}
  @flickr.sign_request(options)
  Flickr::Base::AUTH_ENDPOINT + "?" + options.collect{|k,v| "#{k}=#{v}"}.join('&')
end