Class: Watsbot::Response::Parser
- Inherits:
-
Object
- Object
- Watsbot::Response::Parser
- Defined in:
- lib/watsbot/response/parser.rb
Instance Method Summary collapse
-
#initialize(response) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
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
#parse ⇒ Object
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. = 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 |