From d91e816eddf9f91cda0001822f354577dee1e70a Mon Sep 17 00:00:00 2001 From: Philippe Bernard Date: Mon, 6 Mar 2017 14:46:20 +0100 Subject: [PATCH 1/6] Typos in entity sample code --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 05945ad..646d6bb 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ client.text_request 'call Mozart', entities: [ ] } ] - + ``` Or with separate **create_user_entities_request** object with full CRUD support: @@ -102,11 +102,11 @@ entries_unknown = [ ApiAiRuby::Entry.new('Jane Doe', %w(Jane)) ] -entity_contacts = ApiAiRuby::Entity.new('contacts', [entries_composers]) +entity_contacts = ApiAiRuby::Entity.new('contacts', entries_composers) # let's go uer = client.create_user_entities_request -uer.create(contacts) # or uer.create([entity1, entity2...]) +uer.create(entity_contacts) # or uer.create([entity1, entity2...]) client.text_request 'call Mozart' # will work @@ -117,7 +117,7 @@ client.text_request 'call John' # will work uer.retrieve('contacts') # will return current state of user entity uer.delete('contacts') # will remove user entities for given session - + ``` ## Context Also SDK has full support of [contexts](https://docs.api.ai/docs/contexts) API.AI endpoint with special object, called ```contexts_request``` @@ -131,7 +131,7 @@ parameters = { } name = 'test_context' -# you can create context using built-in model ApiAiRuby::Context +# you can create context using built-in model ApiAiRuby::Context test_context = ApiAiRuby::Context.new(name, lifespan, parameters) another_test_context = ApiAiRuby::Context.new('another_test_context') one_more_test_context = ApiAiRuby::Context.new('one_more_test_context', 4) @@ -179,7 +179,7 @@ Please see the [httprb wiki on timeouts](https://github.com/httprb/http/wiki/Tim ###Breaking: - http gem dependency updated to 2.0, it does no longer raise `Errno::ETIMEDOUT`. Thanks to @tak1n -##1.3.0 +##1.3.0 ###Non-breaking: - contexts endpoint support (https://docs.api.ai/docs/contexts) @@ -194,6 +194,6 @@ Please see the [httprb wiki on timeouts](https://github.com/httprb/http/wiki/Tim * 1.2.2 - added configurable timeouts for requests (thanks [bramski](https://github.com/bramski)) * 1.2.1 - fixed UTF-8 in text-requests * 1.2.0 - added configurable session_id and full userEntities support -* 1.1.4 - removed unused dependency and updated default API version +* 1.1.4 - removed unused dependency and updated default API version * 1.1.3 - fixed non-correctly serialized parameters in new contexts during query send process * 1.1.2 - fixed compatibility with ruby version less then 2.1.6 From 0208242b4e54813a70a780d2789f39b852bfe0be Mon Sep 17 00:00:00 2001 From: Philippe Bernard Date: Mon, 6 Mar 2017 14:58:27 +0100 Subject: [PATCH 2/6] create_entities_request added --- lib/api-ai-ruby/client.rb | 9 +++++++-- lib/api-ai-ruby/crud/user_entity_request.rb | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/api-ai-ruby/client.rb b/lib/api-ai-ruby/client.rb index 1d475bf..473745f 100644 --- a/lib/api-ai-ruby/client.rb +++ b/lib/api-ai-ruby/client.rb @@ -89,7 +89,12 @@ def voice_request(file_stream, options = {}) # @return [ApiAiRuby::UserEntitiesRequest] def create_user_entities_request - ApiAiRuby::UserEntitiesRequest.new(self); + ApiAiRuby::UserEntitiesRequest.new(self) + end + + # @return [ApiAiRuby::UserEntitiesRequest] + def create_entities_request + ApiAiRuby::UserEntitiesRequest.new(self, {uriPath: 'entities'}) end # @return [ApiAiRuby::ContextsRequest] @@ -98,4 +103,4 @@ def create_contexts_request end end -end \ No newline at end of file +end diff --git a/lib/api-ai-ruby/crud/user_entity_request.rb b/lib/api-ai-ruby/crud/user_entity_request.rb index c4d1b9b..f168baa 100644 --- a/lib/api-ai-ruby/crud/user_entity_request.rb +++ b/lib/api-ai-ruby/crud/user_entity_request.rb @@ -4,7 +4,8 @@ class UserEntitiesRequest < ApiAiRuby::RequestQuery def initialize(client, options = {}) super client, options @headers['Content-Type'] = 'application/json; charset=UTF-8' - @crud_base_uri = client.api_base_url + 'userEntities' + @crud_base_uri = client.api_base_url + + (options[:uriPath] ? options[:uriPath] : 'userEntities') @uri = @crud_base_uri end @@ -54,4 +55,4 @@ def delete(name) end end -end \ No newline at end of file +end From 7c7359693e2583c68d098a25a6ceec8d39bcdc54 Mon Sep 17 00:00:00 2001 From: Philippe Bernard Date: Mon, 6 Mar 2017 16:26:57 +0100 Subject: [PATCH 3/6] Change option name from uriPath to uri_path --- lib/api-ai-ruby/client.rb | 2 +- lib/api-ai-ruby/crud/user_entity_request.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/api-ai-ruby/client.rb b/lib/api-ai-ruby/client.rb index 473745f..7c9b786 100644 --- a/lib/api-ai-ruby/client.rb +++ b/lib/api-ai-ruby/client.rb @@ -94,7 +94,7 @@ def create_user_entities_request # @return [ApiAiRuby::UserEntitiesRequest] def create_entities_request - ApiAiRuby::UserEntitiesRequest.new(self, {uriPath: 'entities'}) + ApiAiRuby::UserEntitiesRequest.new(self, {uri_path: 'entities'}) end # @return [ApiAiRuby::ContextsRequest] diff --git a/lib/api-ai-ruby/crud/user_entity_request.rb b/lib/api-ai-ruby/crud/user_entity_request.rb index f168baa..8823d18 100644 --- a/lib/api-ai-ruby/crud/user_entity_request.rb +++ b/lib/api-ai-ruby/crud/user_entity_request.rb @@ -5,8 +5,7 @@ def initialize(client, options = {}) super client, options @headers['Content-Type'] = 'application/json; charset=UTF-8' @crud_base_uri = client.api_base_url + - (options[:uriPath] ? options[:uriPath] : 'userEntities') - @uri = @crud_base_uri + (options[:uri_path] ? options[:uri_path] : 'userEntities') end # @param argument [Array, ApiAiRuby::Entity, Hash] From bfaffd5c01bcc4abff837589872561aa607f6b23 Mon Sep 17 00:00:00 2001 From: Philippe Bernard Date: Mon, 6 Mar 2017 16:27:22 +0100 Subject: [PATCH 4/6] Add entries without updating the entity itself --- lib/api-ai-ruby/crud/user_entity_request.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/api-ai-ruby/crud/user_entity_request.rb b/lib/api-ai-ruby/crud/user_entity_request.rb index 8823d18..df24443 100644 --- a/lib/api-ai-ruby/crud/user_entity_request.rb +++ b/lib/api-ai-ruby/crud/user_entity_request.rb @@ -46,6 +46,20 @@ def update(name, entries, extend = false) response end + def add_entries(name, entries) + raise ApiAiRuby::ClientError.new('Entity name required') if !name + + @options = entries + + @request_method = :post + @uri = @crud_base_uri + '/' + name + '/entries' + response = self.perform + @options.delete(:extend) + @options.delete(:name) + @options.delete(:entries) + response + end + def delete(name) raise ApiAiRuby::ClientError.new('Entity name required') if !name @request_method = :delete From 39be6a45f515067f8015dc1953c5050230da329c Mon Sep 17 00:00:00 2001 From: Philippe Bernard Date: Tue, 7 Mar 2017 08:56:24 +0100 Subject: [PATCH 5/6] Fix: create entity with ApiAiRuby::Entity --- lib/api-ai-ruby/crud/user_entity_request.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/api-ai-ruby/crud/user_entity_request.rb b/lib/api-ai-ruby/crud/user_entity_request.rb index df24443..051787d 100644 --- a/lib/api-ai-ruby/crud/user_entity_request.rb +++ b/lib/api-ai-ruby/crud/user_entity_request.rb @@ -16,9 +16,23 @@ def create(argument) end @uri = @crud_base_uri @request_method = :post - @options[:entities] = argument.is_a?(Array) ? argument : [argument] - response = self.perform - @options.delete(:entities) + + old_options = nil + + begin + if argument.is_a?(ApiAiRuby::Entity) + old_options = @options + @options = argument + else + @options[:entities] = argument.is_a?(Array) ? argument : [argument] + end + + response = self.perform + + @options.delete(:entities) if @options.respond_to? :delete + rescue + @options = old_options || @options + end response end From f0edd01f9476715f742ba137c2db6b418745ebb4 Mon Sep 17 00:00:00 2001 From: Philippe Bernard Date: Tue, 7 Mar 2017 08:57:01 +0100 Subject: [PATCH 6/6] ApiAiRuby::UserEntitiesRequest::update_entries --- lib/api-ai-ruby/crud/user_entity_request.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/api-ai-ruby/crud/user_entity_request.rb b/lib/api-ai-ruby/crud/user_entity_request.rb index 051787d..6464dc0 100644 --- a/lib/api-ai-ruby/crud/user_entity_request.rb +++ b/lib/api-ai-ruby/crud/user_entity_request.rb @@ -60,6 +60,21 @@ def update(name, entries, extend = false) response end + def update_entries(name, entries) + + raise ApiAiRuby::ClientError.new('Entity name required') if !name + + @options = entries + + @request_method = :put + @uri = @crud_base_uri + '/' + name + '/entries' + response = self.perform + @options.delete(:extend) + @options.delete(:name) + @options.delete(:entries) + response + end + def add_entries(name, entries) raise ApiAiRuby::ClientError.new('Entity name required') if !name