Class: Webceo::Api::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/webceo/api/request.rb

Overview

Class Request provides wrapper for the request parameters for the api call to be made It also provides a to_json method to build the JSON format request to be sent as the body for the API call

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, data = {}) ⇒ Request

Initializes a Request instance for use in our Client

Parameters:

  • method_name (String)

    Name of the API Method to invoke

  • data (Hash) (defaults to: {})

    Any arguments required to sent along with the method



19
20
21
22
# File 'lib/webceo/api/request.rb', line 19

def initialize(method_name, data = {})
  @method_name = method_name
  @data = data.with_indifferent_access
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



11
12
13
# File 'lib/webceo/api/request.rb', line 11

def data
  @data
end

#method_nameObject

Returns the value of attribute method_name.



11
12
13
# File 'lib/webceo/api/request.rb', line 11

def method_name
  @method_name
end

Instance Method Details

#to_jsonJSON

This method returns a JSON format of the complete request to be sent to the Webceo API server

It also appends the api_key necessary for the API call to be successfull

Returns:

  • (JSON)

    API Request Hash



33
34
35
36
37
38
39
40
# File 'lib/webceo/api/request.rb', line 33

def to_json
  MultiJson.dump({
    method: @method_name.to_s,
    key: Webceo.configuration.api_key,
    id: @data[:id],
    data: @data
  })
end