nexmo-voice 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +3 -1
- data/lib/nexmo/voice.rb +10 -10
- data/lib/nexmo/voice/version.rb +1 -1
- data/spec/nexmo/voice/calls_spec.rb +13 -5
- data/spec/nexmo/voice/ttses_spec.rb +13 -5
- data/spec/nexmo/voice_spec.rb +9 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ed1c1f753d58c6150bf9ebd530581db7a4a8087
|
4
|
+
data.tar.gz: da4b358a220faa34f0a9a1de37a0bc5f084a3826
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2d5bf776ca0a39bc00b4817d649bb52964b2827785d178d686bdd226034a3bd2ba3c632edf8ab125e6e0b076c0b02f94863a1d84c3dee1bdf54f2dafa44037c
|
7
|
+
data.tar.gz: 4d4f695d64b4493226e82c7103ea75b61741fd4858a64fcb6bb2348b8b39f37208eea990c93871733cd0f5c1ea14f25583c283977241704c7087d82fdfb38796
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -21,7 +21,9 @@ Or install it yourself as:
|
|
21
21
|
```ruby
|
22
22
|
# Initialize your client
|
23
23
|
client = Nexmo::Voice::Client.new 'your_key', 'your_secret'
|
24
|
-
|
24
|
+
# or initialize with timeout(default: 10 seconds)
|
25
|
+
client = Nexmo::Voice::Client.new 'your_key', 'your_secret', timeout: 2
|
26
|
+
|
25
27
|
# Make a tts call with minimum options
|
26
28
|
options = {
|
27
29
|
to: 'recipient_number',
|
data/lib/nexmo/voice.rb
CHANGED
@@ -9,23 +9,23 @@ module Nexmo
|
|
9
9
|
BASE_URL = 'https://api.nexmo.com'
|
10
10
|
|
11
11
|
class Client
|
12
|
-
attr_accessor :
|
12
|
+
attr_accessor :nexmo_adaptor, :api_config,
|
13
13
|
:calls, :ttses
|
14
14
|
|
15
|
-
def initialize(api_key, api_secret)
|
16
|
-
@
|
15
|
+
def initialize(api_key, api_secret, options = {})
|
16
|
+
@nexmo_adaptor = RestClient::Resource.new(BASE_URL, timeout: options.fetch(:timeout, 10))
|
17
|
+
|
18
|
+
@api_config = {
|
19
|
+
api_key: api_key,
|
20
|
+
api_secret: api_secret
|
21
|
+
}
|
22
|
+
|
17
23
|
@calls = Calls.new(self)
|
18
24
|
@ttses = Ttses.new(self)
|
19
25
|
end
|
20
26
|
|
21
27
|
def get(resource, entity = {})
|
22
|
-
|
23
|
-
params = entity.merge({
|
24
|
-
api_key: @api_key,
|
25
|
-
api_secret: @api_secret
|
26
|
-
})
|
27
|
-
|
28
|
-
RestClient.get(uri, params: params)
|
28
|
+
@nexmo_adaptor[resource.class::RELATIVE_URL].get(params: entity.merge(@api_config))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
data/lib/nexmo/voice/version.rb
CHANGED
@@ -3,20 +3,28 @@ require 'spec_helper'
|
|
3
3
|
describe Nexmo::Voice::Calls do
|
4
4
|
let(:client) { Nexmo::Voice::Client.new('api_key', 'api_secret') }
|
5
5
|
let(:entity) { { to: '8618000000001', answer_url: 'http://test.com/answer_url' } }
|
6
|
-
|
7
|
-
|
8
|
-
response_json = {
|
6
|
+
let(:response_json) {
|
7
|
+
{
|
9
8
|
'call-id' => 'd7d74aed5c754a992586c5baf01ed24d',
|
10
9
|
'to' => '8618600000001',
|
11
10
|
'status' => '0',
|
12
11
|
'error-text' => 'Success'
|
13
12
|
}
|
14
|
-
|
15
|
-
end
|
13
|
+
}
|
16
14
|
|
17
15
|
it 'not raises errors' do
|
16
|
+
stub_request(:get, %r(https://api.nexmo.com/call/json.*)).to_return(body: response_json)
|
17
|
+
|
18
18
|
expect {
|
19
19
|
client.calls.create(entity)
|
20
20
|
}.not_to raise_error
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'timeouts' do
|
24
|
+
stub_request(:get, %r(https://api.nexmo.com/call/json.*)).to_timeout
|
25
|
+
|
26
|
+
expect {
|
27
|
+
client.calls.create(entity)
|
28
|
+
}.to raise_error
|
29
|
+
end
|
22
30
|
end
|
@@ -3,21 +3,29 @@ require 'spec_helper'
|
|
3
3
|
describe Nexmo::Voice::Ttses do
|
4
4
|
let(:client) { Nexmo::Voice::Client.new('api_key', 'api_secret') }
|
5
5
|
let(:entity) { { to: '8618000000001', text: 'Hello from gem' } }
|
6
|
-
|
7
|
-
|
8
|
-
response_json = {
|
6
|
+
let(:response_json) {
|
7
|
+
{
|
9
8
|
'call-id' => 'd7d74aed5c754a992586c5baf01ed24d',
|
10
9
|
'to' => '8618600000001',
|
11
10
|
'status' => '0',
|
12
11
|
'error-text' => 'Success'
|
13
12
|
}
|
14
|
-
|
15
|
-
end
|
13
|
+
}
|
16
14
|
|
17
15
|
it 'not raises errors' do
|
16
|
+
stub_request(:get, %r(https://api.nexmo.com/tts/json.*)).to_return(body: response_json)
|
17
|
+
|
18
18
|
expect {
|
19
19
|
client.ttses.create(entity)
|
20
20
|
}.not_to raise_error
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'timeouts' do
|
24
|
+
stub_request(:get, %r(https://api.nexmo.com/tts/json.*)).to_timeout
|
25
|
+
|
26
|
+
expect {
|
27
|
+
client.calls.create(entity)
|
28
|
+
}.to raise_error
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
data/spec/nexmo/voice_spec.rb
CHANGED
@@ -11,11 +11,16 @@ RSpec.describe Nexmo::Voice::Client do
|
|
11
11
|
let(:api_secret) { 'test_api_secret' }
|
12
12
|
let(:client) { Nexmo::Voice::Client.new api_key, api_secret }
|
13
13
|
|
14
|
-
it 'sets the
|
15
|
-
expect(client.
|
14
|
+
it 'sets the api_config' do
|
15
|
+
expect(client.api_config).to match({ api_key: api_key, api_secret: api_secret })
|
16
16
|
end
|
17
17
|
|
18
|
-
it 'sets the
|
19
|
-
expect(client.
|
18
|
+
it 'sets the default timeout' do
|
19
|
+
expect(client.nexmo_adaptor.timeout).to eq 10
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'sets the timeout' do
|
23
|
+
another_client = Nexmo::Voice::Client.new api_key, api_secret, timeout: 2
|
24
|
+
expect(another_client.nexmo_adaptor.timeout).to eq 2
|
20
25
|
end
|
21
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexmo-voice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fahchen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
+
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.md
|
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
123
|
version: '0'
|
123
124
|
requirements: []
|
124
125
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.4.
|
126
|
+
rubygems_version: 2.4.8
|
126
127
|
signing_key:
|
127
128
|
specification_version: 4
|
128
129
|
summary: A Ruby wrapper for the Nexmo Voice API.
|