Class: VoxableApiAiRuby::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/voxable-api-ai-ruby/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, options = {}) ⇒ VoxableApiAiRuby::TextRequest

Parameters:

  • client (VoxableApiAiRuby::Client)
  • path (String)

    the path to the proper API endpoint

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


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/voxable-api-ai-ruby/request.rb', line 15

def initialize(client, options = {})
  @client = client
  @uri = client.api_base_url + @path + '?v=' + client.api_version
  @request_method = :post
  options[:params] ||= {}
  options[:params] = options[:params].merge({ lang: client.api_lang })
  @options = options
  @headers = {
      'Authorization': ('Bearer ' + client.client_access_token),
      'Content-Type': 'application/json; charset=utf-8'
  }
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/voxable-api-ai-ruby/request.rb', line 8

def client
  @client
end

#headersObject

Returns the value of attribute headers.



8
9
10
# File 'lib/voxable-api-ai-ruby/request.rb', line 8

def headers
  @headers
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/voxable-api-ai-ruby/request.rb', line 8

def options
  @options
end

#request_methodObject

Returns the value of attribute request_method.



8
9
10
# File 'lib/voxable-api-ai-ruby/request.rb', line 8

def request_method
  @request_method
end

#uriObject

Returns the value of attribute uri.



8
9
10
# File 'lib/voxable-api-ai-ruby/request.rb', line 8

def uri
  @uri
end

Instance Method Details

#performArray, Hash

Returns:

  • (Array, Hash)


29
30
31
32
33
34
35
# File 'lib/voxable-api-ai-ruby/request.rb', line 29

def perform
  response = HTTP.with(@headers).public_send(@request_method, @uri.to_s, @options)

  response_body = symbolize_keys!(response.parse)
  response_headers = response.headers
  fail_or_return_response_body(response.code, response_body)
end