Class: Clova::Client
- Inherits:
-
Object
- Object
- Clova::Client
- Defined in:
- lib/clova-speech/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#build_request(raw_request) ⇒ Object
raw_request: the HTTPRequest that is recieved, including headers, body, before deserialization.
- #build_response(raw_request) ⇒ Object
- #configure {|config| ... } ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
Constructor Details
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/clova-speech/client.rb', line 4 def config @config end |
Instance Method Details
#build_request(raw_request) ⇒ Object
raw_request: the HTTPRequest that is recieved, including headers, body, before deserialization
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/clova-speech/client.rb', line 21 def build_request(raw_request) validator = Clova::Validator.new(app_id: config.application_id) validator.validate(raw_request) raw_request.body.rewind #allows for the request to be read a second time request = JSON.parse(raw_request.body.read.to_s, :symbolize_names => true) type = request[:request].fetch(:type) case type when 'IntentRequest' IntentRequest.new(request) when 'EventRequest' EventRequest.new(request) when 'LaunchRequest' LaunchRequest.new(request) when 'SessionEndedRequest' SessionEndedRequest.new(request) else raise "Request Invalid (no matching type)" end end |
#build_response(raw_request) ⇒ Object
14 15 16 17 18 |
# File 'lib/clova-speech/client.rb', line 14 def build_response(raw_request) request = self.build_request(raw_request) skill = config.skill_class.new(request) skill.call end |
#configure {|config| ... } ⇒ Object
10 11 12 |
# File 'lib/clova-speech/client.rb', line 10 def configure yield(config) end |