Class: Watsbot::Response::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/watsbot/response/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
# File 'lib/watsbot/response/parser.rb', line 5

def initialize(response)
  @response = response
  @response_body = JSON.parse(response.body)
end

Instance Method Details

#parseObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/watsbot/response/parser.rb', line 10

def parse
  if @response.code >= 400
    response = Error.new @response.code
    response.message = parse_error_message
    response
  else
    response = Success.new @response.code
    response.intents = @response_body["intents"]
    response.entities = parse_entities
    response.input = @response_body["input"]
    response.output = @response_body["output"]
    response.context = @response_body["context"]
    response
  end
end