Class: Vng::Request Private

Inherits:
Object
  • Object
show all
Defined in:
lib/vng/http_request.rb,
lib/vng/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:

List the species of all breeds.

host = ''subdomain.vonigo.com'
path = '/api/v1/resources/breeds/'
body = {securityToken: security_token}
response = Vng::Request.new(path: path, body: body).run
response['Breeds'].map{|breed| breed['species']}

Constant Summary collapse

AVAILABLE_ROUTE_ID =

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

1630
@@logged_out =

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

false

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

  • :host (String)

    The host of the request URI.

  • :path (String)

    The path of the request URI.

  • :query (Hash) — default: {}

    The params to use as the query component of the request URI, for instance the Hash {a: 1, b: 2} corresponds to the query parameters “a=1&b=2”.

  • :body (Hash)

    The body of the request.



27
28
29
30
31
32
# File 'lib/vng/http_request.rb', line 27

def initialize(options = {})
  @host = options[:host]
  @path = options[:path]
  @body = options[:body]
  @query = options.fetch :query, {}
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:



38
39
40
41
42
43
# File 'lib/vng/http_request.rb', line 38

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