Module: ApiAi

Defined in:
lib/api_ai/error.rb,
lib/api-ai.rb,
lib/api_ai/client.rb,
lib/api_ai/request.rb,
lib/api_ai/session.rb,
lib/api_ai/version.rb,
lib/api_ai/endpoint.rb,
lib/api_ai/endpoint/tts.rb,
lib/api_ai/endpoint/query.rb,
lib/api_ai/endpoint/intents.rb,
lib/api_ai/endpoint/entities.rb

Overview

Copyright (c) 2015 Gustavo Bazan MIT License

Defined Under Namespace

Modules: Endpoint, Request Classes: AuthError, Client, Error, Session

Constant Summary collapse

WEB_SERVER =

api.ai url

'api.ai'
API_SERVER =

api.ai api path

'api.api.ai'
API_VERSION =
'20150520'
VERSION =
'0.0.1'.freeze

Class Method Summary collapse

Class Method Details

.parse_response(response, raw = false) ⇒ Object

Parse response. You probably shouldn't be calling this directly. This takes responses from the server and parses them. It also checks for errors and raises exceptions with the appropriate messages.

Parameters:

  • response (Net::HTTPResponse)
  • raw (Boolean) (defaults to: false)

    if return raw data

Raises:



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/api-ai.rb', line 29

def self.parse_response(response, raw = false)
  if response.is_a?(Net::HTTPServerError)
    fail ApiAi::Error.new("api.ai Server Error: #{response} - #{response.body}", response)
  end
  return response.body if raw
  begin
    return JSON.parse(response.body)
  rescue JSON::ParserError
    raise ApiAi::Error.new("Unable to parse JSON response: #{response.body}", response)
  end
end