Class: FlickRaw::Flickr

Inherits:
Request show all
Defined in:
lib/flickraw.rb

Overview

Root class of the flickr api hierarchy.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Request

build_request, flickr_methods, flickr_objects, request_name

Constructor Details

#initializeFlickr

:nodoc:



270
271
272
273
274
275
276
277
278
# File 'lib/flickraw.rb', line 270

def initialize # :nodoc:
  raise "No API key or secret defined !" if FlickRaw.api_key.nil? or FlickRaw.shared_secret.nil?
  @oauth_consumer = OAuth.new(FlickRaw.api_key, FlickRaw.shared_secret)
  @oauth_consumer.proxy = FlickRaw.proxy
  @oauth_consumer.user_agent = USER_AGENT
  
  Flickr.build(call('flickr.reflection.getMethods')) if Flickr.flickr_objects.empty?
  super self
end

Instance Attribute Details

#access_secretObject

Returns the value of attribute access_secret.



266
267
268
# File 'lib/flickraw.rb', line 266

def access_secret
  @access_secret
end

#access_tokenObject

Returns the value of attribute access_token.



266
267
268
# File 'lib/flickraw.rb', line 266

def access_token
  @access_token
end

Class Method Details

.build(methods) ⇒ Object



268
# File 'lib/flickraw.rb', line 268

def self.build(methods); methods.each { |m| build_request m } end

Instance Method Details

#call(req, args = {}, &block) ⇒ Object

This is the central method. It does the actual request to the flickr server.

Raises FailedResponse if the response status is failed.



283
284
285
286
# File 'lib/flickraw.rb', line 283

def call(req, args={}, &block)
  http_response = @oauth_consumer.post_form(REST_PATH, @access_secret, {:oauth_token => @access_token}, build_args(args, req))
  process_response(req, http_response.body)
end

#get_access_token(token, secret, verify) ⇒ Object



294
295
296
297
298
# File 'lib/flickraw.rb', line 294

def get_access_token(token, secret, verify)
  access_token = @oauth_consumer.access_token(FLICKR_OAUTH_ACCESS_TOKEN, secret, :oauth_token => token, :oauth_verifier => verify)
  @access_token, @access_secret = access_token['oauth_token'], access_token['oauth_token_secret']
  access_token
end

#get_request_token(args = {}) ⇒ Object



288
289
290
291
292
# File 'lib/flickraw.rb', line 288

def get_request_token(args = {})
  request_token = @oauth_consumer.request_token(FLICKR_OAUTH_REQUEST_TOKEN)
  authorize_url = @oauth_consumer.authorize_url(FLICKR_OAUTH_AUTHORIZE, args.merge(:oauth_token => request_token['oauth_token']))
  request_token.merge('oauth_authorize_url' => authorize_url)
end

#replace_photo(file, args = {}) ⇒ Object

Use this to replace the photo with :photo_id with the photo in file.

flickr.replace_photo '/path/to/the/photo', :photo_id => id

See www.flickr.com/services/api/replace.api.html for more information on the arguments.



312
# File 'lib/flickraw.rb', line 312

def replace_photo(file, args={}); upload_flickr(REPLACE_PATH, file, args) end

#upload_photo(file, args = {}) ⇒ Object

Use this to upload the photo in file.

flickr.upload_photo '/path/to/the/photo', :title => 'Title', :description => 'This is the description'

See www.flickr.com/services/api/upload.api.html for more information on the arguments.



305
# File 'lib/flickraw.rb', line 305

def upload_photo(file, args={}); upload_flickr(UPLOAD_PATH, file, args) end