tropo-provisioning 0.0.20

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.
@@ -0,0 +1,77 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "TropoProvisioning" do
4
+ before(:all) do
5
+ @app_details = { :voiceUrl => 'http://mydomain.com/voice_script.rb',
6
+ :partition => 'staging',
7
+ :messagingUrl => 'http://mydomain.com/message_script.rb',
8
+ :platform => 'scripting' }
9
+ @tp = TropoProvisioning.new('jsgoecke', 'test123')
10
+ end
11
+
12
+ after(:all) do
13
+
14
+ end
15
+
16
+ it "should create an application" do
17
+ result = @tp.create_application(@app_details.merge!({ :name => 'Live API Test' }))
18
+ result.href.should =~ /^http:\/\/api.tropo.com\/provisioning\/applications\/\d{1,7}$/
19
+ result.application_id.should =~ /\d{1,7}/
20
+ APPLICATION_ID = result.application_id
21
+ end
22
+
23
+ it "should get a list of exchanges" do
24
+ exchanges = @tp.exchanges
25
+ exchanges[0].city.should == 'Houston'
26
+ end
27
+
28
+ it "should add a phone, IM and token address to the application" do
29
+ result = @tp.create_address(APPLICATION_ID, { :type => 'number', :prefix => @tp.exchanges[0].prefix })
30
+ result.href.should =~ /http:\/\/api.tropo.com\/provisioning\/applications\/\d{1,7}\/addresses\/number\/\d{1,20}/
31
+
32
+ result = @tp.create_address(APPLICATION_ID, { :type => 'jabber', :username => "liveapitest#{rand(100000).to_s}@bot.im" } )
33
+ result.href.should =~ /http:\/\/api.tropo.com\/provisioning\/applications\/\d{1,7}\/addresses\/jabber\/\w{10,16}@bot.im/
34
+
35
+ result = @tp.create_address(APPLICATION_ID, { :type => 'token', :channel => 'voice' } )
36
+ result.href.should =~ /http:\/\/api.tropo.com\/provisioning\/applications\/\d{1,7}\/addresses\/token\/\w{88}/
37
+ end
38
+
39
+ it "should update the application" do
40
+ # First, get the application in question
41
+ app_data = @tp.application(APPLICATION_ID)
42
+ app_data['name'] = 'Live API Test Update'
43
+ result = @tp.update_application(APPLICATION_ID, app_data)
44
+ result.href.should =~ /^http:\/\/api.tropo.com\/provisioning\/applications\/\d{1,7}$/
45
+ end
46
+
47
+ it "should move a address to a new application and then back" do
48
+ new_app = @tp.create_application(@app_details.merge!({ :name => 'Live API Test New' }))
49
+ new_app.href.should =~ /^http:\/\/api.tropo.com\/provisioning\/applications\/\d{1,7}$/
50
+ new_address = @tp.create_address(new_app.application_id, { :type => 'number', :prefix => @tp.exchanges[0]['prefix'] })
51
+
52
+ result = @tp.move_address({ :from => APPLICATION_ID,
53
+ :to => new_app,
54
+ :address => new_address.address })
55
+ result.should == nil
56
+
57
+ result = @tp.move_address({ :from => new_app,
58
+ :to => APPLICATION_ID,
59
+ :address => new_address.address })
60
+ result.should == nil
61
+ end
62
+
63
+ # it "should delete the addresses of an application" do
64
+ # addresses = @tp.addresses(APPLICATION_ID)
65
+ # addresses.each do |address|
66
+ # result = @tp.delete_address(APPLICATION_ID, address['number']) if address['number']
67
+ # result.message.should == 'delete successful'
68
+ # result = @tp.delete_address(APPLICATION_ID, address['username']) if address['username']
69
+ # result.message.should == 'delete successful'
70
+ # end
71
+ # end
72
+ #
73
+ # it "should delete an application" do
74
+ # result = @tp.delete_application(APPLICATION_ID)
75
+ # result.message.should == 'delete successful'
76
+ # end
77
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'tropo-provisioning'
4
+ require 'rspec'
5
+ require 'rspec/autorun'
6
+ require 'fakeweb'
7
+
8
+ RSpec.configure do |config|
9
+
10
+ end
@@ -0,0 +1,1168 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ # These tests are all local unit tests
4
+ FakeWeb.allow_net_connect = false
5
+
6
+ describe "TropoProvisioning" do
7
+ before(:all) do
8
+ @applications = [ { "voiceUrl" => "http://webhosting.voxeo.net/1234/www/simple.js",
9
+ "name" => "API Test",
10
+ "href" => "http://api.tropo.com/v1/applications/108000",
11
+ "partition" => "staging",
12
+ "platform" => "scripting" },
13
+ { "voiceUrl" => "http://hosting.tropo.com/1234/www/simon.rb",
14
+ "name" => "Simon Game",
15
+ "href" => "http://api.tropo.com/v1/applications/105838",
16
+ "partition" => "staging",
17
+ "messagingUrl" => "http://hosting.tropo.com/1234/www/simon.rb",
18
+ "platform" => "scripting" },
19
+ { "voiceUrl" => "http://webhosting.voxeo.net/1234/www/simple.js",
20
+ "name" => "Foobar",
21
+ "href" => "http://api.tropo.com/v1/applications/108002",
22
+ "partition" => "staging",
23
+ "platform" => "scripting" } ]
24
+
25
+ @addresses = [ { "region" => "I-US",
26
+ "city" => "iNum US",
27
+ "number" => "883510001812716",
28
+ "href" => "http://api.tropo.com/v1/applications/108000/addresses/number/883510001812716",
29
+ "prefix" => "008",
30
+ "type" => "number" },
31
+ { "number" => "9991436301",
32
+ "href" => "http://api.tropo.com/v1/applications/108000/addresses/pin/9991436300",
33
+ "type" => "pin" },
34
+ { "href" => "http://api.tropo.com/v1/applications/108000/addresses/jabber/xyz123",
35
+ "nickname" => "",
36
+ "username" => "xyz123",
37
+ "type" => "jabber" },
38
+ { "href" => "http://api.tropo.com/v1/applications/108000/addresses/jabber/xyz123",
39
+ "nickname" => "",
40
+ "username" => "9991436300",
41
+ "type" => "pin" },
42
+ { "href" => "http://api.tropo.com/v1/applications/108000/addresses/token/a1b2c3d4",
43
+ "nickname" => "",
44
+ "username" => "a1b2c3d4",
45
+ "type" => "token" } ]
46
+
47
+ @exchanges = '[
48
+ {
49
+ "prefix":"1407",
50
+ "city":"Orlando",
51
+ "state":"FL",
52
+ "country": "United States"
53
+ },
54
+ {
55
+ "prefix":"1312",
56
+ "city":"Chicago",
57
+ "state":"IL",
58
+ "country":"United States"
59
+ },
60
+ {
61
+ "prefix":"1303",
62
+ "city":"Denver",
63
+ "state":"CO",
64
+ "country":"United States"
65
+ },
66
+ {
67
+ "prefix":"1310",
68
+ "city": "Los Angeles",
69
+ "state":"CA",
70
+ "country":"United States"
71
+ },
72
+ {
73
+ "prefix": "1412",
74
+ "city":"Pittsburgh",
75
+ "state":"PA",
76
+ "country": "United States"
77
+ },
78
+ {
79
+ "prefix":"1415",
80
+ "city":"San Francisco",
81
+ "state": "CA",
82
+ "country":"United States"
83
+ },
84
+ {
85
+ "prefix":"1206",
86
+ "city": "Seattle",
87
+ "state":"WA",
88
+ "country":"United States"
89
+ },
90
+ {
91
+ "prefix": "1301",
92
+ "city":"Washington",
93
+ "state":"DC",
94
+ "country": "United States"
95
+ }
96
+ ]'
97
+
98
+ @new_user = { 'user_id' => "12345", 'href' => "http://api.tropo.com/v1/users/12345", 'confirmation_key' => '1234' }
99
+ @new_user_json = ActiveSupport::JSON.encode({ 'user_id' => "12345", 'href' => "http://api.tropo.com/v1/users/12345", 'confirmationKey' => '1234' })
100
+ @existing_user = { "city" => "Orlando",
101
+ "address" => "1234 Anywhere St",
102
+ "href" => "https://api-smsified-eng.voxeo.net/v1/users/12345",
103
+ "lastName" => "User",
104
+ "address2" => "Unit 1337",
105
+ "joinDate" => "2010-05-17T18:26:07.217+0000",
106
+ "country" => "USA",
107
+ "username" => "foo",
108
+ "phoneNumber" => "4075551212",
109
+ "id" => "12345",
110
+ "postalCode" => "32801",
111
+ "jobTitle" => "Technical Writer",
112
+ "firstName" => "Tropo",
113
+ "organization" => "Voxeo",
114
+ "status" => "active",
115
+ "email" => "support@tropo.com"}
116
+
117
+
118
+ @list_account = { 'account_id' => "12345", 'href' => "http://api-eng.voxeo.net:8080/v1/users/12345" }
119
+
120
+ @payment_method = { "rechargeAmount" => "0.00",
121
+ "paymentType" => "https://api-smsified-eng.voxeo.net/v1/types/payment/1",
122
+ "accountNumber" => "5555",
123
+ "paymentTypeName" => "visa",
124
+ "rechargeThreshold" => "0.00",
125
+ "id" => "1" }
126
+
127
+ @payment_methods = [ { "name" => "visa",
128
+ "href" => "https://api-smsified-eng.voxeo.net/v1/types/payment/1",
129
+ "id" => "1" },
130
+ { "name" => "mastercard",
131
+ "href" => "https://api-smsified-eng.voxeo.net/v1/types/payment/2",
132
+ "id" => "2" },
133
+ { "name" => "amex",
134
+ "href" => "https://api-smsified-eng.voxeo.net/v1/types/payment/3",
135
+ "id" => "3" }]
136
+
137
+ @features = [ { "name" => "International Outbound SMS",
138
+ "href" => "https://api-smsified-eng.voxeo.net/v1/features/9",
139
+ "id" => "9",
140
+ "description" => "International Outbound SMS" },
141
+ { "name" => "Test Outbound SMS",
142
+ "href" => "https://api-smsified-eng.voxeo.net/v1/features/7",
143
+ "id" => "7",
144
+ "description" => "Test Outbound SMS" },
145
+ { "name" => "Domestic Outbound SMS",
146
+ "href" => "https://api-smsified-eng.voxeo.net/v1/features/8",
147
+ "id" => "8",
148
+ "description" => "Domestic Outbound SMS" } ]
149
+
150
+ @user_features = [ { "feature" => "https://api-smsified-eng.voxeo.net/v1/features/7",
151
+ "href" => "https://api-smsified-eng.voxeo.net/v1/users/12345/features/7",
152
+ "featureName" => "Test Outbound SMS" } ]
153
+
154
+ @feature = { 'href' => 'http://api-smsified-eng.voxeo.net/v1/users/12345/features/8' }
155
+
156
+ @feature_delete_message = { "message" => "disabled feature https://api-smsified-eng.voxeo.net/v1/features/8 for user https://api-smsified-eng.voxeo.net/v1/users/12345" }
157
+
158
+ @payment_info_message = { "href" => "http://api-smsified-eng.voxeo.net/v1/users/12345/payment/method" }
159
+
160
+ @bad_account_creds = { "account-accesstoken-get-response" =>
161
+ { "accessToken" => "",
162
+ "statusMessage" => "Invalid login.",
163
+ "statusCode" => 403 } }
164
+
165
+ @search_accounts = [ { "href" => "http://api-smsified-eng.voxeo.net/v1/users/53209",
166
+ "marketingOptIn" => true,
167
+ "lastName" => "Empty LastName",
168
+ "joinDate" => "2010-11-15T21:13:23.837+0000",
169
+ "username" => "foobar5331",
170
+ "id" => "53209",
171
+ "phoneNumber" => "Empty Phone",
172
+ "firstName" => "Empty FirstName",
173
+ "status" => "active",
174
+ "email" => "jsgoecke@voxeo.com"},
175
+ { "href" => "http://api-smsified-eng.voxeo.net/v1/users/53211",
176
+ "marketingOptIn" => true,
177
+ "lastName" => "Empty LastName",
178
+ "joinDate" => "2010-11-15T21:17:24.473+0000",
179
+ "username" => "foobar1197",
180
+ "id" => "53211",
181
+ "phoneNumber" => "Empty Phone",
182
+ "firstName" => "Empty FirstName",
183
+ "status" => "active",
184
+ "email" => "jsgoecke@voxeo.com" } ]
185
+
186
+ @partitions = [{ "name" => "staging", "href" => "https://api-smsified-eng.voxeo.net/v1/partitions/staging" },
187
+ { "name" => "production", "href" => "https://api-smsified-eng.voxeo.net/v1/partitions/production" }]
188
+
189
+ @platforms = [{ "name" => "sms", "href" => "https://api-smsified-eng.voxeo.net/v1/platforms/sms", "description" => "SMSified Interface" }]
190
+
191
+ @balance = { "pendingUsageAmount" => "0.00", "pendingRechargeAmount" => "0.00", "balance" => "3.00" }
192
+
193
+ @whitelist = [{ "href" => "https://api-smsified-eng.voxeo.net/v1/partitions/staging/platforms/sms/whitelist/14075551212", "value"=>"14075551212" }]
194
+
195
+ @countries = [{ "name"=>"Zimbabwe", "href"=>"http://api-smsified-eng.voxeo.net/v1/countries/426", "code"=>"ZW", "id" => "426" },
196
+ { "name"=>"United States", "href"=>"http://api-smsified-eng.voxeo.net/v1/countries/36", "code"=>"US", "states"=>"http://api-smsified-eng.voxeo.net/v1/countries/36/states", "id" => "36" }]
197
+
198
+ @states = [{ "name"=>"Wisconsin", "href"=>"http://api-smsified-eng.voxeo.net/v1/countries/36/states/49", "code"=>"WI", "id" => "49" },
199
+ { "name"=>"Wyoming", "href"=>"http://api-smsified-eng.voxeo.net/v1/countries/36/states/50", "code"=>"WY", "id"=>"50" }]
200
+
201
+ @recurrence = { 'rechargeAmount' => 13.50, 'rechargeThreshold' => 10.00 }
202
+ @recurrence_updated = { 'href' => 'http://api-smsified-eng.voxeo.net/v1/users/1234/payment/recurrence' }
203
+
204
+ # Register our resources
205
+
206
+ # Applications with a bad uname/passwd
207
+ FakeWeb.register_uri(:get,
208
+ %r|http://bad:password@api.tropo.com/v1/applications|,
209
+ :status => ["401", "Unauthorized"])
210
+
211
+ # A specific application
212
+ FakeWeb.register_uri(:get,
213
+ "http://foo:bar@api.tropo.com/v1/applications/108000",
214
+ :body => ActiveSupport::JSON.encode(@applications[0]),
215
+ :content_type => "application/json")
216
+
217
+ # Applications
218
+ FakeWeb.register_uri(:get,
219
+ %r|http://foo:bar@api.tropo.com/v1/applications|,
220
+ :body => ActiveSupport::JSON.encode(@applications),
221
+ :content_type => "application/json")
222
+
223
+ # Create an application
224
+ FakeWeb.register_uri(:post,
225
+ %r|http://foo:bar@api.tropo.com/v1/applications|,
226
+ :body => ActiveSupport::JSON.encode({ "href" => "http://api.tropo.com/v1/applications/108016" }),
227
+ :status => ["200", "OK"])
228
+
229
+ # Update a specific application
230
+ FakeWeb.register_uri(:put,
231
+ %r|http://foo:bar@api.tropo.com/v1/applications/108000|,
232
+ :body => ActiveSupport::JSON.encode({ "href" => "http://api.tropo.com/v1/applications/108016" }),
233
+ :status => ["200", "OK"])
234
+
235
+ # Addresses
236
+ FakeWeb.register_uri(:get,
237
+ "http://foo:bar@api.tropo.com/v1/applications/108000/addresses",
238
+ :body => ActiveSupport::JSON.encode(@addresses),
239
+ :content_type => "application/json")
240
+
241
+ # Get a specific address
242
+ FakeWeb.register_uri(:get,
243
+ "http://foo:bar@api.tropo.com/v1/applications/108000/addresses/number/883510001812716",
244
+ :body => ActiveSupport::JSON.encode(@addresses[0]),
245
+ :content_type => "application/json")
246
+
247
+ # Get a address that is an IM/username
248
+ FakeWeb.register_uri(:get,
249
+ "http://foo:bar@api.tropo.com/v1/applications/108000/addresses/jabber/xyz123",
250
+ :body => ActiveSupport::JSON.encode(@addresses[2]),
251
+ :content_type => "application/json")
252
+
253
+ # Get a address that is a token
254
+ FakeWeb.register_uri(:get,
255
+ "http://foo:bar@api.tropo.com/v1/applications/108000/addresses/jabber/xyz123",
256
+ :body => ActiveSupport::JSON.encode(@addresses[2]),
257
+ :content_type => "application/json")
258
+
259
+ # Get a address that is a Pin
260
+ FakeWeb.register_uri(:post,
261
+ "http://foo:bar@api.tropo.com/v1/applications/108000/addresses",
262
+ :body => ActiveSupport::JSON.encode(@addresses[2]),
263
+ :content_type => "application/json")
264
+
265
+ # Get a address that is a token
266
+ FakeWeb.register_uri(:get,
267
+ "http://foo:bar@api.tropo.com/v1/applications/108000/addresses/token/a1b2c3d4",
268
+ :body => ActiveSupport::JSON.encode(@addresses[4]),
269
+ :content_type => "application/json")
270
+
271
+ # Get a address that is a number
272
+ FakeWeb.register_uri(:post,
273
+ "http://foo:bar@api.tropo.com/v1/applications/108000/addresses",
274
+ :body => ActiveSupport::JSON.encode({ "href" => "http://api.tropo.com/v1/applications/108000/addresses/number/7202551912" }),
275
+ :content_type => "application/json")
276
+
277
+ # Create a address that is an IM account
278
+ FakeWeb.register_uri(:post,
279
+ "http://foo:bar@api.tropo.com/v1/applications/108001/addresses",
280
+ :body => ActiveSupport::JSON.encode({ "href" => "http://api.tropo.com/v1/applications/108001/addresses/jabber/xyz123@bot.im" }),
281
+ :content_type => "application/json")
282
+
283
+ # Create a address that is a Token
284
+ FakeWeb.register_uri(:post,
285
+ "http://foo:bar@api.tropo.com/v1/applications/108002/addresses",
286
+ :body => ActiveSupport::JSON.encode({ "href" => "http://api.tropo.com/v1/applications/108002/addresses/token/12345679f90bac47a05b178c37d3c68aaf38d5bdbc5aba0c7abb12345d8a9fd13f1234c1234567dbe2c6f63b" }),
287
+ :content_type => "application/json")
288
+
289
+ # Delete an application
290
+ FakeWeb.register_uri(:delete,
291
+ "http://foo:bar@api.tropo.com/v1/applications/108000",
292
+ :body => ActiveSupport::JSON.encode({ 'message' => 'delete successful' }),
293
+ :content_type => "application/json",
294
+ :status => ["200", "OK"])
295
+
296
+ # Exchanges
297
+ FakeWeb.register_uri(:get,
298
+ "http://foo:bar@api.tropo.com/v1/exchanges",
299
+ :body => @exchanges,
300
+ :status => ["200", "OK"],
301
+ :content_type => "application/json")
302
+
303
+ # Delete a address
304
+ FakeWeb.register_uri(:delete,
305
+ "http://foo:bar@api.tropo.com/v1/applications/108000/addresses/number/883510001812716",
306
+ :body => ActiveSupport::JSON.encode({ 'message' => 'delete successful' }),
307
+ :content_type => "application/json",
308
+ :status => ["200", "OK"])
309
+
310
+ # Add a specific address
311
+ FakeWeb.register_uri(:post,
312
+ "http://foo:bar@api.tropo.com/v1/applications/108002/addresses/number/883510001812716",
313
+ :body => ActiveSupport::JSON.encode({ 'message' => 'delete successful' }),
314
+ :content_type => "application/json",
315
+ :status => ["200", "OK"])
316
+
317
+ # Create a new user
318
+ FakeWeb.register_uri(:post,
319
+ "http://foo:bar@api.tropo.com/v1/users",
320
+ :body => @new_user_json,
321
+ :content_type => "application/json",
322
+ :status => ["200", "OK"])
323
+
324
+ # Get a specific user by user_id
325
+ FakeWeb.register_uri(:get,
326
+ "http://foo:bar@api.tropo.com/v1/users/12345",
327
+ :body => ActiveSupport::JSON.encode(@existing_user),
328
+ :content_type => "application/json",
329
+ :status => ["200", "OK"])
330
+
331
+ # Get a specific user by user_id
332
+ FakeWeb.register_uri(:get,
333
+ "http://foo:bar@api.tropo.com/v1/users/98765",
334
+ :body => nil,
335
+ :content_type => "application/json",
336
+ :status => ["404", "Got an error here!"])
337
+
338
+ # Get a specific user by username
339
+ FakeWeb.register_uri(:get,
340
+ "http://foo:bar@api.tropo.com/v1/users/foo",
341
+ :body => ActiveSupport::JSON.encode(@existing_user),
342
+ :content_type => "application/json",
343
+ :status => ["200", "OK"])
344
+
345
+ # Get a specific user by username with HTTPS/SSL
346
+ FakeWeb.register_uri(:get,
347
+ "https://foo:bar@api.tropo.com/v1/users/foo",
348
+ :body => ActiveSupport::JSON.encode(@existing_user),
349
+ :content_type => "application/json",
350
+ :status => ["200", "OK"])
351
+
352
+ # Invalid credentials
353
+ FakeWeb.register_uri(:get,
354
+ "http://bad:password@api.tropo.com/v1/users/bad",
355
+ :content_type => "application/json",
356
+ :status => ["401", "Unauthorized"])
357
+
358
+ # Confirm an account account
359
+ FakeWeb.register_uri(:post,
360
+ "http://foo:bar@api.tropo.com/v1/users/12345/confirmations",
361
+ :body => ActiveSupport::JSON.encode({"message" => "successfully confirmed user 12345" }),
362
+ :content_type => "application/json",
363
+ :status => ["200", "OK"])
364
+
365
+ # Return the payment method configured for a user
366
+ FakeWeb.register_uri(:get,
367
+ "http://foo:bar@api.tropo.com/v1/users/12345/payment/method",
368
+ :body => ActiveSupport::JSON.encode(@payment_method),
369
+ :content_type => "application/json",
370
+ :status => ["200", "OK"])
371
+
372
+ # Return payment types
373
+ FakeWeb.register_uri(:get,
374
+ "http://foo:bar@api.tropo.com/v1/types/payment",
375
+ :body => ActiveSupport::JSON.encode(@payment_methods),
376
+ :content_type => "application/json",
377
+ :status => ["200", "OK"])
378
+
379
+ # Return features
380
+ FakeWeb.register_uri(:get,
381
+ "http://foo:bar@api.tropo.com/v1/features",
382
+ :body => ActiveSupport::JSON.encode(@features),
383
+ :content_type => "application/json",
384
+ :status => ["200", "OK"])
385
+
386
+ # Return features for a user
387
+ FakeWeb.register_uri(:get,
388
+ "http://foo:bar@api.tropo.com/v1/users/12345/features",
389
+ :body => ActiveSupport::JSON.encode(@user_features),
390
+ :content_type => "application/json",
391
+ :status => ["200", "OK"])
392
+
393
+ # Add a feature to a user
394
+ FakeWeb.register_uri(:post,
395
+ "http://foo:bar@api.tropo.com/v1/users/12345/features",
396
+ :body => ActiveSupport::JSON.encode(@feature),
397
+ :content_type => "application/json",
398
+ :status => ["200", "OK"])
399
+
400
+ # Add a feature to a user
401
+ FakeWeb.register_uri(:delete,
402
+ "http://foo:bar@api.tropo.com/v1/users/12345/features/8",
403
+ :body => ActiveSupport::JSON.encode(@feature_delete_message),
404
+ :content_type => "application/json",
405
+ :status => ["200", "OK"])
406
+
407
+ # Add payment info to a user
408
+ FakeWeb.register_uri(:put,
409
+ "http://foo:bar@api.tropo.com/v1/users/12345/payment/method",
410
+ :body => ActiveSupport::JSON.encode(@payment_info_message),
411
+ :content_type => "application/json",
412
+ :status => ["200", "OK"])
413
+
414
+
415
+ # List an account, with bad credentials
416
+ FakeWeb.register_uri(:get,
417
+ "http://evolution.voxeo.com/api/account/accesstoken/get.jsp?username=foobar7474&password=fooeyfooey",
418
+ :body => ActiveSupport::JSON.encode(@bad_account_creds),
419
+ :content_type => "application/json",
420
+ :status => ["403", "Invalid Login."])
421
+
422
+ # Get our search terms
423
+ FakeWeb.register_uri(:get,
424
+ "http://foo:bar@api.tropo.com/v1/users/?username=foobar",
425
+ :body => ActiveSupport::JSON.encode(@search_accounts),
426
+ :content_type => "application/json",
427
+ :status => ["200", "OK"])
428
+
429
+ # Payment resource
430
+ FakeWeb.register_uri(:post,
431
+ "http://foo:bar@api.tropo.com/v1/users/1234/payments",
432
+ :body => ActiveSupport::JSON.encode({ :message => "successfully posted payment for the amount 1.000000" }),
433
+ :content_type => "application/json",
434
+ :status => ["200", "OK"])
435
+
436
+ # Modify a user
437
+ FakeWeb.register_uri(:put,
438
+ "http://foo:bar@api.tropo.com/v1/users/12345",
439
+ :body => ActiveSupport::JSON.encode({ :href => "http://api-smsified-eng.voxeo.net/v1/users/12345" }),
440
+ :content_type => "application/json",
441
+ :status => ["200", "OK"])
442
+
443
+ # List available partitions
444
+ FakeWeb.register_uri(:get,
445
+ "http://foo:bar@api.tropo.com/v1/partitions",
446
+ :body => ActiveSupport::JSON.encode(@partitions),
447
+ :content_type => "application/json",
448
+ :status => ["200", "OK"])
449
+
450
+ # List available platforms
451
+ FakeWeb.register_uri(:get,
452
+ "http://foo:bar@api.tropo.com/v1/partitions/staging/platforms",
453
+ :body => ActiveSupport::JSON.encode(@platforms),
454
+ :content_type => "application/json",
455
+ :status => ["200", "OK"])
456
+
457
+ # List balance
458
+ FakeWeb.register_uri(:get,
459
+ "http://foo:bar@api.tropo.com/v1/users/12345/usage",
460
+ :body => ActiveSupport::JSON.encode(@balance),
461
+ :content_type => "application/json",
462
+ :status => ["200", "OK"])
463
+
464
+ # Whitelist
465
+ FakeWeb.register_uri(:get,
466
+ "http://foo:bar@api.tropo.com/v1/users/12345/partitions/production/platforms/sms/whitelist",
467
+ :body => ActiveSupport::JSON.encode(@whitelist),
468
+ :content_type => "application/json",
469
+ :status => ["200", "OK"])
470
+ # Whitelist
471
+ FakeWeb.register_uri(:get,
472
+ "http://foo:bar@api.tropo.com/v1/users/partitions/production/platforms/sms/whitelist",
473
+ :body => ActiveSupport::JSON.encode(@whitelist),
474
+ :content_type => "application/json",
475
+ :status => ["200", "OK"])
476
+
477
+ # Whitelist create
478
+ FakeWeb.register_uri(:post,
479
+ "http://foo:bar@api.tropo.com/v1/users/12345/partitions/production/platforms/sms/whitelist",
480
+ :body => ActiveSupport::JSON.encode(@whitelist),
481
+ :content_type => "application/json",
482
+ :status => ["200", "OK"])
483
+ # Whitelist delete
484
+ FakeWeb.register_uri(:delete,
485
+ "http://foo:bar@api.tropo.com/v1/users/12345/partitions/production/platforms/sms/whitelist/14155551212",
486
+ :body => ActiveSupport::JSON.encode(@whitelist),
487
+ :content_type => "application/json",
488
+ :status => ["200", "OK"])
489
+
490
+ # Countries
491
+ FakeWeb.register_uri(:get,
492
+ "http://foo:bar@api.tropo.com/v1/countries",
493
+ :body => ActiveSupport::JSON.encode(@countries),
494
+ :content_type => "application/json",
495
+ :status => ["200", "OK"])
496
+
497
+ # States
498
+ FakeWeb.register_uri(:get,
499
+ "http://foo:bar@api.tropo.com/v1/countries/36/states",
500
+ :body => ActiveSupport::JSON.encode(@states),
501
+ :content_type => "application/json",
502
+ :status => ["200", "OK"])
503
+
504
+ # Recurrency get
505
+ FakeWeb.register_uri(:get,
506
+ "http://foo:bar@api.tropo.com/v1/users/1234/payment/recurrence",
507
+ :body => ActiveSupport::JSON.encode(@recurrence),
508
+ :content_type => "application/json",
509
+ :status => ["200", "OK"])
510
+
511
+ # Recurrency update
512
+ FakeWeb.register_uri(:put,
513
+ "http://foo:bar@api.tropo.com/v1/users/1234/payment/recurrence",
514
+ :body => ActiveSupport::JSON.encode(@recurrence_updated),
515
+ :content_type => "application/json",
516
+ :status => ["200", "OK"])
517
+
518
+ @invitation_created = { 'href' => "http://api-smsified-eng.voxeo.net/v1/invitations/ABC457" }
519
+ @deleted_invitation = { 'message' => "deleted invitation at uri http://api-smsified-eng.voxeo.net/v1/invitations/ABC457" }
520
+ @invitations = [ { 'code' => "ABC456", 'count' => 100, 'credit' => "10.00", 'href' => "http://api-smsified-eng.voxeo.net/v1/invitations/ABC456" },
521
+ { 'code' => "ABC457", 'count' => 100, 'credit' => "10.00", 'href' => "http://api-smsified-eng.voxeo.net/v1/invitations/ABC457" }]
522
+
523
+ # List invitations
524
+ FakeWeb.register_uri(:get,
525
+ "http://foo:bar@api.tropo.com/v1/invitations",
526
+ :body => ActiveSupport::JSON.encode(@invitations),
527
+ :content_type => "application/json",
528
+ :status => ["200", "OK"])
529
+
530
+ # Get an invitation
531
+ FakeWeb.register_uri(:get,
532
+ "http://foo:bar@api.tropo.com/v1/invitations/ABC457",
533
+ :body => ActiveSupport::JSON.encode(@invitations[1]),
534
+ :content_type => "application/json",
535
+ :status => ["200", "OK"])
536
+
537
+ # Update an invitation
538
+ FakeWeb.register_uri(:put,
539
+ "http://foo:bar@api.tropo.com/v1/invitations/ABC457",
540
+ :body => ActiveSupport::JSON.encode(@invitation_created),
541
+ :content_type => "application/json",
542
+ :status => ["200", "OK"])
543
+
544
+ # Update an invitation
545
+ FakeWeb.register_uri(:put,
546
+ "http://foo:bar@api.tropo.com/v1/users/15909/invitations/ABC457",
547
+ :body => ActiveSupport::JSON.encode(@invitation_created),
548
+ :content_type => "application/json",
549
+ :status => ["200", "OK"])
550
+
551
+ # Delete an invitation
552
+ FakeWeb.register_uri(:delete,
553
+ "http://foo:bar@api.tropo.com/v1/invitations/ABC457",
554
+ :body => ActiveSupport::JSON.encode(@deleted_invitation),
555
+ :content_type => "application/json",
556
+ :status => ["200", "OK"])
557
+
558
+ # Delete an invitation
559
+ FakeWeb.register_uri(:delete,
560
+ "http://foo:bar@api.tropo.com/v1/users/15909/invitations/ABC457",
561
+ :body => ActiveSupport::JSON.encode(@deleted_invitation),
562
+ :content_type => "application/json",
563
+ :status => ["200", "OK"])
564
+
565
+ # Create invitation
566
+ FakeWeb.register_uri(:post,
567
+ "http://foo:bar@api.tropo.com/v1/invitations",
568
+ :body => ActiveSupport::JSON.encode(@invitation_created),
569
+ :content_type => "application/json",
570
+ :status => ["200", "OK"])
571
+
572
+ # Create invitation
573
+ FakeWeb.register_uri(:post,
574
+ "http://foo:bar@api.tropo.com/v1/users/15909/invitations",
575
+ :body => ActiveSupport::JSON.encode(@invitation_created),
576
+ :content_type => "application/json",
577
+ :status => ["200", "OK"])
578
+
579
+ # List invitation for a user
580
+ FakeWeb.register_uri(:get,
581
+ "http://foo:bar@api.tropo.com/v1/users/15909/invitations",
582
+ :body => ActiveSupport::JSON.encode([@invitation_created]),
583
+ :content_type => "application/json",
584
+ :status => ["200", "OK"])
585
+
586
+ # List invitation for a user via SSL
587
+ FakeWeb.register_uri(:get,
588
+ "https://foo:bar@api.tropo.com/v1/invitations",
589
+ :body => ActiveSupport::JSON.encode(@invitations),
590
+ :content_type => "application/json",
591
+ :status => ["200", "OK"])
592
+
593
+ # List invitation for a user
594
+ FakeWeb.register_uri(:get,
595
+ "http://foo:bar@api.tropo.com/v1/users/15909/invitations/ABC457",
596
+ :body => ActiveSupport::JSON.encode(@invitations[1]),
597
+ :content_type => "application/json",
598
+ :status => ["200", "OK"])
599
+
600
+ @username_check = { 'available' => false, 'href' => "http://api.smsified.com/v1/usernames/jsgoecke", 'valid' => true }
601
+ # List invitation for a user
602
+ FakeWeb.register_uri(:get,
603
+ "http://foo:bar@api.tropo.com/v1/usernames/12345",
604
+ :body => ActiveSupport::JSON.encode(@username_check),
605
+ :content_type => "application/json",
606
+ :status => ["200", "OK"])
607
+ end
608
+
609
+ before(:each) do
610
+ @tropo_provisioning = TropoProvisioning.new('foo', 'bar')
611
+ end
612
+
613
+ it "should create a TropoProvisioning object" do
614
+ @tropo_provisioning.instance_of?(TropoProvisioning).should == true
615
+ end
616
+
617
+ describe 'authentication' do
618
+ it "should get an unathorized back if there is an invalid username or password" do
619
+ begin
620
+ bad_credentials = TropoProvisioning.new('bad', 'password')
621
+ rescue => e
622
+ e.to_s.should == '401: Unauthorized - '
623
+ end
624
+ end
625
+
626
+ it 'should have the user data on the object if a successful login' do
627
+ provisioning = TropoProvisioning.new('foo', 'bar')
628
+ provisioning.user_data['username'].should == 'foo'
629
+ end
630
+
631
+ it "should not provide a token for an existing account if wrong credentials" do
632
+ pending('Need to work on tests for the new account')
633
+ begin
634
+ result = @tropo_provisioning.account("foobar7474", 'fooeyfooey')
635
+ rescue => e
636
+ e.to_s.should == "403 - Invalid Login."
637
+ end
638
+ end
639
+
640
+ it "should provide a token for an existing account" do
641
+ pending('Need to work on tests for the new account')
642
+ result = @tropo_provisioning.account("foobar7474", 'fooey')
643
+ result.should == @list_account
644
+ end
645
+ end
646
+
647
+ describe 'applications' do
648
+ it "should get a list of applications" do
649
+ applications = []
650
+ @applications.each { |app| applications << app.merge({ 'application_id' => app['href'].split('/').last }) }
651
+
652
+ @tropo_provisioning.applications.should == applications
653
+ end
654
+
655
+ it "should get a specific application" do
656
+ response = @tropo_provisioning.application '108000'
657
+ response['href'].should == @applications[0]['href']
658
+ end
659
+
660
+ it "should raise ArgumentErrors if appropriate arguments are not specified" do
661
+ begin
662
+ @tropo_provisioning.create_application({ :foo => 'bar' })
663
+ rescue => e
664
+ e.to_s.should == ':name is a required parameter'
665
+ end
666
+ end
667
+
668
+ it "should raise ArgumentErrors if appropriate values are not passed" do
669
+ begin
670
+ @tropo_provisioning.create_application({ :name => 'foobar',
671
+ :partition => 'foobar',
672
+ :platform => 'foobar',
673
+ :messagingUrl => 'http://foobar' })
674
+ rescue => e
675
+ e.to_s.should == ":platform must be 'scripting' or 'webapi'"
676
+ end
677
+
678
+ begin
679
+ @tropo_provisioning.create_application({ :name => 'foobar',
680
+ :partition => 'foobar',
681
+ :platform => 'scripting',
682
+ :messagingUrl => 'http://foobar' })
683
+ rescue => e
684
+ e.to_s.should == ":partiion must be 'staging' or 'production'"
685
+ end
686
+ end
687
+
688
+ it "should receive an href back when we create a new application receiving an href back" do
689
+ # With camelCase
690
+ result = @tropo_provisioning.create_application({ :name => 'foobar',
691
+ :partition => 'production',
692
+ :platform => 'scripting',
693
+ :messagingUrl => 'http://foobar' })
694
+ result.href.should == "http://api.tropo.com/v1/applications/108016"
695
+ result.application_id.should == '108016'
696
+
697
+ # With underscores
698
+ result = @tropo_provisioning.create_application({ :name => 'foobar',
699
+ :partition => 'production',
700
+ :platform => 'scripting',
701
+ :messaging_url => 'http://foobar' })
702
+ result.href.should == "http://api.tropo.com/v1/applications/108016"
703
+ result.application_id.should == '108016'
704
+ end
705
+
706
+ it "should receive an href back when we update an application receiving an href back" do
707
+ # With camelCase
708
+ result = @tropo_provisioning.update_application('108000', { :name => 'foobar',
709
+ :partition => 'production',
710
+ :platform => 'scripting',
711
+ :messagingUrl => 'http://foobar' })
712
+ result.href.should == "http://api.tropo.com/v1/applications/108016"
713
+
714
+ # With underscore
715
+ result = @tropo_provisioning.update_application('108000', { :name => 'foobar',
716
+ :partition => 'production',
717
+ :platform => 'scripting',
718
+ :messaging_url => 'http://foobar' })
719
+ result.href.should == "http://api.tropo.com/v1/applications/108016"
720
+ end
721
+
722
+ it "should delete an application" do
723
+ result = @tropo_provisioning.delete_application('108000')
724
+ result.message.should == 'delete successful'
725
+ end
726
+ end
727
+
728
+ describe 'addresses' do
729
+ it "should list all of the addresses available for an application" do
730
+ result = @tropo_provisioning.addresses('108000')
731
+ result.should == @addresses
732
+ end
733
+
734
+ it "should list a single address when requested with a number for numbers" do
735
+ result = @tropo_provisioning.address('108000', '883510001812716')
736
+ result.should == @addresses[0]
737
+ end
738
+
739
+ it "should list a single address of the appropriate type when requested" do
740
+ # First a number
741
+ result = @tropo_provisioning.address('108000', '883510001812716')
742
+ result.should == @addresses[0]
743
+
744
+ # Then an IM username
745
+ result = @tropo_provisioning.address('108000', 'xyz123')
746
+ result.should == @addresses[2]
747
+
748
+ # Then a pin
749
+ result = @tropo_provisioning.address('108000', '9991436300')
750
+ result.should == @addresses[3]
751
+
752
+ # Then a token
753
+ result = @tropo_provisioning.address('108000', 'a1b2c3d4')
754
+ result.should == @addresses[4]
755
+ end
756
+
757
+ it "should generate an error of the addition of the address does not have a required field" do
758
+ # Add a address without a type
759
+ begin
760
+ @tropo_provisioning.create_address('108000')
761
+ rescue => e
762
+ e.to_s.should == ":type is a required parameter"
763
+ end
764
+
765
+ # Add a number without a prefix
766
+ begin
767
+ @tropo_provisioning.create_address('108000', { :type => 'number' })
768
+ rescue => e
769
+ e.to_s.should == ":prefix required to add a number address"
770
+ end
771
+
772
+ # Add a jabber without a username
773
+ begin
774
+ @tropo_provisioning.create_address('108000', { :type => 'jabber' })
775
+ rescue => e
776
+ e.to_s.should == ":username is a required parameter"
777
+ end
778
+
779
+ # Add an aim without a password
780
+ begin
781
+ @tropo_provisioning.create_address('108000', { :type => 'aim', :username => 'joeblow@aim.com' })
782
+ rescue => e
783
+ e.to_s.should == ":password is a required parameter"
784
+ end
785
+
786
+ # Add a token without a channel
787
+ begin
788
+ @tropo_provisioning.create_address('108000', { :type => 'token' })
789
+ rescue => e
790
+ e.to_s.should == ":channel is a required parameter"
791
+ end
792
+
793
+ # Add a token with an invalid channel type
794
+ begin
795
+ @tropo_provisioning.create_address('108000', { :type => 'token', :channel => 'BBC' })
796
+ rescue => e
797
+ e.to_s.should == ":channel must be voice or messaging"
798
+ end
799
+ end
800
+
801
+ it "should add appropriate addresses" do
802
+ # Add a address based on a prefix
803
+ result = @tropo_provisioning.create_address('108000', { :type => 'number', :prefix => '1303' })
804
+ result[:href].should == "http://api.tropo.com/v1/applications/108000/addresses/number/7202551912"
805
+ result[:address].should == '7202551912'
806
+
807
+ # Add a jabber account
808
+ result = @tropo_provisioning.create_address('108001', { :type => 'jabber', :username => 'xyz123@bot.im' })
809
+ result[:href].should == "http://api.tropo.com/v1/applications/108001/addresses/jabber/xyz123@bot.im"
810
+ result[:address].should == 'xyz123@bot.im'
811
+
812
+ # Add a token
813
+ result = @tropo_provisioning.create_address('108002', { :type => 'token', :channel => 'voice' })
814
+ result[:href].should == "http://api.tropo.com/v1/applications/108002/addresses/token/12345679f90bac47a05b178c37d3c68aaf38d5bdbc5aba0c7abb12345d8a9fd13f1234c1234567dbe2c6f63b"
815
+ result[:address].should == '12345679f90bac47a05b178c37d3c68aaf38d5bdbc5aba0c7abb12345d8a9fd13f1234c1234567dbe2c6f63b'
816
+ end
817
+
818
+ it "should delete a address" do
819
+ result = @tropo_provisioning.delete_address('108000', '883510001812716')
820
+ result[:message].should == "delete successful"
821
+ end
822
+
823
+ it "should raise an ArgumentError if the right params are not passed to move_address" do
824
+ begin
825
+ @tropo_provisioning.move_address({ :to => '108002', :address => '883510001812716'})
826
+ rescue => e
827
+ e.to_s.should == ':from is a required parameter'
828
+ end
829
+
830
+ begin
831
+ @tropo_provisioning.move_address({ :from => '108002', :address => '883510001812716'})
832
+ rescue => e
833
+ e.to_s.should == ':to is a required parameter'
834
+ end
835
+
836
+ begin
837
+ @tropo_provisioning.move_address({ :from => '108002', :to => '883510001812716'})
838
+ rescue => e
839
+ e.to_s.should == ':address is a required parameter'
840
+ end
841
+ end
842
+
843
+ it "should move a address" do
844
+ results = @tropo_provisioning.move_address({ :from => '108000', :to => '108002', :address => '883510001812716'})
845
+ results.should == { 'message' => 'delete successful' }
846
+ end
847
+
848
+ it "should return accounts with associated addresses" do
849
+ pending()
850
+ result = @tropo_provisioning.account_with_addresses('108000')
851
+ result.should == nil
852
+
853
+ result = @tropo_provisioning.accounts_with_addresses
854
+ result.should == nil
855
+ end
856
+ end
857
+
858
+ describe 'exchanges' do
859
+ it "should obtain a list of available exchanges" do
860
+ results = @tropo_provisioning.exchanges
861
+ results.should == ActiveSupport::JSON.decode(@exchanges)
862
+ end
863
+ end
864
+
865
+ describe 'user' do
866
+ it "should raise argument errors on create_user if required params not passed" do
867
+ begin
868
+ @tropo_provisioning.create_user
869
+ rescue => e
870
+ e.to_s.should == ':username is a required parameter'
871
+ end
872
+
873
+ begin
874
+ @tropo_provisioning.create_user({ :username => "foobar7474" })
875
+ rescue => e
876
+ e.to_s.should == ':password is a required parameter'
877
+ end
878
+
879
+ begin
880
+ @tropo_provisioning.create_user({ :username => "foobar7474", :password => 'fooey' })
881
+ rescue => e
882
+ e.to_s.should == ':email is a required parameter'
883
+ end
884
+ end
885
+
886
+ it "should create a new user" do
887
+ result = @tropo_provisioning.create_user({ :username => "foobar7474", :password => 'fooey', :email => 'jsgoecke@voxeo.com' })
888
+ result.should == @new_user
889
+ end
890
+
891
+ it "should confirm a user" do
892
+ result = @tropo_provisioning.confirm_user('12345', '1234', '127.0.0.1')
893
+ result.message.should == "successfully confirmed user 12345"
894
+ end
895
+
896
+ it "should obtain details about a user" do
897
+ result = @tropo_provisioning.user('12345')
898
+ result.should == @existing_user
899
+ end
900
+
901
+ it 'should return a list of search terms that we search for' do
902
+ result = @tropo_provisioning.search_users('username=foobar')
903
+ result.should == @search_accounts
904
+ end
905
+
906
+ it 'should modify a user' do
907
+ result = @tropo_provisioning.modify_user('12345', { :password => 'foobar' })
908
+ result.href.should == 'http://api-smsified-eng.voxeo.net/v1/users/12345'
909
+ @tropo_provisioning.user_data['password'].should == 'foobar'
910
+ end
911
+
912
+ it 'should see if a username is available' do
913
+ @tropo_provisioning.username_exists?('12345').should == @username_check
914
+ end
915
+ end
916
+
917
+ describe 'features' do
918
+ it "should return a list of available features" do
919
+ result = @tropo_provisioning.features
920
+ result.should == @features
921
+ end
922
+
923
+ it "should return a list of features configured for a user" do
924
+ result = @tropo_provisioning.user_features('12345')
925
+ result.should == @user_features
926
+ end
927
+
928
+ it "should add a feature to a user" do
929
+ result = @tropo_provisioning.user_enable_feature('12345', 'http://api-smsified-eng.voxeo.net/v1/features/8')
930
+ result.should == @feature
931
+ end
932
+
933
+ it "should disable a feature for a user" do
934
+ result = @tropo_provisioning.user_disable_feature('12345', '8')
935
+ result.should == @feature_delete_message
936
+ end
937
+ end
938
+
939
+ describe 'platforms and partitions' do
940
+ it 'should list the available partitions' do
941
+ result = @tropo_provisioning.partitions
942
+ result[0]['name'].should == 'staging'
943
+ end
944
+
945
+ it 'should return a list of available platforms under a partition' do
946
+ result = @tropo_provisioning.platforms('staging')
947
+ result[0].name.should == 'sms'
948
+ end
949
+ end
950
+
951
+ describe 'payments' do
952
+ it "should add a payment method to a user" do
953
+ result = @tropo_provisioning.add_payment_info('12345', { :account_number => '1234567890',
954
+ :payment_type => 'https://api-smsified-eng.voxeo.net/v1/types/payment/1',
955
+ :address => '123 Smith Avenue',
956
+ :city => 'San Carlos',
957
+ :state => 'CA',
958
+ :postal_code => '94070',
959
+ :country => 'USA',
960
+ :name_on_account => 'Tropo User',
961
+ :expiration_date => '2011-12-10',
962
+ :security_code => '123',
963
+ :recharge_amount => 10.50,
964
+ :recharge_threshold => 5.00,
965
+ :email => 'j@doe.com',
966
+ :phone_number => '4155551212' })
967
+ result.should == @payment_info_message
968
+ end
969
+
970
+ it "should add a payment method to a user in camelCase" do
971
+ result = @tropo_provisioning.add_payment_info('12345', { :accountNumber => '1234567890',
972
+ :paymentType => 'https://api-smsified-eng.voxeo.net/v1/types/payment/1',
973
+ :address => '123 Smith Avenue',
974
+ :city => 'San Carlos',
975
+ :state => 'CA',
976
+ :postalCode => '94070',
977
+ :country => 'USA',
978
+ :nameOnAccount => 'Tropo User',
979
+ :expirationDate => '2011-12-10',
980
+ :securityCode => '123',
981
+ :rechargeAmount => 10.50,
982
+ :rechargeThreshold => 5.00,
983
+ :email => 'j@doe.com',
984
+ :phoneNumber => '4155551212' })
985
+
986
+ result.should == @payment_info_message
987
+ end
988
+
989
+ it 'should add a payment method to a user keys as strings' do
990
+ result = @tropo_provisioning.add_payment_info('12345', { 'account_number' => '1234567890',
991
+ 'payment_type' => 'https://api-smsified-eng.voxeo.net/v1/types/payment/1',
992
+ 'address' => '123 Smith Avenue',
993
+ 'city' => 'San Carlos',
994
+ 'state' => 'CA',
995
+ 'postal_code' => '94070',
996
+ 'country' => 'USA',
997
+ 'name_on_account' => 'Tropo User',
998
+ 'expiration_date' => '2011-12-10',
999
+ 'security_code' => '123',
1000
+ 'recharge_amount' => 10.50,
1001
+ 'recharge_threshold' => 5.00,
1002
+ 'email' => 'j@doe.com',
1003
+ 'phone_number' => '4155551212' })
1004
+
1005
+
1006
+ result.should == @payment_info_message
1007
+ end
1008
+
1009
+ it 'should add a payment method to a user in camelCase and keys as strings' do
1010
+ result = @tropo_provisioning.add_payment_info('12345', { 'accountNumber' => '1234567890',
1011
+ 'paymentType' => 'https://api-smsified-eng.voxeo.net/v1/types/payment/1',
1012
+ 'address' => '123 Smith Avenue',
1013
+ 'city' => 'San Carlos',
1014
+ 'state' => 'CA',
1015
+ 'postalCode' => '94070',
1016
+ 'country' => 'USA',
1017
+ 'nameOnAccount' => 'Tropo User',
1018
+ 'expirationDate' => '2011-12-10',
1019
+ 'securityCode' => '123',
1020
+ 'rechargeAmount' => 10.50,
1021
+ 'rechargeThreshold' => 5.00,
1022
+ 'email' => 'j@doe.com',
1023
+ 'phone_number' => '4155551212' })
1024
+
1025
+ result.should == @payment_info_message
1026
+ end
1027
+
1028
+ it 'should return the balance' do
1029
+ result = @tropo_provisioning.balance('12345')
1030
+ result['balance'].should == "3.00"
1031
+ end
1032
+
1033
+ it 'should make a payment' do
1034
+ result = @tropo_provisioning.make_payment('1234', 1.0)
1035
+ result.message.should == "successfully posted payment for the amount 1.000000"
1036
+ end
1037
+
1038
+ it "should get the payment method for a user" do
1039
+ result = @tropo_provisioning.user_payment_method('12345')
1040
+ result.should == @payment_method
1041
+ end
1042
+
1043
+ it "should return a list of available payment types" do
1044
+ result = @tropo_provisioning.available_payment_types
1045
+ result.should == @payment_methods
1046
+ end
1047
+
1048
+ it 'should raise an error if a float is not passed in amount for make_payment' do
1049
+ begin
1050
+ @tropo_provisioning.make_payment('1234', { :foo => 'bar' })
1051
+ rescue => e
1052
+ e.to_s.should == "amount must be of type Float"
1053
+ end
1054
+ end
1055
+
1056
+ it 'should update the recurring payment details' do
1057
+ result = @tropo_provisioning.update_recurrence('1234', { :recharge_amount => 13.50, :threshold_percentage => 10 })
1058
+ result.should == @recurrence_updated
1059
+ end
1060
+
1061
+ it 'should get the existing recurrent payment details' do
1062
+ @tropo_provisioning.get_recurrence('1234').should == @recurrence
1063
+ end
1064
+ end
1065
+
1066
+ describe 'whitelists' do
1067
+ it 'should get the whitelist for a user account' do
1068
+ result = @tropo_provisioning.whitelist('12345')
1069
+ result.should == @whitelist
1070
+
1071
+ result = @tropo_provisioning.whitelist
1072
+ result.should == @whitelist
1073
+ end
1074
+
1075
+ it 'should add to a whitelist' do
1076
+ result = @tropo_provisioning.add_whitelist({ :user_id => '12345', :value => '14155551212' })
1077
+ result.should == @whitelist
1078
+ end
1079
+
1080
+ it 'should remove from a whitelist' do
1081
+ result = @tropo_provisioning.delete_whitelist({ :user_id => '12345', :value => '14155551212' })
1082
+ result.should == @whitelist
1083
+ end
1084
+ end
1085
+
1086
+ describe 'custome error' do
1087
+ it 'should raise a custom error with an http_status code on the error object' do
1088
+ begin
1089
+ @tropo_provisioning.user('98765')
1090
+ rescue => e
1091
+ e.http_status.should == "404"
1092
+ e.message.should == '404: Got an error here! - '
1093
+ end
1094
+ end
1095
+ end
1096
+
1097
+ describe 'geography' do
1098
+ it 'should return a list of countries' do
1099
+ @tropo_provisioning.countries.should == @countries
1100
+ end
1101
+
1102
+ it 'should have the id added for the country' do
1103
+ result = @tropo_provisioning.countries[1][:id].should == '36'
1104
+ end
1105
+
1106
+ it 'should return a list of states' do
1107
+ @tropo_provisioning.states('36').should == @states
1108
+ end
1109
+
1110
+ it 'should have the id added for the state' do
1111
+ @tropo_provisioning.states('36')[1]['id'].should == '50'
1112
+ end
1113
+ end
1114
+
1115
+ describe 'invitations' do
1116
+ it 'should return a list of inivitations' do
1117
+ @tropo_provisioning.invitations.should == @invitations
1118
+ end
1119
+
1120
+ it 'should return an invitation' do
1121
+ @tropo_provisioning.invitation('ABC457').should == @invitations[1]
1122
+ end
1123
+
1124
+ it 'should create an invitation' do
1125
+ @tropo_provisioning.create_invitation({ :code => 'ABC457',
1126
+ :count => 100,
1127
+ :credit => 10 }).should == @invitation_created
1128
+ end
1129
+
1130
+ it 'should create an invitationfor a specific user' do
1131
+ @tropo_provisioning.create_invitation('15909',
1132
+ { :code => 'ABC457',
1133
+ :count => 100,
1134
+ :credit => 10 }).should == @invitation_created
1135
+ end
1136
+
1137
+ it 'should update an invitation' do
1138
+ @tropo_provisioning.update_invitation('ABC457', :count => 200).should == @invitation_created
1139
+ end
1140
+
1141
+ it 'should update an invitation for a specific user' do
1142
+ @tropo_provisioning.update_invitation('ABC457', '15909', :count => 200).should == @invitation_created
1143
+ end
1144
+
1145
+ it 'should delete an invitation' do
1146
+ @tropo_provisioning.delete_invitation('ABC457').should == @deleted_invitation
1147
+ end
1148
+
1149
+ it 'should delete a specific user invitation' do
1150
+ @tropo_provisioning.delete_invitation('ABC457', '15909').should == @deleted_invitation
1151
+ end
1152
+
1153
+ it 'should fetch the invitations for a user' do
1154
+ @tropo_provisioning.user_invitations('15909').should == [@invitation_created]
1155
+ end
1156
+
1157
+ it 'should list a specific invitation for a user' do
1158
+ @tropo_provisioning.invitation('ABC457', '15909').should == @invitations[1]
1159
+ end
1160
+ end
1161
+
1162
+ describe "HTTPS/SSL support" do
1163
+ it 'should fetch invitations via HTTPS/SSL' do
1164
+ tp = TropoProvisioning.new('foo', 'bar', :base_uri => 'https://foo:bar@api.tropo.com/v1')
1165
+ tp.invitations.should == @invitations
1166
+ end
1167
+ end
1168
+ end