Class: Contacts::Flickr

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

Constant Summary collapse

DOMAIN =
'api.flickr.com'
ServicesPath =
'/services/rest/'

Class Method Summary collapse

Class Method Details

.authentication_url(key, secret) ⇒ Object



32
33
34
35
36
37
# File 'lib/contacts/flickr.rb', line 32

def self.authentication_url(key, secret)
  response = http_start do |flickr|
    flickr.get(frob_url(key, secret))
  end
  authentication_url_for_frob(frob_from_response(response), key, secret)
end

.authentication_url_for_frob(frob, key, secret) ⇒ Object



27
28
29
30
# File 'lib/contacts/flickr.rb', line 27

def self.authentication_url_for_frob(frob, key, secret)
  params = { :api_key => key, :secret => secret, :perms => 'read', :frob => frob }
  'http://www.flickr.com/services/auth/?' + query_string(params)
end

.frob_from_response(response) ⇒ Object



22
23
24
25
# File 'lib/contacts/flickr.rb', line 22

def self.frob_from_response(response)
  doc = Hpricot::XML response.body
  doc.at('frob').inner_text
end

.frob_url(key, secret) ⇒ Object



18
19
20
# File 'lib/contacts/flickr.rb', line 18

def self.frob_url(key, secret)
  url_for(:api_key => key, :secret => secret, :method => 'flickr.auth.getFrob')
end

.get_token_from_frob(key, secret, frob) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/contacts/flickr.rb', line 44

def self.get_token_from_frob(key, secret, frob)
  response = http_start do |flickr|
    flickr.get(token_url(key, secret, frob))
  end
  doc = Hpricot::XML response.body
  doc.at('token').inner_text
end

.token_url(key, secret, frob) ⇒ Object



39
40
41
42
# File 'lib/contacts/flickr.rb', line 39

def self.token_url(key, secret, frob)
  params = { :api_key => key, :secret => secret, :frob => frob, :method => 'flickr.auth.getToken' }
  url_for(params)
end