Class: FlickrInvocation

Inherits:
Object
  • Object
show all
Defined in:
lib/objectiveflickr/flickr_invocation.rb

Overview

This class plays the major role of the package. Named “FlickrInvocation” to allude to the making of an RPC call.

Constant Summary collapse

SHARED_SECRET =
''
AUTH_ENDPOINT =
'http://flickr.com/services/auth/'
REST_ENDPOINT =
'http://api.flickr.com/services/rest/'
@@default_api_key =
''
@@default_shared_secret =
''
@@default_options =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, shared_secret = nil, options = nil) ⇒ FlickrInvocation

Initializes the instance with the api_key (required) and an optional shared_secret (required only if you need to make authenticated call). Current available option is:

  • :raise_exception_on_error: set this key to true if you want the call method to raise an error if Flickr returns one



35
36
37
38
39
# File 'lib/objectiveflickr/flickr_invocation.rb', line 35

def initialize(api_key = nil, shared_secret = nil, options = nil)
  @api_key = api_key || @@default_api_key
  @shared_secret = shared_secret || @@default_shared_secret
  @options = options || @@default_options    
end

Class Method Details

.default_api_key(k) ⇒ Object

set the default API key



103
104
105
# File 'lib/objectiveflickr/flickr_invocation.rb', line 103

def self.default_api_key(k)
  @@default_api_key=k
end

.default_options(o) ⇒ Object

set the default options, e.g. :raise_exception_on_error=>true



113
114
115
# File 'lib/objectiveflickr/flickr_invocation.rb', line 113

def self.default_options(o)
  @@default_options = o
end

.default_shared_secret(s) ⇒ Object

set the default shared secret



108
109
110
# File 'lib/objectiveflickr/flickr_invocation.rb', line 108

def self.default_shared_secret(s)
  @@default_shared_secret=s
end

Instance Method Details

#call(method, params = nil) ⇒ Object

Invoke a Flickr method, pass :auth=>true in the param hash if you want the method call to be signed (required when you make authenticaed calls, e.g. flickr.auth.getFrob or any method call that requires an auth token)

NOTE: If you supply :auth_token in the params hash, your API call will automatically be signed, and the call will be treated by Flickr as an authenticated call



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/objectiveflickr/flickr_invocation.rb', line 49

def call(method, params=nil)
  if params && params[:post]
    rsp = FlickrResponse.new Net::HTTP.post_form(URI.parse(REST_ENDPOINT), post_params(method, params)).body
  else
    url = method_url(method, params)
    rsp = FlickrResponse.new Net::HTTP.get(URI.parse(url))
  end
  
  if @options[:raise_exception_on_error] && rsp.error?
    raise RuntimeError, rsp
  end
  
  rsp
end

#login_url(permission, frob = nil) ⇒ Object

Returns a login URL to which you can redirect user’s browser to complete the Flickr authentication process (Flickr then uses the callback address you’ve set previously to pass the authentication frob back to your web app)

New in 0.9.5: frob parameter for desktop applications www.flickr.com/services/api/auth.howto.desktop.html



71
72
73
74
75
76
77
78
79
80
# File 'lib/objectiveflickr/flickr_invocation.rb', line 71

def (permission, frob=nil)
  if frob
    sig = api_sig(:api_key => @api_key, :perms => permission.to_s, :frob=> frob)
    url = "#{AUTH_ENDPOINT}?api_key=#{@api_key}&perms=#{permission}&frob=#{frob}&api_sig=#{sig}"
  else
    sig = api_sig(:api_key => @api_key, :perms => permission.to_s)
    url = "#{AUTH_ENDPOINT}?api_key=#{@api_key}&perms=#{permission}&api_sig=#{sig}"
  end
  url
end

#photo_div_id(params, prefix = 'photo') ⇒ Object

DEPRECATED–Use FlickrPhoto.unique_id_from_hash(params, prefix)



88
89
90
# File 'lib/objectiveflickr/flickr_invocation.rb', line 88

def photo_div_id(params, prefix='photo')
  FlickrPhoto.unique_id_from_hash(params, prefix)
end

#photo_info_from_div_id(uid) ⇒ Object

DEPRECATED–Use FlickrPhoto.hash_from_unique_id(uid)



98
99
100
# File 'lib/objectiveflickr/flickr_invocation.rb', line 98

def photo_info_from_div_id(uid)
  FlickrPhoto.hash_from_unique_id(uid)
end

#photo_url(params) ⇒ Object

DEPRECATED–Use FlickrPhoto.url_from_hash(params)



83
84
85
# File 'lib/objectiveflickr/flickr_invocation.rb', line 83

def photo_url(params)
  FlickrPhoto.url_from_hash(params)
end

#photo_url_from_div_id(uid) ⇒ Object

DEPRECATED–Use FlickrPhoto.url_from_unique_id(uid)



93
94
95
# File 'lib/objectiveflickr/flickr_invocation.rb', line 93

def photo_url_from_div_id(uid)
  FlickrPhoto.url_from_unique_id(uid)
end