Class: Mocodo::SentenceUnderstanding
- Inherits:
-
Object
- Object
- Mocodo::SentenceUnderstanding
- Defined in:
- lib/mocodo/sentence_understanding.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #build_body(talk) ⇒ Object
- #configure(options = {}) ⇒ Object
- #get_current_data(option = nil) ⇒ Object
-
#initialize(api_key) ⇒ SentenceUnderstanding
constructor
A new instance of SentenceUnderstanding.
- #sentenceUnderstanding(talk) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ SentenceUnderstanding
Returns a new instance of SentenceUnderstanding.
8 9 10 11 |
# File 'lib/mocodo/sentence_understanding.rb', line 8 def initialize(api_key) @client = Client.new(api_key) self.config = {} end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/mocodo/sentence_understanding.rb', line 6 def config @config end |
Instance Method Details
#build_body(talk) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/mocodo/sentence_understanding.rb', line 27 def build_body(talk) body = {} self.config.each { |sym| body[sym[0].id2name] = sym[1] } body['userUtterance'] = {} body['userUtterance']['utteranceText'] = talk return body.to_json end |
#configure(options = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/mocodo/sentence_understanding.rb', line 13 def configure( = {}) .each do |key, value| self.config[key] = value end end |
#get_current_data(option = nil) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/mocodo/sentence_understanding.rb', line 19 def get_current_data(option=nil) if option.nil? return self.config else return self.config[option] end end |
#sentenceUnderstanding(talk) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mocodo/sentence_understanding.rb', line 37 def sentenceUnderstanding talk uri = URI.parse("https://api.apigw.smt.docomo.ne.jp/sentenceUnderstanding/v1/task?APIKEY=#{@client.get_api_key}") http = Net::HTTP.new('api.apigw.smt.docomo.ne.jp', 443) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/x-www-form-urlencoded'}) request.body = build_body(talk) response = nil http.start do |h| response = JSON.parse(h.request(request).body, symbolize_names: true) end configure(response) return response end |