Class: Iter::Request Private

Inherits:
Object
  • Object
show all
Defined in:
lib/iter/http_request.rb,
lib/iter/mock_request.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A mock version of HTTPRequest which returns pre-built responses.

Examples:

Updates the email of a user.

path = '/api/users/update'
body = {userId: '666', email: '[email protected]'}
response = Iter::Request.new(path: path, body: body).run
response['msg'] # => User successfully created/updated.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes an MockRequest object.

Parameters:

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

    the options for the request.

Options Hash (options):

  • :path (String)

    The path of the request URI.

  • :body (Hash)

    The body of the request.



22
23
24
25
# File 'lib/iter/http_request.rb', line 22

def initialize(options = {})
  @path = options[:path]
  @body = options[:body]
end

Instance Method Details

#runHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sends the request and returns the body parsed from the JSON response.

Returns:

  • (Hash)

    the body parsed from the JSON response.

Raises:



31
32
33
34
35
36
# File 'lib/iter/http_request.rb', line 31

def run
  return {} if response.body.empty?
  JSON(response.body).tap do |data|
    raise Error, "#{data['errMsg']} #{data['Errors']}" unless data['errNo'].zero?
  end
end