wit_ruby 1.0.1 → 1.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
2
  SHA1:
3
- metadata.gz: 35527605a33f51d07c685e9973074d80adc2a342
4
- data.tar.gz: 5f98a7b4f5549d06e5380fcc2a55d22496d9f1b3
3
+ metadata.gz: e040638ae931f07535588e9e1c12d684322fa5b9
4
+ data.tar.gz: bfaab5bddd0a95d47ee32f9f1aa63fddd8002b16
5
5
  SHA512:
6
- metadata.gz: 7c8663cf2937717cd9179db12645e7848d44649bc8f93c3d1725e4fcb25ff6ffd048e88c3427a194dd7ebfdb88179d93be76598d82fea6f092bf9e80b8ca008c
7
- data.tar.gz: a2f6aad050b9e0dd33ec0a86813ed8eae1d7037057fb2147244755116bd84641f9605f9530eff92fc034a2fac5c253b7ceea06ef27d7e336c6f12ec419f52acf
6
+ metadata.gz: e8706451d4e2fcc63f27f31d0cd73289fe2e839797c6383df98944fb19d1e2150af17a0603fa6c78f36a0f74ed72c8ac8dc03c94de78553a3b0dec0879a718aa
7
+ data.tar.gz: 2ebc0aa165a14e8bbe3280669b202b0f67d945c44d04bc13d4d6667593f089cfa38b351db4a73a5d636bbbfe7dedfb7ee5fa9f83cc4a49f91bdfc48a189224d8
data/.travis.yml CHANGED
@@ -7,4 +7,4 @@ rvm:
7
7
  script: bundle exec rake
8
8
  env:
9
9
  global:
10
- secure: TspoESXh5kwkswN8DjNHkcT50zTa6wzCoF3Q/wQ8rmH9aSpke55nh81+T29OXMNsTxdSvoj93KRC3U2MHhRYM+aIKdtjwXFClTERbWKJmcFlkEWf/1LVxYRLqR/jMfb9gIkDQJ10vB1kFqZ+niShcQGgdfJGZn0y4cucA/ZPG9I=
10
+ secure: AALEF5biTduH6D0+o6SLFzIZuoypg92KV/08XdAnm0nvUFjdu/XU6qhY6b10x/coLQa6CJYTwZ6L5YVZHc90YJTf/N4mpYGUuEMXKg6Nr53I+072BaYshDjDh8IA/t2DtT53ZGr7t9VBf6FWqoDbGJXjdmvbOZZ/AcyQUnu6ksg=
@@ -64,12 +64,14 @@ module Wit
64
64
  method_rest_class = Net::HTTP.const_get rest_method.to_s.capitalize
65
65
 
66
66
  ## Define the actual method for Wit::Session:Client
67
- define_method rest_method do |path, params=nil|
67
+ define_method rest_method do |path, params=nil, content_overide=nil|
68
68
  request = method_rest_class.new path, {"Authorization" => "Bearer #{@auth_token}"}
69
69
  ## If post or put, set content-type to be JSON
70
70
  if [:post, :put].include?(rest_method)
71
71
  request.body = params
72
- request["Content-Type"] = "application/json"
72
+ ## Will check if there is a Content-Type Header overide, and if not, default to
73
+ ## JSON specific header.
74
+ request["Content-Type"] = content_overide || "application/json"
73
75
  request["Accept"] = "application/vnd.wit.20160202+json"
74
76
  end
75
77
  return connect_send(request)
@@ -34,8 +34,23 @@ module Wit
34
34
  ## Do check the certain documentation of what the specific audio file
35
35
  ## should be.
36
36
  ##
37
- ## @param sound [String] path to sound file.
38
- def send_sound_message(sound)
37
+ ## @param sound_file_path [String] path to sound file.
38
+ def send_sound_message(sound_file_path)
39
+ ## Given the path, we send the file and add proper headers
40
+ ## Check if it is a specifc file type
41
+ ## This seems dirty, look more into it.
42
+ sound_file_type = sound_file_path.split(".")[-1]
43
+ ## Raise error if not accepted
44
+ unless ["wav", "mp3", "ulaw", "raw"].include?(sound_file_type)
45
+ raise NotCorrectSchema.new("The current sound file is not one of the supported types. The file types accepted are .wav, .mp3, .ulaw and .raw")
46
+ end
47
+
48
+ ## Set Content-Type header by overiding it with the correct filetype.
49
+ ## If it is raw, add the extra params to the end of it.
50
+ content_overide = "audio/#{sound_file_type}"
51
+ content_overide += ";encoding=unsigned-integer;bits=16;rate=8000;endian=big" if sound_file_type == "raw"
52
+ results = @client.post("/speech", File.read(sound_file_path), "audio/#{sound_file_type}")
53
+ return return_with_class(Wit::REST::Message, results)
39
54
  end
40
55
 
41
56
  ## GET - returns stored message for specific id.
@@ -1,3 +1,3 @@
1
1
  module Wit
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
Binary file
@@ -9,7 +9,14 @@ describe Wit::REST::Session do
9
9
  let(:message) {"Hi"}
10
10
  let(:rand_hash) {{"a" => "a", "b" => "b"}}
11
11
  let(:randSession) {Wit::REST::Session.new(randClient)}
12
- let(:session) {Wit::REST::Client.new.session}
12
+ ## Uses a testing specific developer instances so a generic testing platform is created.
13
+ ## Don't do dirty stuff.
14
+ ## If in Travis, use ENV["TRAVIS_WIT_TOKEN"]
15
+ if ENV["TRAVIS_WIT_TOKEN"]
16
+ let(:session) {Wit::REST::Client.new(token: ENV["TRAVIS_WIT_TOKEN"]).session}
17
+ else
18
+ let(:session) {Wit::REST::Client.new(token: "BRB7NEG4D2TCL6C5VUMD4UA5H376DPKU").session}
19
+ end
13
20
  random_name = (0...10).map { ('a'..'z').to_a[rand(26)] }.join
14
21
 
15
22
 
@@ -23,7 +30,7 @@ describe Wit::REST::Session do
23
30
  randSession.should respond_to(:send_message)
24
31
  end
25
32
 
26
- it ".send_sound_message(soundwave)" do
33
+ it ".send_sound_message(sound_file)" do
27
34
  randSession.should respond_to(:send_sound_message)
28
35
  end
29
36
 
@@ -138,6 +145,25 @@ describe Wit::REST::Session do
138
145
  end
139
146
 
140
147
 
148
+ describe "Sending sound file" do
149
+ let(:test_sound_file_hello_path) {File.dirname(__FILE__) + '/../../test_hello.wav'}
150
+
151
+ let(:sent_message_sound_result) {session.send_sound_message(test_sound_file_hello_path)}
152
+ before do
153
+ VCR.insert_cassette 'send_sound_message', record: :once, preserve_exact_body_bytes: true
154
+ end
155
+ after do
156
+ VCR.eject_cassette
157
+ end
158
+
159
+ it "should return an object of class Message" do
160
+ expect(sent_message_sound_result.class).to eql(Wit::REST::Message)
161
+ end
162
+
163
+
164
+ end
165
+
166
+
141
167
  describe "Geting message info" do
142
168
  let(:sent_message_result) {session.send_message(message)}
143
169
  let(:sent_message_id) {sent_message_result.msg_id}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wit_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2014-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -220,6 +220,7 @@ files:
220
220
  - lib/wit_ruby/rest/session.rb
221
221
  - lib/wit_ruby/version.rb
222
222
  - spec/spec_helper.rb
223
+ - spec/test_hello.wav
223
224
  - spec/wit_ruby/rest/bodyjson_spec.rb
224
225
  - spec/wit_ruby/rest/client_spec.rb
225
226
  - spec/wit_ruby/rest/entity_spec.rb
@@ -255,6 +256,7 @@ specification_version: 4
255
256
  summary: Provides a Ruby API wrapper with the Wit.ai API.
256
257
  test_files:
257
258
  - spec/spec_helper.rb
259
+ - spec/test_hello.wav
258
260
  - spec/wit_ruby/rest/bodyjson_spec.rb
259
261
  - spec/wit_ruby/rest/client_spec.rb
260
262
  - spec/wit_ruby/rest/entity_spec.rb