Class: Fleakr::Api::MethodRequest

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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).



37
38
39
40
41
# File 'lib/fleakr/api/method_request.rb', line 37

def initialize(method, additional_parameters = {})
  @parameters = ParameterList.new(additional_parameters)
  
  self.method = method
end

Instance Attribute Details

#methodObject

Returns the value of attribute method.



10
11
12
# File 'lib/fleakr/api/method_request.rb', line 10

def method
  @method
end

#parametersObject (readonly)

Returns the value of attribute parameters.



10
11
12
# File 'lib/fleakr/api/method_request.rb', line 10

def parameters
  @parameters
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:



16
17
18
19
20
21
22
23
# File 'lib/fleakr/api/method_request.rb', line 16

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

#sendObject

:nodoc:



48
49
50
51
52
53
54
# File 'lib/fleakr/api/method_request.rb', line 48

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