telapi 1.0.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.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +162 -0
- data/Rakefile +1 -0
- data/lib/telapi.rb +24 -0
- data/lib/telapi/account.rb +14 -0
- data/lib/telapi/application.rb +88 -0
- data/lib/telapi/available_phone_number.rb +24 -0
- data/lib/telapi/call.rb +214 -0
- data/lib/telapi/caller_id.rb +16 -0
- data/lib/telapi/carrier.rb +16 -0
- data/lib/telapi/conference.rb +206 -0
- data/lib/telapi/configuration.rb +40 -0
- data/lib/telapi/error.rb +22 -0
- data/lib/telapi/fraud.rb +79 -0
- data/lib/telapi/inbound_xml.rb +36 -0
- data/lib/telapi/incoming_phone_number.rb +86 -0
- data/lib/telapi/message.rb +47 -0
- data/lib/telapi/network.rb +50 -0
- data/lib/telapi/notification.rb +29 -0
- data/lib/telapi/recording.rb +69 -0
- data/lib/telapi/resource.rb +18 -0
- data/lib/telapi/resource_collection.rb +38 -0
- data/lib/telapi/transcription.rb +44 -0
- data/lib/telapi/version.rb +3 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/telapi_helpers.rb +38 -0
- data/spec/telapi/account_spec.rb +17 -0
- data/spec/telapi/application_spec.rb +69 -0
- data/spec/telapi/available_phone_number_spec.rb +27 -0
- data/spec/telapi/call_spec.rb +173 -0
- data/spec/telapi/caller_id_spec.rb +17 -0
- data/spec/telapi/carrier_spec.rb +17 -0
- data/spec/telapi/conference_spec.rb +174 -0
- data/spec/telapi/configuration_spec.rb +38 -0
- data/spec/telapi/error_spec.rb +32 -0
- data/spec/telapi/fraud_spec.rb +55 -0
- data/spec/telapi/inbound_xml_spec.rb +49 -0
- data/spec/telapi/incoming_phone_number_spec.rb +69 -0
- data/spec/telapi/message_spec.rb +41 -0
- data/spec/telapi/network_spec.rb +80 -0
- data/spec/telapi/notification_spec.rb +34 -0
- data/spec/telapi/recording_spec.rb +72 -0
- data/spec/telapi/resource_collection_spec.rb +64 -0
- data/spec/telapi/resource_spec.rb +25 -0
- data/spec/telapi/transcription_spec.rb +41 -0
- data/telapi-ruby.gemspec +32 -0
- metadata +227 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Telapi::ApiError do
|
4
|
+
subject do
|
5
|
+
Telapi::ApiError.new(
|
6
|
+
'status' => 403,
|
7
|
+
'message' => 'Invalid credentials supplied',
|
8
|
+
'code' => 10004,
|
9
|
+
'more_info' => 'http://www.telapi.com/docs/api/rest/overview/errors/10004'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has a status" do
|
14
|
+
subject.status.should == 403
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has a code" do
|
18
|
+
subject.code.should == 10004
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has a help uri" do
|
22
|
+
subject.help_uri.should == 'http://www.telapi.com/docs/api/rest/overview/errors/10004'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Telapi::InvalidConfiguration do
|
27
|
+
subject { Telapi::InvalidConfiguration.new('attribute name') }
|
28
|
+
|
29
|
+
it "has a message containing the attribute" do
|
30
|
+
subject.message.should include('attribute name')
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Telapi::Fraud do
|
4
|
+
before do
|
5
|
+
stub_telapi_request
|
6
|
+
set_account_sid_and_auth_token
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_kind_of(Telapi::Resource) }
|
10
|
+
|
11
|
+
describe ".list" do
|
12
|
+
before { stub_telapi_request('{ "frauds": [] }') }
|
13
|
+
|
14
|
+
it "calls api via http get and returns a ResourceCollection" do
|
15
|
+
api_should_use(:get)
|
16
|
+
klass.list.should be_a(Telapi::ResourceCollection)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when Fraud controls exist" do
|
20
|
+
before { stub_telapi_request('{ "frauds": [{ "key": "value" }] }') }
|
21
|
+
|
22
|
+
it "has a collection of Fraud objects" do
|
23
|
+
klass.list.first.should be_a(klass)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".authorize" do
|
29
|
+
it "calls api via http post and returns a Fraud resource" do
|
30
|
+
api_should_use(:post)
|
31
|
+
klass.authorize('US').should be_a(klass)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".extend_authorization" do
|
36
|
+
it "calls api via http post and returns a Fraud resource" do
|
37
|
+
api_should_use(:post)
|
38
|
+
klass.extend_authorization('US').should be_a(klass)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".block" do
|
43
|
+
it "calls api via http post and returns a Fraud resource" do
|
44
|
+
api_should_use(:post)
|
45
|
+
klass.block('US').should be_a(klass)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".whitelist" do
|
50
|
+
it "calls api via http post and returns a Fraud resource" do
|
51
|
+
api_should_use(:post)
|
52
|
+
klass.whitelist('US').should be_a(klass)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# to avoid retesting the Nokogiri gem, our specs are minimal
|
4
|
+
describe Telapi::InboundXml do
|
5
|
+
describe "#reponse" do
|
6
|
+
it "returns XML wrapped in a Response node" do
|
7
|
+
|
8
|
+
ix = klass.new do
|
9
|
+
Say('Hello.', :loop => 3, :voice => 'man')
|
10
|
+
Say('Hello, my name is Jane.', :voice => 'woman')
|
11
|
+
Say('Now I will not stop talking.', :loop => 0)
|
12
|
+
end
|
13
|
+
|
14
|
+
expected = <<-END.gsub(/^ {6}/, '')
|
15
|
+
<?xml version="1.0"?>
|
16
|
+
<Response>
|
17
|
+
<Say loop="3" voice="man">Hello.</Say>
|
18
|
+
<Say voice="woman">Hello, my name is Jane.</Say>
|
19
|
+
<Say loop="0">Now I will not stop talking.</Say>
|
20
|
+
</Response>
|
21
|
+
END
|
22
|
+
|
23
|
+
ix.response.should == expected
|
24
|
+
end
|
25
|
+
|
26
|
+
it "handles nested blocks correctly" do
|
27
|
+
|
28
|
+
ix = klass.new do
|
29
|
+
Gather(:action => 'http://example.com/example-callback-url/say?example=simple.xml',
|
30
|
+
:method => 'GET',
|
31
|
+
:numDigits => '4',
|
32
|
+
:finishOnKey => '#') {
|
33
|
+
Say 'Please enter your 4 digit pin.'
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
expected = <<-END.gsub(/^ {6}/, '')
|
38
|
+
<?xml version="1.0"?>
|
39
|
+
<Response>
|
40
|
+
<Gather action="http://example.com/example-callback-url/say?example=simple.xml" method="GET" numDigits="4" finishOnKey="#">
|
41
|
+
<Say>Please enter your 4 digit pin.</Say>
|
42
|
+
</Gather>
|
43
|
+
</Response>
|
44
|
+
END
|
45
|
+
|
46
|
+
ix.response.should == expected
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Telapi::IncomingPhoneNumber do
|
4
|
+
before do
|
5
|
+
stub_telapi_request
|
6
|
+
set_account_sid_and_auth_token
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_kind_of(Telapi::Resource) }
|
10
|
+
|
11
|
+
describe ".list" do
|
12
|
+
before { stub_telapi_request('{ "incoming_phone_numbers": [] }') }
|
13
|
+
|
14
|
+
it "calls api via http get and returns a ResourceCollection" do
|
15
|
+
api_should_use(:get)
|
16
|
+
klass.list.should be_a(Telapi::ResourceCollection)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when Incoming Phone Numbers exist" do
|
20
|
+
before { stub_telapi_request('{ "incoming_phone_numbers": [{ "phone_number": "+14242495526" }] }') }
|
21
|
+
|
22
|
+
it "has a collection of Incoming Phone Number objects" do
|
23
|
+
klass.list.first.should be_a(klass)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".get" do
|
29
|
+
it "calls api via http get and returns a IncomingPhoneNumber resource" do
|
30
|
+
api_should_use(:get)
|
31
|
+
klass.get('abc123').should be_a(klass)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".create" do
|
36
|
+
it "calls api via http post and returns an IncomingPhoneNumber resource" do
|
37
|
+
api_should_use(:post)
|
38
|
+
klass.create('14155551234').should be_a(klass)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".delete" do
|
43
|
+
it "calls api via http delete and returns an IncomingPhoneNumber resource" do
|
44
|
+
api_should_use(:delete)
|
45
|
+
klass.delete('123').should be_a(klass)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#delete" do
|
50
|
+
it "proxies to IncomingPhoneNumber.speak_text" do
|
51
|
+
klass.should_receive(:delete)
|
52
|
+
klass.get('abc123').delete
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe ".update" do
|
57
|
+
it "calls api via http post and returns an IncomingPhoneNumber resource" do
|
58
|
+
api_should_use(:post)
|
59
|
+
klass.update('123', :FriendlyName => 'new name').should be_a(klass)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#update" do
|
64
|
+
it "proxies to IncomingPhoneNumber.update" do
|
65
|
+
klass.should_receive(:update)
|
66
|
+
klass.get('abc123').update(:FriendlyName => 'new name')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Telapi::Message do
|
4
|
+
before do
|
5
|
+
stub_telapi_request
|
6
|
+
set_account_sid_and_auth_token
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_kind_of(Telapi::Resource) }
|
10
|
+
|
11
|
+
describe ".list" do
|
12
|
+
before { stub_telapi_request('{ "sms_messages": [] }') }
|
13
|
+
|
14
|
+
it "calls api via http get and returns a ResourceCollection" do
|
15
|
+
api_should_use(:get)
|
16
|
+
klass.list.should be_a(Telapi::ResourceCollection)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when SMS Messages exist" do
|
20
|
+
before { stub_telapi_request('{ "sms_messages": [{ "from": "+14245551234","to": "+17325551234"}] }') }
|
21
|
+
|
22
|
+
it "has a collection of Message objects" do
|
23
|
+
klass.list.first.should be_a(klass)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".get" do
|
29
|
+
it "calls api via http get and returns a Message resource" do
|
30
|
+
api_should_use(:get)
|
31
|
+
klass.get('abc123').should be_a(klass)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".create" do
|
36
|
+
it "calls api via http post and returns a Message resource" do
|
37
|
+
api_should_use(:post)
|
38
|
+
klass.create('(111) 111-1111', '(999) 999-9999', 'My SMS message').should be_a(klass)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Telapi::Network do
|
4
|
+
before do
|
5
|
+
set_account_sid_and_auth_token
|
6
|
+
stub_telapi_request
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".get" do
|
10
|
+
it "gets an api response and converts to a hash" do
|
11
|
+
subject.get.should be_a(Hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when error is returned by the API" do
|
15
|
+
before { stub_telapi_request_with_error_response }
|
16
|
+
|
17
|
+
it "raises a ApiError" do
|
18
|
+
expect { subject.get }.to raise_error(Telapi::ApiError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".post" do
|
24
|
+
it "gets an api response and converts to a hash" do
|
25
|
+
subject.post(:param1 => 'value1').should be_a(Hash)
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when error is returned by the API" do
|
29
|
+
before { stub_telapi_request_with_error_response }
|
30
|
+
|
31
|
+
it "raises a ApiError" do
|
32
|
+
expect { subject.post(:param1 => 'value1') }.to raise_error(Telapi::ApiError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".delete" do
|
38
|
+
it "gets an api response and converts to a hash" do
|
39
|
+
subject.delete.should be_a(Hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when error is returned by the API" do
|
43
|
+
before { stub_telapi_request_with_error_response }
|
44
|
+
|
45
|
+
it "raises a ApiError" do
|
46
|
+
expect { subject.delete }.to raise_error(Telapi::ApiError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe ".api_uri" do
|
52
|
+
it "generates a uri using an array of path components" do
|
53
|
+
path_components = ['SomeResource', '123']
|
54
|
+
subject.api_uri(path_components).should == 'https://api.telapi.com/2011-07-01/Accounts/a1b2c3/SomeResource/123.json'
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when path components are not supplied" do
|
58
|
+
it "generates a uri consisting of the root resource (Account)" do
|
59
|
+
subject.api_uri.should == 'https://api.telapi.com/2011-07-01/Accounts/a1b2c3.json'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe ".response_format" do
|
65
|
+
it "is json" do
|
66
|
+
subject.response_format.should == '.json'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe ".default_options" do
|
71
|
+
it "raises an Invalid Configuration exception when not set properly" do
|
72
|
+
reset_config
|
73
|
+
expect { subject.default_options }.to raise_error(Telapi::InvalidConfiguration)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "gets a hash of config options" do
|
77
|
+
subject.default_options.should be_a(Hash)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Telapi::Notification do
|
4
|
+
before do
|
5
|
+
stub_telapi_request
|
6
|
+
set_account_sid_and_auth_token
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_kind_of(Telapi::Resource) }
|
10
|
+
|
11
|
+
describe ".list" do
|
12
|
+
before { stub_telapi_request('{ "notifications": [] }') }
|
13
|
+
|
14
|
+
it "calls api via http get and returns a ResourceCollection" do
|
15
|
+
api_should_use(:get)
|
16
|
+
klass.list.should be_a(Telapi::ResourceCollection)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when Notifications exist" do
|
20
|
+
before { stub_telapi_request('{ "notifications": [{ "message_text": "foo" }] }') }
|
21
|
+
|
22
|
+
it "has a collection of Notification objects" do
|
23
|
+
klass.list.first.should be_a(klass)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".get" do
|
29
|
+
it "calls api via http get and returns a Notification resource" do
|
30
|
+
api_should_use(:get)
|
31
|
+
klass.get('abc123').should be_a(klass)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Telapi::Recording do
|
4
|
+
before do
|
5
|
+
stub_telapi_request
|
6
|
+
set_account_sid_and_auth_token
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_kind_of(Telapi::Resource) }
|
10
|
+
|
11
|
+
describe ".list" do
|
12
|
+
before { stub_telapi_request('{ "recordings": [] }') }
|
13
|
+
|
14
|
+
it "calls api via http get and returns a ResourceCollection" do
|
15
|
+
api_should_use(:get)
|
16
|
+
klass.list.should be_a(Telapi::ResourceCollection)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when Recordings exist" do
|
20
|
+
before { stub_telapi_request('{ "recordings": [{ "duration": "6" }] }') }
|
21
|
+
|
22
|
+
it "has a collection of Recording objects" do
|
23
|
+
klass.list.first.should be_a(klass)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".get" do
|
29
|
+
it "calls api via http get and returns a Recording resource" do
|
30
|
+
api_should_use(:get)
|
31
|
+
klass.get('abc123').should be_a(klass)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".transcribe" do
|
36
|
+
it "calls api via http post and returns a Transcription resource" do
|
37
|
+
api_should_use(:post)
|
38
|
+
klass.transcribe('abc123').should be_a(Telapi::Transcription)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#transcribe" do
|
43
|
+
it "proxies to Recording.transcribe" do
|
44
|
+
klass.should_receive(:transcribe)
|
45
|
+
klass.get('abc123').transcribe
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".transcriptions" do
|
50
|
+
before { stub_telapi_request('{ "transcriptions": [] }') }
|
51
|
+
|
52
|
+
it "calls api via http get and returns a ResourceCollection" do
|
53
|
+
api_should_use(:get)
|
54
|
+
klass.transcriptions('abc123').should be_a(Telapi::ResourceCollection)
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when Transcriptions exist" do
|
58
|
+
before { stub_telapi_request('{ "transcriptions": [{ "transcription_text": "foo" }] }') }
|
59
|
+
|
60
|
+
it "has a collection of Transcription objects" do
|
61
|
+
klass.transcriptions('abc123').first.should be_a(Telapi::Transcription)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#transcriptions" do
|
67
|
+
it "proxies to Recording.transcriptions" do
|
68
|
+
klass.should_receive(:transcriptions)
|
69
|
+
klass.get('abc123').transcriptions
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Telapi::ResourceCollection do
|
4
|
+
context "when initialized with at least one nested item" do
|
5
|
+
subject do
|
6
|
+
klass.new({
|
7
|
+
'page' => 0,
|
8
|
+
'num_pages' => 0,
|
9
|
+
'page_size' => 5,
|
10
|
+
'total' => 1,
|
11
|
+
'start' => 0,
|
12
|
+
'end' => 0,
|
13
|
+
'items' => [{ 'food' => 'burger', 'drink' => 'beer' }]
|
14
|
+
}, 'items', Telapi::Resource)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "setting collection-specific metrics" do
|
18
|
+
its(:page) { should == 0 }
|
19
|
+
its(:num_pages) { should == 0 }
|
20
|
+
its(:page_size) { should == 5 }
|
21
|
+
its(:total) { should == 1 }
|
22
|
+
its(:start) { should == 0 }
|
23
|
+
its(:end) { should == 0 }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has an item count greater than 0" do
|
27
|
+
subject.items.length.should be > 0
|
28
|
+
end
|
29
|
+
|
30
|
+
it "is not empty" do
|
31
|
+
subject.should_not be_empty
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can return the last item" do
|
35
|
+
subject.last.should be_a(Telapi::Resource)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can return an item using its index" do
|
39
|
+
subject[0].should be_a(Telapi::Resource)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when initialized without any nested items" do
|
44
|
+
subject do
|
45
|
+
klass.new({ 'meal' => 'dinner', 'items' => [] }, 'items', Telapi::Resource)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "has 0 items" do
|
49
|
+
subject.items.length.should == 0
|
50
|
+
end
|
51
|
+
|
52
|
+
it "is empty" do
|
53
|
+
subject.should be_empty
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns nil when getting the last item" do
|
57
|
+
subject.last.should be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns nil when getting a specific index" do
|
61
|
+
subject[0].should be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|