Class: FlickRaw::Flickr

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

Overview

Root class of the flickr api hierarchy.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Request

build_request, flickr_methods, flickr_objects, request_name

Constructor Details

#initialize(token = ) ⇒ Flickr

:nodoc:



150
151
152
153
154
# File 'lib/flickraw.rb', line 150

def initialize(token = FlickRawOptions['auth_token']) # :nodoc:
  Flickr.build(call('flickr.reflection.getMethods')) if Flickr.flickr_objects.empty?
  super self
  @token = token
end

Class Method Details

.build(methods) ⇒ Object



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

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

Instance Method Details

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

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

Raises FailedResponse if the response status is failed.

Raises:



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/flickraw.rb', line 159

def call(req, args={})
  http_response = open_flickr do |http|
    request = Net::HTTP::Post.new(REST_PATH, 'User-Agent' => "Flickraw/#{VERSION}")
    request.set_form_data(build_args(args, req))
    http.request(request)
  end

  json = JSON.load(http_response.body.empty? ? "{}" : http_response.body)
  raise FailedResponse.new(json['message'], json['code'], req) if json.delete('stat') == 'fail'
  type, json = json.to_a.first if json.size == 1 and json.all? {|k,v| v.is_a? Hash}

  res = Response.build json, type
  @token = res.token if res.respond_to? :flickr_type and res.flickr_type == "auth"
  res
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.



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

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.



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

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