Module: Wit
- Defined in:
- lib/wit/wit.rb,
lib/wit/version.rb
Defined Under Namespace
Classes: BadResponse, Entity, EntityCollection, Result, Unauthorized
Constant Summary collapse
- VERSION =
'0.0.2'
Class Attribute Summary collapse
-
.token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Class Attribute Details
.token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/wit/wit.rb', line 8 def token @token end |
Class Method Details
.connection ⇒ Object
28 29 30 31 32 |
# File 'lib/wit/wit.rb', line 28 def self.connection @connection ||= Faraday.new url: 'https://api.wit.ai' do |faraday| faraday.adapter Faraday.default_adapter end end |
.message(message = '') ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wit/wit.rb', line 15 def self.( = '') response = connection.get do |req| req.headers['Authorization'] = "Bearer #{token}" req.url '/message', q: end case response.status when 200 then return Result.new JSON.parse(response.body) when 401 then raise Unauthorized, "incorrect token set for Wit.token set an env for WIT_TOKEN or set Wit::TOKEN manually" else raise BadResponse, "response code: #{response.status}" end end |