Class: Fleakr::Api::MethodRequest

Inherits:
Object
  • Object
show all
Includes:
Support::Request
Defined in:
lib/fleakr/api/method_request.rb

Overview

MethodRequest

Handles all API requests that are non-upload related. For upload requests see the UploadRequest class.

Instance Attribute Summary collapse

Attributes included from Support::Request

#parameters

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::Request

#endpoint_uri

Constructor Details

#initialize(method, additional_parameters = {}) ⇒ MethodRequest

Create a new request for the specified API method and pass along any additional parameters. The Flickr API uses namespacing for its methods - this is optional when calling this method.

This must be called after initializing the library with the required API key see (#Fleakr.api_key=)

The additional_parameters is a list of parameters to pass directly to the Flickr API call. The exception to this is the :authenticate? option that will force the call to not be authenticated if it is set to false (The default behavior is to authenticate all calls when we have a token).



40
41
42
43
# File 'lib/fleakr/api/method_request.rb', line 40

def initialize(method, additional_parameters = {})
  super(additional_parameters)
  self.method = method
end

Instance Attribute Details

#methodObject

Returns the value of attribute method.



13
14
15
# File 'lib/fleakr/api/method_request.rb', line 13

def method
  @method
end

Class Method Details

.with_response!(method, additional_parameters = {}) ⇒ Object

Makes a request to the Flickr API and returns a valid Response object. If there are errors on the response it will raise an ApiError exception. See MethodRequest#new for details about the additional parameters

Raises:



19
20
21
22
23
24
25
26
# File 'lib/fleakr/api/method_request.rb', line 19

def self.with_response!(method, additional_parameters = {})
  request = self.new(method, additional_parameters)
  response = request.send
  
  raise(Fleakr::ApiError, "Code: #{response.error.code} - #{response.error.message}") if response.error?

  response
end

Instance Method Details

#endpoint_urlObject



50
51
52
# File 'lib/fleakr/api/method_request.rb', line 50

def endpoint_url
  'http://api.flickr.com/services/rest/'
end

#sendObject

:nodoc:



54
55
56
57
58
59
60
# File 'lib/fleakr/api/method_request.rb', line 54

def send # :nodoc:
  logger.info("Sending request to: #{endpoint_uri}")
  response_xml = Net::HTTP.get(endpoint_uri)
  logger.debug("Response data:\n#{response_xml}")
  
  Response.new(response_xml)
end