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



30
31
32
33
34
35
# File 'lib/contacts/flickr.rb', line 30

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



25
26
27
28
# File 'lib/contacts/flickr.rb', line 25

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



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

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

.frob_url(key, secret) ⇒ Object



16
17
18
# File 'lib/contacts/flickr.rb', line 16

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



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

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



37
38
39
40
# File 'lib/contacts/flickr.rb', line 37

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