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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcde1288aaa42a8c6fe96875317a2d7d80490f43
4
- data.tar.gz: 0824bef538f1f8a2bcbf967eabba1273927ee943
3
+ metadata.gz: 7ed1c1f753d58c6150bf9ebd530581db7a4a8087
4
+ data.tar.gz: da4b358a220faa34f0a9a1de37a0bc5f084a3826
5
5
  SHA512:
6
- metadata.gz: 9900632c2417fa020fb7b41a837e5138ec7f2f3e13573f1697208c998e509169eddcc26e7de98c8a34d35b0a75a33e9f6c53ad23d3b45d1a78e718d80a54f7a7
7
- data.tar.gz: 249e2583124f011ca64b05e0dc59e474c3a9d5b4d3bda1ed5a21324539db6cee7a1526287bc08894ede8772201514ca93a5dd0918b2edeb4fe9f817dd1fa5dcd
6
+ metadata.gz: e2d5bf776ca0a39bc00b4817d649bb52964b2827785d178d686bdd226034a3bd2ba3c632edf8ab125e6e0b076c0b02f94863a1d84c3dee1bdf54f2dafa44037c
7
+ data.tar.gz: 4d4f695d64b4493226e82c7103ea75b61741fd4858a64fcb6bb2348b8b39f37208eea990c93871733cd0f5c1ea14f25583c283977241704c7087d82fdfb38796
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ * Support timeout `Nexmo::Voice::Client.new 'your_key', 'your_secret', timeout: 2`
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',
@@ -9,23 +9,23 @@ module Nexmo
9
9
  BASE_URL = 'https://api.nexmo.com'
10
10
 
11
11
  class Client
12
- attr_accessor :api_key, :api_secret,
12
+ attr_accessor :nexmo_adaptor, :api_config,
13
13
  :calls, :ttses
14
14
 
15
- def initialize(api_key, api_secret)
16
- @api_key, @api_secret = api_key, api_secret
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
- uri = "#{BASE_URL}#{resource.class::RELATIVE_URL}"
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
 
@@ -1,5 +1,5 @@
1
1
  module Nexmo
2
2
  module Voice
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -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
- before do
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
- stub_request(:get, %r(https://api.nexmo.com/call/json.*)).to_return(body: response_json)
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
- before do
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
- stub_request(:get, %r(https://api.nexmo.com/tts/json.*)).to_return(body: response_json)
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
 
@@ -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 api_key' do
15
- expect(client.api_key).to eq api_key
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 api_secret' do
19
- expect(client.api_secret).to eq api_secret
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.2
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: 2015-01-26 00:00:00.000000000 Z
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.5
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.