Class: Sendowl::Request

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

Constant Summary collapse

DEFAULT_HEADERS =
{
  'Content-Type' => 'application/json; charset=utf8',
  'Accept'       => 'application/json',
  'User-Agent'   => "sendowl-ruby/#{Sendowl::VERSION}"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, method, model, options = {}) ⇒ Request

Returns a new instance of Request.



15
16
17
18
19
20
21
22
# File 'lib/sendowl/request.rb', line 15

def initialize(path, method, model, options={})
  @path       = path
  @method     = method
  @model      = model
  @parameters = options[:params]  || {}
  @query      = options[:query]   || {}
  @headers    = options[:headers] || {}
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



7
8
9
# File 'lib/sendowl/request.rb', line 7

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



7
8
9
# File 'lib/sendowl/request.rb', line 7

def method
  @method
end

#modelObject

Returns the value of attribute model.



7
8
9
# File 'lib/sendowl/request.rb', line 7

def model
  @model
end

#parametersObject

Returns the value of attribute parameters.



7
8
9
# File 'lib/sendowl/request.rb', line 7

def parameters
  @parameters
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/sendowl/request.rb', line 7

def path
  @path
end

#queryObject

Returns the value of attribute query.



7
8
9
# File 'lib/sendowl/request.rb', line 7

def query
  @query
end

Instance Method Details

#callObject



29
30
31
# File 'lib/sendowl/request.rb', line 29

def call
  model.parse run
end

#runObject



24
25
26
27
# File 'lib/sendowl/request.rb', line 24

def run
  response = RestClient::Request.execute request_params
  JSON.parse response.body
end