api-ai-ruby 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 23133323a1d44a623c85d017620cae32a44e9ff2
4
- data.tar.gz: 50614d55d052aef546b5aabcb94c51e95b01ad3e
2
+ SHA256:
3
+ metadata.gz: 6ec8e00ec1d07a6c2271409f31628818773117741902d989484cfa4e61764af9
4
+ data.tar.gz: 43c83533d9479a782d56a50c4f4e4323c367ca7409a15c1765972ee55eb8dc88
5
5
  SHA512:
6
- metadata.gz: 7b605200b1e15ae56ee73fe4052f47eeba29704da9f96945547f1782608fdb5fe93a3af9076e20d68bd491a56958e297c04ce0c4eb3de1ea85fe28e50aa378d9
7
- data.tar.gz: 211cd510f08369b79d85bbf8bf0bb6c56e5a39310b2678844b931c36e874c84e51a1ca29eb41c0d1ad3d5a69f5484ea65898ef34b2f7b524c5f5da8e68792853
6
+ metadata.gz: 76b667a4e39af32b9ef5b1f7ef7b58d15acf2c7551073388e785908b94dd1402e1a4352a535811bd25707afb3d8f4e5cf37cd7c3c03155c79a280d142f4d1f9d
7
+ data.tar.gz: 923988dccb32dab43db2753bc10c592bfad156f239a6570c88a2e5af5c3d58230ad3253b705d95fe08213e5c7b398c88807aa710ecf198c46af9488246eeda8c
data/README.md CHANGED
@@ -32,7 +32,7 @@ response_two = client.event_request 'MY_EVENT_WITH_DATA_TO_STORE', {:some_param
32
32
 
33
33
  ```
34
34
 
35
- **voice_request** and **text_request** methods returns symbolized https://api.ai response. Structure of response can be found at https://docs.api.ai/docs/query#response.
35
+ **text_request** method returns symbolized https://api.ai response. Structure of response can be found at https://docs.api.ai/docs/query#response.
36
36
 
37
37
  ## Advanced usage
38
38
 
@@ -48,11 +48,10 @@ ApiAiRuby::Client.new(
48
48
  )
49
49
  ```
50
50
 
51
- And you also can send additional data to server during request, use second parameter of **text_request** and **voice_request** methods to do that
51
+ And you also can send additional data to server during request, use second parameter of **text_request** method to do that
52
52
 
53
53
  ```ruby
54
54
  response = client.text_request 'Hello', :contexts => ['firstContext'], :resetContexts => true
55
- response = client.voice_request file, :timezone => 'America/New_York'
56
55
  ```
57
56
 
58
57
  More information about possible parameters can be found at https://docs.api.ai/docs/query page
@@ -84,7 +83,7 @@ client.text_request 'call Mozart', entities: [
84
83
  ]
85
84
  }
86
85
  ]
87
-
86
+
88
87
  ```
89
88
 
90
89
  Or with separate **create_user_entities_request** object with full CRUD support:
@@ -102,11 +101,11 @@ entries_unknown = [
102
101
  ApiAiRuby::Entry.new('Jane Doe', %w(Jane))
103
102
  ]
104
103
 
105
- entity_contacts = ApiAiRuby::Entity.new('contacts', [entries_composers])
104
+ entity_contacts = ApiAiRuby::Entity.new('contacts', entries_composers)
106
105
 
107
106
  # let's go
108
107
  uer = client.create_user_entities_request
109
- uer.create(contacts) # or uer.create([entity1, entity2...])
108
+ uer.create(entity_contacts) # or uer.create([entity1, entity2...])
110
109
 
111
110
  client.text_request 'call Mozart' # will work
112
111
 
@@ -117,7 +116,7 @@ client.text_request 'call John' # will work
117
116
 
118
117
  uer.retrieve('contacts') # will return current state of user entity
119
118
  uer.delete('contacts') # will remove user entities for given session
120
-
119
+
121
120
  ```
122
121
  ## Context
123
122
  Also SDK has full support of [contexts](https://docs.api.ai/docs/contexts) API.AI endpoint with special object, called ```contexts_request```
@@ -131,7 +130,7 @@ parameters = {
131
130
  }
132
131
  name = 'test_context'
133
132
 
134
- # you can create context using built-in model ApiAiRuby::Context
133
+ # you can create context using built-in model ApiAiRuby::Context
135
134
  test_context = ApiAiRuby::Context.new(name, lifespan, parameters)
136
135
  another_test_context = ApiAiRuby::Context.new('another_test_context')
137
136
  one_more_test_context = ApiAiRuby::Context.new('one_more_test_context', 4)
@@ -153,7 +152,7 @@ context_request.delete() # will remove all context in session
153
152
 
154
153
  ```
155
154
 
156
- #Timeouts
155
+ # Timeouts
157
156
  **ApiAiRuby::Client** uses the [http gem](https://github.com/httprb/http) under the hood. You can use ```timeout_options``` on the client to set these.
158
157
  ```ruby
159
158
  ApiAiRuby::Client.new(
@@ -169,31 +168,35 @@ ApiAiRuby::Client.new(
169
168
  Please see the [httprb wiki on timeouts](https://github.com/httprb/http/wiki/Timeouts) for more information.
170
169
 
171
170
 
172
- #Error handling
171
+ # Error handling
173
172
  **ApiAiRuby::Client** currently able to raise two kind of errors: **ApiAiRuby::ClientError** (due to configuration mismatch) and **ApiAiRuby::RequestError** in case of something goes wrong during request. For both kind of errors you can get **error.message** (as usual) and **ApiAiRuby::RequestError** can additionally give you code of server error (you can get it with **error.code**)
174
173
 
175
174
 
176
- #Changelog
175
+ # Changelog
176
+
177
+ ## 2.1.0
178
+ ### Breaking:
179
+ - voice request removed
177
180
 
178
- ##2.0.0
179
- ###Breaking:
181
+ ## 2.0.0
182
+ ### Breaking:
180
183
  - http gem dependency updated to 2.0, it does no longer raise `Errno::ETIMEDOUT`. Thanks to @tak1n
181
184
 
182
- ##1.3.0
185
+ ## 1.3.0
183
186
 
184
- ###Non-breaking:
187
+ ### Non-breaking:
185
188
  - contexts endpoint support (https://docs.api.ai/docs/contexts)
186
189
  - better RDoc
187
190
 
188
- ###Breaking:
191
+ ### Breaking:
189
192
  - ApiAiRuby::Client::user_entities_request renamed to ApiAiRuby::Client::create_user_entities_request
190
193
  - ApiAiRuby::Entity::addEntry renamed to ApiAiRuby::Entity::add_entry
191
194
 
192
- ##Previous
195
+ ## Previous
193
196
  * 1.2.3 - events support
194
197
  * 1.2.2 - added configurable timeouts for requests (thanks [bramski](https://github.com/bramski))
195
198
  * 1.2.1 - fixed UTF-8 in text-requests
196
199
  * 1.2.0 - added configurable session_id and full userEntities support
197
- * 1.1.4 - removed unused dependency and updated default API version
200
+ * 1.1.4 - removed unused dependency and updated default API version
198
201
  * 1.1.3 - fixed non-correctly serialized parameters in new contexts during query send process
199
202
  * 1.1.2 - fixed compatibility with ruby version less then 2.1.6
@@ -5,7 +5,6 @@ require 'api-ai-ruby/client_error'
5
5
  require 'api-ai-ruby/request/request_query'
6
6
  require 'api-ai-ruby/request/text_request'
7
7
  require 'api-ai-ruby/request/event_request'
8
- require 'api-ai-ruby/request/voice_request'
9
8
  require 'api-ai-ruby/models/context'
10
9
  require 'api-ai-ruby/models/entry'
11
10
  require 'api-ai-ruby/models/entity'
@@ -77,19 +77,14 @@ module ApiAiRuby
77
77
  ApiAiRuby::EventRequest.new(self, options).perform
78
78
  end
79
79
 
80
- # @deprecated
81
- # @param file_stream [File]
82
- # @param options [Object]
83
- # @return [Array, Hash]
84
- def voice_request(file_stream, options = {})
85
- raise ApiAiRuby::ClientError.new('Credentials missing') if !credentials?
86
- options[:file] = file_stream
87
- ApiAiRuby::VoiceRequest.new(self, options).perform
80
+ # @return [ApiAiRuby::UserEntitiesRequest]
81
+ def create_user_entities_request
82
+ ApiAiRuby::UserEntitiesRequest.new(self)
88
83
  end
89
84
 
90
85
  # @return [ApiAiRuby::UserEntitiesRequest]
91
- def create_user_entities_request
92
- ApiAiRuby::UserEntitiesRequest.new(self);
86
+ def create_entities_request
87
+ ApiAiRuby::UserEntitiesRequest.new(self, {uri_path: 'entities'})
93
88
  end
94
89
 
95
90
  # @return [ApiAiRuby::ContextsRequest]
@@ -98,4 +93,4 @@ module ApiAiRuby
98
93
  end
99
94
 
100
95
  end
101
- end
96
+ end
@@ -1,6 +1,6 @@
1
1
  module ApiAiRuby
2
2
  class Constants
3
- VERSION = '2.0.0'
3
+ VERSION = '2.1.0'
4
4
  DEFAULT_BASE_URL = 'https://api.api.ai/v1/'
5
5
  DEFAULT_API_VERSION = '20150910'
6
6
  DEFAULT_CLIENT_LANG = 'en'
@@ -4,8 +4,8 @@ module ApiAiRuby
4
4
  def initialize(client, options = {})
5
5
  super client, options
6
6
  @headers['Content-Type'] = 'application/json; charset=UTF-8'
7
- @crud_base_uri = client.api_base_url + 'userEntities'
8
- @uri = @crud_base_uri
7
+ @crud_base_uri = client.api_base_url +
8
+ (options[:uri_path] ? options[:uri_path] : 'userEntities')
9
9
  end
10
10
 
11
11
  # @param argument [Array<ApiAiRuby::Entity, Hash>, ApiAiRuby::Entity, Hash]
@@ -16,9 +16,23 @@ module ApiAiRuby
16
16
  end
17
17
  @uri = @crud_base_uri
18
18
  @request_method = :post
19
- @options[:entities] = argument.is_a?(Array) ? argument : [argument]
20
- response = self.perform
21
- @options.delete(:entities)
19
+
20
+ old_options = nil
21
+
22
+ begin
23
+ if argument.is_a?(ApiAiRuby::Entity)
24
+ old_options = @options
25
+ @options = argument
26
+ else
27
+ @options[:entities] = argument.is_a?(Array) ? argument : [argument]
28
+ end
29
+
30
+ response = self.perform
31
+
32
+ @options.delete(:entities) if @options.respond_to? :delete
33
+ rescue
34
+ @options = old_options || @options
35
+ end
22
36
  response
23
37
  end
24
38
 
@@ -46,6 +60,35 @@ module ApiAiRuby
46
60
  response
47
61
  end
48
62
 
63
+ def update_entries(name, entries)
64
+
65
+ raise ApiAiRuby::ClientError.new('Entity name required') if !name
66
+
67
+ @options = entries
68
+
69
+ @request_method = :put
70
+ @uri = @crud_base_uri + '/' + name + '/entries'
71
+ response = self.perform
72
+ @options.delete(:extend)
73
+ @options.delete(:name)
74
+ @options.delete(:entries)
75
+ response
76
+ end
77
+
78
+ def add_entries(name, entries)
79
+ raise ApiAiRuby::ClientError.new('Entity name required') if !name
80
+
81
+ @options = entries
82
+
83
+ @request_method = :post
84
+ @uri = @crud_base_uri + '/' + name + '/entries'
85
+ response = self.perform
86
+ @options.delete(:extend)
87
+ @options.delete(:name)
88
+ @options.delete(:entries)
89
+ response
90
+ end
91
+
49
92
  def delete(name)
50
93
  raise ApiAiRuby::ClientError.new('Entity name required') if !name
51
94
  @request_method = :delete
@@ -54,4 +97,4 @@ module ApiAiRuby
54
97
  end
55
98
 
56
99
  end
57
- end
100
+ end
@@ -41,12 +41,6 @@ describe 'api' do
41
41
  expect {client.text_request}.to raise_error(ApiAiRuby::RequestError)
42
42
  end
43
43
 
44
- it 'should send voiceData to API' do
45
- expect(@client.voice_request(File.new(fixture_path + '/hello.wav'))[:result][:resolvedQuery]).to eq 'hello'
46
- # asr was disabled for non-premium users
47
- # expect {@client.voice_request(File.new(fixture_path + '/hello.wav'))}.to raise_error(ApiAiRuby::RequestError)
48
- end
49
-
50
44
  it 'should correctly set contexts with parameters' do
51
45
  @client.text_request 'Hello', :resetContexts => true
52
46
  response = @client.text_request 'hello', contexts: [{ name: 'user', parameters: { first_name: 'Johnny' }}]
@@ -26,7 +26,6 @@ describe ApiAiRuby::Client do
26
26
 
27
27
  it 'raises error on request without credentials' do
28
28
  expect {subject.text_request '123'}.to raise_error(ApiAiRuby::ClientError)
29
- expect {subject.voice_request '123'}.to raise_error(ApiAiRuby::ClientError)
30
29
  end
31
30
 
32
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-ai-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - api.ai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-22 00:00:00.000000000 Z
11
+ date: 2017-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,7 +78,6 @@ files:
78
78
  - lib/api-ai-ruby/request/event_request.rb
79
79
  - lib/api-ai-ruby/request/request_query.rb
80
80
  - lib/api-ai-ruby/request/text_request.rb
81
- - lib/api-ai-ruby/request/voice_request.rb
82
81
  - lib/api-ai-ruby/request_error.rb
83
82
  - spec/api-ai-ruby/api_spec.rb
84
83
  - spec/api-ai-ruby/client_spec.rb
@@ -109,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
108
  version: '0'
110
109
  requirements: []
111
110
  rubyforge_project:
112
- rubygems_version: 2.5.1
111
+ rubygems_version: 2.6.12
113
112
  signing_key:
114
113
  specification_version: 4
115
114
  summary: ruby SDK for https://api.ai
@@ -123,4 +122,3 @@ test_files:
123
122
  - spec/api-ai-ruby/voice_request_spec.rb
124
123
  - spec/fixtures/hello.wav
125
124
  - spec/helper.rb
126
- has_rdoc:
@@ -1,23 +0,0 @@
1
- require 'json'
2
-
3
- module ApiAiRuby
4
- class VoiceRequest < ApiAiRuby::RequestQuery
5
-
6
-
7
- # @param client [ApiAiRuby::Client]
8
- # @param options [Hash]
9
- # @return [ApiAiRuby::VoiceRequest]
10
- def initialize(client, options = {})
11
- options[:lang] = client.api_lang
12
- super client, options
13
- file = options.delete(:file)
14
- options = {
15
- :request => options.to_json,
16
- :voiceData => HTTP::FormData::File.new(file, filename: File.basename(file))
17
- }
18
- @options = options
19
- self
20
- end
21
-
22
- end
23
- end