Class: Wit::REST::Session
- Inherits:
-
Object
- Object
- Wit::REST::Session
- Defined in:
- lib/wit_ruby/rest/session.rb
Instance Attribute Summary collapse
-
#last_result ⇒ Object
readonly
Able to read cached result from last request.
Instance Method Summary collapse
-
#add_expression(entity_id, value, expression) ⇒ Wit::REST::Result
POST - adds a new expression to the value of the entity.
-
#add_value(new_value_with_entity) ⇒ Wit::REST::Result
POST - adds the possible value into the list of values for the given - entity with the id.
-
#create_entity(new_entity) ⇒ Wit::REST::Result
POST - creates a new entity with the given attributes.
-
#delete_entity(entity_id) ⇒ Wit::REST::Result
DELETE - deletes the given entity with the entity id.
-
#delete_expression(entity_id, value, expression) ⇒ Wit::REST::Result
DELETE - deletes the expression in the value of the entity.
-
#delete_value(entity_name, delete_value) ⇒ Wit::REST::Result
DELETE - deletes the value from the list of values in the entity with - with the given value.
-
#get_entities(entity_id = nil) ⇒ Wit::REST::MultiEntity
GET - returns a list of available entities given this instance with the given token if no id is given.
-
#get_intents(intent_indicator = nil) ⇒ Wit:REST::Intent
GET - returns either a list of intents if no id is given.
-
#get_message(message_id) ⇒ Wit::REST::Message
GET - returns stored message for specific id.
-
#initialize(client) ⇒ Session
constructor
Initialize with the given client.
-
#refresh_last ⇒ Wit::REST::Result
Used to refresh the last result given from the last request.
-
#refresh_results(result) ⇒ Wit::REST::Result
Used to refresh the results from the given results.
-
#send_message(message) ⇒ Wit::REST::Message
GET - extracted meaning from a sentence.
-
#send_sound_message(sound) ⇒ Object
POST - extract meaning from a audio file Do check the certain documentation of what the specific audio file should be.
-
#update_entity(entity_id, update_entity_data) ⇒ Wit::REST::Result
PUT - updates a given entity with the specific entity id and BodyJson data.
Constructor Details
#initialize(client) ⇒ Session
Initialize with the given client.
14 15 16 |
# File 'lib/wit_ruby/rest/session.rb', line 14 def initialize(client) @client = client end |
Instance Attribute Details
#last_result ⇒ Object (readonly)
Able to read cached result from last request.
10 11 12 |
# File 'lib/wit_ruby/rest/session.rb', line 10 def last_result @last_result end |
Instance Method Details
#add_expression(entity_id, value, expression) ⇒ Wit::REST::Result
POST - adds a new expression to the value of the entity.
140 141 142 |
# File 'lib/wit_ruby/rest/session.rb', line 140 def add_expression(entity_id, value, expression) return @client.post("/entities/#{entity_id}/values/#{value}/expressions", "{\"expression\":\"#{expression}\"}") end |
#add_value(new_value_with_entity) ⇒ Wit::REST::Result
notify wit.ai that documentation is off.
POST - adds the possible value into the list of values for the given
- entity with the id.
119 120 121 122 123 124 125 |
# File 'lib/wit_ruby/rest/session.rb', line 119 def add_value(new_value_with_entity) ## Makes sure values exist and has a value and id as well. if new_value_with_entity.id.nil? || new_value_with_entity.one_value_to_json == "null" raise NotCorrectSchema.new("The current BodyJson object passed in does not have either an \"id\" or a \"value\" defined.") end return @client.post("/entities/#{new_value_with_entity.id}/values", new_value_with_entity.one_value_to_json) end |
#create_entity(new_entity) ⇒ Wit::REST::Result
POST - creates a new entity with the given attributes.
85 86 87 88 89 90 91 92 |
# File 'lib/wit_ruby/rest/session.rb', line 85 def create_entity(new_entity) ## Checks to make sure it has an id, if not, raise error. if new_entity.id.nil? raise NotCorrectSchema.new("The current BodyJson object passed in does not have an \"id\" defined.") end return @client.post("/entities", new_entity.json) end |
#delete_entity(entity_id) ⇒ Wit::REST::Result
DELETE - deletes the given entity with the entity id.
109 110 111 |
# File 'lib/wit_ruby/rest/session.rb', line 109 def delete_entity(entity_id) return @client.delete("/entities/#{entity_id}") end |
#delete_expression(entity_id, value, expression) ⇒ Wit::REST::Result
DELETE - deletes the expression in the value of the entity.
150 151 152 |
# File 'lib/wit_ruby/rest/session.rb', line 150 def delete_expression(entity_id, value, expression) return @client.delete("/entities/#{entity_id}/values/#{value}/expressions/#{expression}") end |
#delete_value(entity_name, delete_value) ⇒ Wit::REST::Result
DELETE - deletes the value from the list of values in the entity with
- with the given value.
132 133 134 |
# File 'lib/wit_ruby/rest/session.rb', line 132 def delete_value(entity_name, delete_value) return @client.delete("/entities/#{entity_name}/values/#{delete_value}") end |
#get_entities(entity_id = nil) ⇒ Wit::REST::MultiEntity
notify Wit.ai to fix their documentations as there is a wrong description.
GET - returns a list of available entities given this instance with the
given token if no id is given.
- returns the specific entity and its parameters with a given id.
71 72 73 74 75 76 77 78 79 |
# File 'lib/wit_ruby/rest/session.rb', line 71 def get_entities(entity_id = nil) ## No specific id, so get list of entities results = entity_id.nil? ? @client.get("/entities") : @client.get("/entities/#{entity_id}") ## Same concept but wrap it properly if neccessary. returnObject = entity_id.nil? ? MultiEntity : Entity return return_with_class(returnObject, results) end |
#get_intents(intent_indicator = nil) ⇒ Wit:REST::Intent
GET - returns either a list of intents if no id is given.
- returns the specific intent of the id given.
53 54 55 56 57 58 59 60 61 |
# File 'lib/wit_ruby/rest/session.rb', line 53 def get_intents(intent_indicator = nil) ## No specific id, so get list of intents or specific id, return it as Intent object results = intent_indicator.nil? ? @client.get("/intents") : @client.get("/intents/#{intent_indicator}") ## Same concept but wrap it around proper object returnObject = intent_indicator.nil? ? MultiIntent : Intent return return_with_class(returnObject, results) end |
#get_message(message_id) ⇒ Wit::REST::Message
possibly renaming as it is ambigious compared to send_message.
Notify Wit.ai as there documentation does not include the stats parameter
GET - returns stored message for specific id.
42 43 44 45 46 |
# File 'lib/wit_ruby/rest/session.rb', line 42 def () results = @client.get("/messages/#{}") return return_with_class(Wit::REST::Message, results) end |
#refresh_last ⇒ Wit::REST::Result
Used to refresh the last result given from the last request.
175 176 177 178 |
# File 'lib/wit_ruby/rest/session.rb', line 175 def refresh_last refreshed_last_result = @client.request_from_result(@last_result.restCode, @last_result.restPath, @last_result.restBody) return_with_class(@last_result.class, refreshed_last_result) end |
#refresh_results(result) ⇒ Wit::REST::Result
Used to refresh the results from the given results. Only applicable to result objects that directly came from the session.
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/wit_ruby/rest/session.rb', line 159 def refresh_results(result) ## Call client with refresh results method ## Checks to see if its part of the specified objects in the Wit module ## Checks to see if the object is refreshable ## If it isn't part of one of these two, then raise error for not being refreshable. result_class = result.class unless result_class.name.split("::")[0] == "Wit" && result.refreshable? raise NotRefreshable.new(%(The inputted object with class "#{result.class}" is not refreshable.)) end refreshed_result = @client.request_from_result(result.restCode, result.restPath, result.restBody) return return_with_class(result_class, refreshed_result) end |
#send_message(message) ⇒ Wit::REST::Message
allow for JSON pass in.
GET - extracted meaning from a sentence.
22 23 24 25 26 |
# File 'lib/wit_ruby/rest/session.rb', line 22 def () ## Recieve unwrapped results results = @client.get("/message?q=#{}") return return_with_class(Wit::REST::Message, results) end |
#send_sound_message(sound) ⇒ Object
POST - extract meaning from a audio file Do check the certain documentation of what the specific audio file should be.
33 34 |
# File 'lib/wit_ruby/rest/session.rb', line 33 def (sound) end |
#update_entity(entity_id, update_entity_data) ⇒ Wit::REST::Result
notify Wit.ai to return back the updated entity results.
PUT - updates a given entity with the specific entity id and BodyJson data.
101 102 103 |
# File 'lib/wit_ruby/rest/session.rb', line 101 def update_entity(entity_id, update_entity_data) return @client.put("/entities/#{entity_id}", update_entity_data.json) end |