telapi 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +20 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +162 -0
  5. data/Rakefile +1 -0
  6. data/lib/telapi.rb +24 -0
  7. data/lib/telapi/account.rb +14 -0
  8. data/lib/telapi/application.rb +88 -0
  9. data/lib/telapi/available_phone_number.rb +24 -0
  10. data/lib/telapi/call.rb +214 -0
  11. data/lib/telapi/caller_id.rb +16 -0
  12. data/lib/telapi/carrier.rb +16 -0
  13. data/lib/telapi/conference.rb +206 -0
  14. data/lib/telapi/configuration.rb +40 -0
  15. data/lib/telapi/error.rb +22 -0
  16. data/lib/telapi/fraud.rb +79 -0
  17. data/lib/telapi/inbound_xml.rb +36 -0
  18. data/lib/telapi/incoming_phone_number.rb +86 -0
  19. data/lib/telapi/message.rb +47 -0
  20. data/lib/telapi/network.rb +50 -0
  21. data/lib/telapi/notification.rb +29 -0
  22. data/lib/telapi/recording.rb +69 -0
  23. data/lib/telapi/resource.rb +18 -0
  24. data/lib/telapi/resource_collection.rb +38 -0
  25. data/lib/telapi/transcription.rb +44 -0
  26. data/lib/telapi/version.rb +3 -0
  27. data/spec/spec_helper.rb +17 -0
  28. data/spec/support/telapi_helpers.rb +38 -0
  29. data/spec/telapi/account_spec.rb +17 -0
  30. data/spec/telapi/application_spec.rb +69 -0
  31. data/spec/telapi/available_phone_number_spec.rb +27 -0
  32. data/spec/telapi/call_spec.rb +173 -0
  33. data/spec/telapi/caller_id_spec.rb +17 -0
  34. data/spec/telapi/carrier_spec.rb +17 -0
  35. data/spec/telapi/conference_spec.rb +174 -0
  36. data/spec/telapi/configuration_spec.rb +38 -0
  37. data/spec/telapi/error_spec.rb +32 -0
  38. data/spec/telapi/fraud_spec.rb +55 -0
  39. data/spec/telapi/inbound_xml_spec.rb +49 -0
  40. data/spec/telapi/incoming_phone_number_spec.rb +69 -0
  41. data/spec/telapi/message_spec.rb +41 -0
  42. data/spec/telapi/network_spec.rb +80 -0
  43. data/spec/telapi/notification_spec.rb +34 -0
  44. data/spec/telapi/recording_spec.rb +72 -0
  45. data/spec/telapi/resource_collection_spec.rb +64 -0
  46. data/spec/telapi/resource_spec.rb +25 -0
  47. data/spec/telapi/transcription_spec.rb +41 -0
  48. data/telapi-ruby.gemspec +32 -0
  49. metadata +227 -0
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Telapi::AvailablePhoneNumber 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('{ "available_phone_numbers": [] }') }
13
+
14
+ it "calls api via http get and returns a ResourceCollection" do
15
+ api_should_use(:get)
16
+ klass.list('US').should be_a(Telapi::ResourceCollection)
17
+ end
18
+
19
+ context "when Available Phone Numbers exist" do
20
+ before { stub_telapi_request('{ "available_phone_numbers": [{ "phone_number": "+14242495526" }] }') }
21
+
22
+ it "has a collection of Available Phone Number objects" do
23
+ klass.list('US').first.should be_a(klass)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,173 @@
1
+ require 'spec_helper'
2
+
3
+ describe Telapi::Call 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('{ "calls": [] }') }
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 Calls exist" do
20
+ before { stub_telapi_request('{ "calls": [{ "from": "+14245551234","to": "+17325551234"}] }') }
21
+
22
+ it "has a collection of Call 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 Call resource" do
30
+ api_should_use(:get)
31
+ klass.get('abc123').should be_a(klass)
32
+ end
33
+ end
34
+
35
+ describe ".make" do
36
+ it "calls api via http post and returns a Call resource" do
37
+ api_should_use(:post)
38
+ klass.make('(111) 111-1111', '(999) 999-9999', 'http://www.telapi.com/ivr/welcome/call').should be_a(klass)
39
+ end
40
+ end
41
+
42
+ describe ".interrupt" do
43
+ it "calls api via http post and returns a Call resource" do
44
+ api_should_use(:post)
45
+ klass.interrupt('abc123', 'http://www.telapi.com/ivr/welcome/call').should be_a(klass)
46
+ end
47
+ end
48
+
49
+ describe "#interrupt" do
50
+ it "proxies to Call.interrupt" do
51
+ klass.should_receive(:interrupt)
52
+ klass.get('abc123').interrupt('http://www.telapi.com/ivr/welcome/call')
53
+ end
54
+ end
55
+
56
+ describe ".hangup" do
57
+ it "calls api via http post and returns a Call resource" do
58
+ api_should_use(:post)
59
+ klass.hangup('abc123').should be_a(klass)
60
+ end
61
+ end
62
+
63
+ describe "#hangup" do
64
+ it "proxies to Call.hangup" do
65
+ klass.should_receive(:hangup)
66
+ klass.get('abc123').hangup
67
+ end
68
+ end
69
+
70
+ describe ".send_digits" do
71
+ it "calls api via http post and returns a Call resource" do
72
+ api_should_use(:post)
73
+ klass.send_digits('abc123', '12ww34').should be_a(klass)
74
+ end
75
+ end
76
+
77
+ describe "#send_digits" do
78
+ it "proxies to Call.send_digits" do
79
+ klass.should_receive(:send_digits)
80
+ klass.get('abc123').send_digits('12ww34')
81
+ end
82
+ end
83
+
84
+ describe ".play_audio" do
85
+ it "calls api via http post and returns a Call resource" do
86
+ api_should_use(:post)
87
+ klass.play_audio('abc123', 'http://www.telapi.com/ivr/welcome/call').should be_a(klass)
88
+ end
89
+ end
90
+
91
+ describe "#play_audio" do
92
+ it "proxies to Call.play_audio" do
93
+ klass.should_receive(:play_audio)
94
+ klass.get('abc123').play_audio('http://www.telapi.com/ivr/welcome/call')
95
+ end
96
+ end
97
+
98
+ describe ".voice_effect" do
99
+ it "calls api via http post and returns a Call resource" do
100
+ api_should_use(:post)
101
+ klass.voice_effect('abc123').should be_a(klass)
102
+ end
103
+ end
104
+
105
+ describe "#voice_effect" do
106
+ it "proxies to Call.voice_effect" do
107
+ klass.should_receive(:voice_effect)
108
+ klass.get('abc123').voice_effect(:Pitch => '-1')
109
+ end
110
+ end
111
+
112
+ describe ".record" do
113
+ it "calls api via http post and returns a Call resource" do
114
+ api_should_use(:post)
115
+ klass.record('abc123').should be_a(klass)
116
+ end
117
+ end
118
+
119
+ describe "#record" do
120
+ it "proxies to Call.record" do
121
+ klass.should_receive(:record)
122
+ klass.get('abc123').record
123
+ end
124
+ end
125
+
126
+ describe ".recordings" do
127
+ before { stub_telapi_request('{ "recordings": [] }') }
128
+
129
+ it "calls api via http get and returns a ResourceCollection" do
130
+ api_should_use(:get)
131
+ klass.recordings('abc123').should be_a(Telapi::ResourceCollection)
132
+ end
133
+
134
+ context "when Recordings exist" do
135
+ before { stub_telapi_request('{ "recordings": [{ "duration": "6" }] }') }
136
+
137
+ it "has a collection of Recording objects" do
138
+ klass.recordings('abc123').first.should be_a(Telapi::Recording)
139
+ end
140
+ end
141
+ end
142
+
143
+ describe "#recordings" do
144
+ it "proxies to Call.recordings" do
145
+ klass.should_receive(:recordings)
146
+ klass.get('abc123').recordings
147
+ end
148
+ end
149
+
150
+ describe ".notifications" do
151
+ before { stub_telapi_request('{ "notifications": [] }') }
152
+
153
+ it "calls api via http get and returns a ResourceCollection" do
154
+ api_should_use(:get)
155
+ klass.notifications('abc123').should be_a(Telapi::ResourceCollection)
156
+ end
157
+
158
+ context "when Notifications exist" do
159
+ before { stub_telapi_request('{ "notifications": [{ "message_text": "foo" }] }') }
160
+
161
+ it "has a collection of Notification objects" do
162
+ klass.notifications('abc123').first.should be_a(Telapi::Notification)
163
+ end
164
+ end
165
+ end
166
+
167
+ describe "#notifications" do
168
+ it "proxies to Call.notifications" do
169
+ klass.should_receive(:notifications)
170
+ klass.get('abc123').notifications
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Telapi::CallerId 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 ".lookup" do
12
+ it "calls api via http get and returns a CallerId resource" do
13
+ api_should_use(:get)
14
+ klass.lookup('17325551234').should be_a(klass)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Telapi::Carrier 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 ".lookup" do
12
+ it "calls api via http get and returns a Carrier resource" do
13
+ api_should_use(:get)
14
+ klass.lookup('17325551234').should be_a(klass)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,174 @@
1
+ require 'spec_helper'
2
+
3
+ describe Telapi::Conference 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('{ "conferences": [] }') }
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 conferences exist" do
20
+ before { stub_telapi_request('{ "conferences": [{ "name": "TelAPIChat" }] }') }
21
+
22
+ it "has a collection of Conference 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 Conference resource" do
30
+ api_should_use(:get)
31
+ klass.get('abc123').should be_a(klass)
32
+ end
33
+ end
34
+
35
+ describe ".mute_member" do
36
+ it "calls api via http post and returns a Conference resource" do
37
+ api_should_use(:post)
38
+ klass.mute_member('abc123', '123').should be_a(klass)
39
+ end
40
+ end
41
+
42
+ describe "#mute_member" do
43
+ it "proxies to Conference.mute_member" do
44
+ klass.should_receive(:mute_member)
45
+ klass.get('abc123').mute_member('123')
46
+ end
47
+ end
48
+
49
+ describe ".unmute_member" do
50
+ it "calls api via http post and returns a Conference resource" do
51
+ api_should_use(:post)
52
+ klass.unmute_member('abc123', '123').should be_a(klass)
53
+ end
54
+ end
55
+
56
+ describe "#unmute_member" do
57
+ it "proxies to Conference.unmute_member" do
58
+ klass.should_receive(:unmute_member)
59
+ klass.get('abc123').unmute_member('123')
60
+ end
61
+ end
62
+
63
+ describe ".deaf_member" do
64
+ it "calls api via http post and returns a Conference resource" do
65
+ api_should_use(:post)
66
+ klass.deaf_member('abc123', '123').should be_a(klass)
67
+ end
68
+ end
69
+
70
+ describe "#deaf_member" do
71
+ it "proxies to Conference.deaf_member" do
72
+ klass.should_receive(:deaf_member)
73
+ klass.get('abc123').deaf_member('123')
74
+ end
75
+ end
76
+
77
+ describe ".undeaf_member" do
78
+ it "calls api via http post and returns a Conference resource" do
79
+ api_should_use(:post)
80
+ klass.undeaf_member('abc123', '123').should be_a(klass)
81
+ end
82
+ end
83
+
84
+ describe "#undeaf_member" do
85
+ it "proxies to Conference.undeaf_member" do
86
+ klass.should_receive(:undeaf_member)
87
+ klass.get('abc123').undeaf_member('123')
88
+ end
89
+ end
90
+
91
+ describe ".hangup_member" do
92
+ it "calls api via http post and returns a Conference resource" do
93
+ api_should_use(:post)
94
+ klass.hangup_member('abc123', '123').should be_a(klass)
95
+ end
96
+ end
97
+
98
+ describe "#hangup_member" do
99
+ it "proxies to Conference.hangup_member" do
100
+ klass.should_receive(:hangup_member)
101
+ klass.get('abc123').hangup_member('123')
102
+ end
103
+ end
104
+
105
+ describe ".kick_member" do
106
+ it "calls api via http post and returns a Conference resource" do
107
+ api_should_use(:post)
108
+ klass.kick_member('abc123', '123').should be_a(klass)
109
+ end
110
+ end
111
+
112
+ describe "#kick_member" do
113
+ it "proxies to Conference.kick_member" do
114
+ klass.should_receive(:kick_member)
115
+ klass.get('abc123').kick_member('123')
116
+ end
117
+ end
118
+
119
+ describe ".speak_text" do
120
+ it "calls api via http post and returns a Conference resource" do
121
+ api_should_use(:post)
122
+ klass.speak_text('abc123', '123', 'hi').should be_a(klass)
123
+ end
124
+ end
125
+
126
+ describe "#speak_text" do
127
+ it "proxies to Conference.speak_text" do
128
+ klass.should_receive(:speak_text)
129
+ klass.get('abc123').speak_text('123', 'hi')
130
+ end
131
+ end
132
+
133
+ describe ".play_audio" do
134
+ it "calls api via http post and returns a Conference resource" do
135
+ api_should_use(:post)
136
+ klass.play_audio('abc123', '123', 'http://url').should be_a(klass)
137
+ end
138
+ end
139
+
140
+ describe "#play_audio" do
141
+ it "proxies to Conference.play_audio" do
142
+ klass.should_receive(:play_audio)
143
+ klass.get('abc123').play_audio('123', 'http://url')
144
+ end
145
+ end
146
+
147
+ describe ".start_recording" do
148
+ it "calls api via http post and returns a Conference resource" do
149
+ api_should_use(:post)
150
+ klass.start_recording('abc123').should be_a(klass)
151
+ end
152
+ end
153
+
154
+ describe "#start_recording" do
155
+ it "proxies to Conference.start_recording" do
156
+ klass.should_receive(:start_recording)
157
+ klass.get('abc123').start_recording
158
+ end
159
+ end
160
+
161
+ describe ".stop_recording" do
162
+ it "calls api via http post and returns a Conference resource" do
163
+ api_should_use(:post)
164
+ klass.stop_recording('abc123').should be_a(klass)
165
+ end
166
+ end
167
+
168
+ describe "#stop_recording" do
169
+ it "proxies to Conference.stop_recording" do
170
+ klass.should_receive(:stop_recording)
171
+ klass.get('abc123').stop_recording
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Configuration" do
4
+ subject { Telapi.config }
5
+
6
+ context "getting config options" do
7
+ it "has retrievable options" do
8
+ subject.ssl_ca_path.should be
9
+ end
10
+
11
+ it "returns nil for unknown options" do
12
+ subject.blah.should be_nil
13
+ end
14
+ end
15
+
16
+ context "setting config options" do
17
+ it "can be set individually" do
18
+ subject.ssl_ca_path = '/foo/bar'
19
+ subject.ssl_ca_path.should == '/foo/bar'
20
+ end
21
+
22
+ it "can be set with a block" do
23
+ Telapi.config do |config|
24
+ config.ssl_ca_path = '/something/else'
25
+ end
26
+
27
+ subject.ssl_ca_path.should == '/something/else'
28
+ end
29
+ end
30
+
31
+ context "inspection" do
32
+ %w(to_s inspect).each do |method|
33
+ it "returns a hash of options via #{method}" do
34
+ subject.send(method.to_sym).should be_a(Hash)
35
+ end
36
+ end
37
+ end
38
+ end