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



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

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



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

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



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

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

.default_shared_secret(s) ⇒ Object

set the default shared secret



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

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



48
49
50
51
52
53
54
55
56
57
# File 'lib/objectiveflickr/flickr_invocation.rb', line 48

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

#login_url(permission) ⇒ 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)



63
64
65
66
# File 'lib/objectiveflickr/flickr_invocation.rb', line 63

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

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

DEPRECATED–Use FlickrPhoto.unique_id_from_hash(params, prefix)



74
75
76
# File 'lib/objectiveflickr/flickr_invocation.rb', line 74

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)



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

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)



69
70
71
# File 'lib/objectiveflickr/flickr_invocation.rb', line 69

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)



79
80
81
# File 'lib/objectiveflickr/flickr_invocation.rb', line 79

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