Class: Flickr::Auth

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

Defined Under Namespace

Classes: Token

Constant Summary

Constants inherited from Base

Base::AUTH_ENDPOINT, Base::REST_ENDPOINT, Base::UPLOAD_ENDPOINT

Instance Attribute Summary

Attributes inherited from Base

#api_key, #api_secret, #token_cache

Instance Method Summary collapse

Methods inherited from Base

#auth, #contacts, #people, #photos, #photosets, #send_request, #sign_request, #test, #uploader, #urls

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
    


51
52
53
54
55
56
57
58
59
60
# File 'lib/flickr/auth.rb', line 51

def cache_token(filename = @flickr.token_cache)
  if filename and self.token
    cache_file = File.open(filename, 'w+')
    cache_file.puts self.token.to_yaml
    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

#frob=(frob) ⇒ Object

set the frob



12
13
14
# File 'lib/flickr/auth.rb', line 12

def frob= frob
  @frob=frob
end

#token(pass_through = true) ⇒ Object

gets the token object 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
    


41
42
43
# File 'lib/flickr/auth.rb', line 41

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

#url(perms = :read, options = {}) ⇒ 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')
    
  • options (Optional)

    additional parameters to pass to flickr.  The most common use-case for
    this is to pass the (undocumented) :extra parameter that is returned
    back from flickr during the callback.
    


29
30
31
32
33
# File 'lib/flickr/auth.rb', line 29

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