urbanairship 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +24 -0
- data/lib/urbanairship.rb +9 -1
- data/spec/urbanairship_spec.rb +135 -127
- metadata +76 -46
data/README.markdown
CHANGED
@@ -161,3 +161,27 @@ response.success? # => false
|
|
161
161
|
response.code # => '503'
|
162
162
|
response.inspect # => "{\"error\"=>\"Request timeout\"}"
|
163
163
|
```
|
164
|
+
|
165
|
+
Instantiating an Urbanairship::Client
|
166
|
+
-------------------------------------
|
167
|
+
|
168
|
+
Anything you can do directly with the Urbanairship module, you can also do with a Client.
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
client = Urbanairship::Client.new
|
172
|
+
client.application_key = 'application-key'
|
173
|
+
client.application_secret = 'application-secret'
|
174
|
+
client.register_device('DEVICE-TOKEN')
|
175
|
+
notification = {
|
176
|
+
:schedule_for => [1.hour.from_now],
|
177
|
+
:device_tokens => ['DEVICE-TOKEN'],
|
178
|
+
:aps => {:alert => 'You have a new message!', :badge => 1}
|
179
|
+
}
|
180
|
+
|
181
|
+
client.push(notification) # =>
|
182
|
+
# {
|
183
|
+
# "scheduled_notifications" => ["https://go.urbanairship.com/api/push/scheduled/123456"]
|
184
|
+
# }
|
185
|
+
```
|
186
|
+
|
187
|
+
This can be used to use clients for different Urbanairship applications in a thread-safe manner.
|
data/lib/urbanairship.rb
CHANGED
@@ -13,7 +13,7 @@ module Urbanairship
|
|
13
13
|
Timer = Timeout
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
module ClassMethods
|
17
17
|
attr_accessor :application_key, :application_secret, :master_secret, :logger, :request_timeout, :provider
|
18
18
|
|
19
19
|
def register_device(device_token, options = {})
|
@@ -128,4 +128,12 @@ module Urbanairship
|
|
128
128
|
@request_timeout || 5.0
|
129
129
|
end
|
130
130
|
end
|
131
|
+
|
132
|
+
class << self
|
133
|
+
include ClassMethods
|
134
|
+
end
|
135
|
+
|
136
|
+
class Client
|
137
|
+
include ClassMethods
|
138
|
+
end
|
131
139
|
end
|
data/spec/urbanairship_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
shared_examples_for "an Urbanairship client" do
|
2
2
|
before(:all) do
|
3
3
|
FakeWeb.allow_net_connect = false
|
4
4
|
|
@@ -39,139 +39,139 @@ describe Urbanairship do
|
|
39
39
|
|
40
40
|
describe "configuration" do
|
41
41
|
it "enables you to configure the application key" do
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
subject.application_key.should be_nil
|
43
|
+
subject.application_key = "asdf1234"
|
44
|
+
subject.application_key.should == "asdf1234"
|
45
45
|
end
|
46
46
|
|
47
47
|
it "enables you to configure the application secret" do
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
subject.application_secret.should be_nil
|
49
|
+
subject.application_secret = "asdf1234"
|
50
|
+
subject.application_secret.should == "asdf1234"
|
51
51
|
end
|
52
52
|
|
53
53
|
it "enables you to configure the master secret" do
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
subject.master_secret.should be_nil
|
55
|
+
subject.master_secret = "asdf1234"
|
56
|
+
subject.master_secret.should == "asdf1234"
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "::register_device" do
|
61
61
|
before(:each) do
|
62
62
|
@valid_params = {:alias => 'one'}
|
63
|
-
|
64
|
-
|
63
|
+
subject.application_key = "my_app_key"
|
64
|
+
subject.application_secret = "my_app_secret"
|
65
65
|
end
|
66
66
|
|
67
67
|
it "raises an error if call is made without an app key and secret configured" do
|
68
|
-
|
69
|
-
|
68
|
+
subject.application_key = nil
|
69
|
+
subject.application_secret = nil
|
70
70
|
|
71
71
|
lambda {
|
72
|
-
|
72
|
+
subject.register_device("asdf1234")
|
73
73
|
}.should raise_error(RuntimeError, "Must configure application_key, application_secret before making this request.")
|
74
74
|
end
|
75
75
|
|
76
76
|
it "uses app key and secret to sign the request" do
|
77
|
-
|
77
|
+
subject.register_device("new_device_token")
|
78
78
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_app_secret').chomp}"
|
79
79
|
end
|
80
80
|
|
81
81
|
it "takes and sends a device token" do
|
82
|
-
|
82
|
+
subject.register_device("new_device_token")
|
83
83
|
FakeWeb.last_request.path.should == "/api/device_tokens/new_device_token"
|
84
84
|
end
|
85
85
|
|
86
86
|
it "returns true when the device is registered for the first time" do
|
87
|
-
|
87
|
+
subject.register_device("new_device_token").success?.should == true
|
88
88
|
end
|
89
89
|
|
90
90
|
it "returns true when the device is registered again" do
|
91
|
-
|
91
|
+
subject.register_device("existing_device_token").success?.should == true
|
92
92
|
end
|
93
93
|
|
94
94
|
it "returns false when the authorization is invalid" do
|
95
|
-
|
96
|
-
|
95
|
+
subject.application_key = "bad_key"
|
96
|
+
subject.register_device("new_device_token").success?.should == false
|
97
97
|
end
|
98
98
|
|
99
99
|
it "accepts an alias" do
|
100
|
-
|
100
|
+
subject.register_device("device_token_one", @valid_params).success?.should == true
|
101
101
|
end
|
102
102
|
|
103
103
|
it "adds alias to the JSON payload" do
|
104
|
-
|
104
|
+
subject.register_device("device_token_one", @valid_params)
|
105
105
|
request_json['alias'].should == "one"
|
106
106
|
end
|
107
107
|
|
108
108
|
it "converts alias param to string" do
|
109
|
-
|
109
|
+
subject.register_device("device_token_one", :alias => 11)
|
110
110
|
request_json['alias'].should be_a_kind_of String
|
111
111
|
end
|
112
112
|
|
113
113
|
it "uses the iOS interface by default" do
|
114
|
-
|
114
|
+
subject.register_device("new_device_token")
|
115
115
|
FakeWeb.last_request.path.should == "/api/device_tokens/new_device_token"
|
116
116
|
end
|
117
117
|
|
118
118
|
it "uses the android interface if 'provider' configuration option is set to :android" do
|
119
|
-
|
120
|
-
|
119
|
+
subject.provider = :android
|
120
|
+
subject.register_device("new_device_token")
|
121
121
|
FakeWeb.last_request.path.should == "/api/apids/new_device_token"
|
122
|
-
|
122
|
+
subject.provider = nil
|
123
123
|
end
|
124
124
|
|
125
125
|
it "uses the android interface if 'provider' option is passed as :android" do
|
126
|
-
|
126
|
+
subject.register_device("new_device_token", :provider => :android)
|
127
127
|
FakeWeb.last_request.path.should == "/api/apids/new_device_token"
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
describe "::unregister_device" do
|
132
132
|
before(:each) do
|
133
|
-
|
134
|
-
|
133
|
+
subject.application_key = "my_app_key"
|
134
|
+
subject.application_secret = "my_app_secret"
|
135
135
|
end
|
136
136
|
|
137
137
|
it "raises an error if call is made without an app key and secret configured" do
|
138
|
-
|
139
|
-
|
138
|
+
subject.application_key = nil
|
139
|
+
subject.application_secret = nil
|
140
140
|
|
141
141
|
lambda {
|
142
|
-
|
142
|
+
subject.unregister_device("asdf1234")
|
143
143
|
}.should raise_error(RuntimeError, "Must configure application_key, application_secret before making this request.")
|
144
144
|
end
|
145
145
|
|
146
146
|
it "uses app key and secret to sign the request" do
|
147
|
-
|
147
|
+
subject.unregister_device("key_to_delete")
|
148
148
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_app_secret').chomp}"
|
149
149
|
end
|
150
150
|
|
151
151
|
it "sends the key that needs to be deleted" do
|
152
|
-
|
152
|
+
subject.unregister_device("key_to_delete")
|
153
153
|
FakeWeb.last_request.path.should == "/api/device_tokens/key_to_delete"
|
154
154
|
end
|
155
155
|
|
156
156
|
it "returns true when the device is successfully unregistered" do
|
157
|
-
|
157
|
+
subject.unregister_device("key_to_delete").success?.should == true
|
158
158
|
FakeWeb.last_request.body.should be_nil
|
159
159
|
end
|
160
160
|
|
161
161
|
it "returns false when the authorization is invalid" do
|
162
|
-
|
163
|
-
|
162
|
+
subject.application_key = "bad_key"
|
163
|
+
subject.unregister_device("key_to_delete").success?.should == false
|
164
164
|
end
|
165
165
|
|
166
166
|
it "uses the android interface if 'provider' configuration option is set to :android" do
|
167
|
-
|
168
|
-
|
167
|
+
subject.provider = :android
|
168
|
+
subject.unregister_device("new_device_token")
|
169
169
|
FakeWeb.last_request.path.should == "/api/apids/new_device_token"
|
170
|
-
|
170
|
+
subject.provider = nil
|
171
171
|
end
|
172
172
|
|
173
173
|
it "uses the android interface if 'provider' option is passed as :android" do
|
174
|
-
|
174
|
+
subject.unregister_device("new_device_token", :provider => :android)
|
175
175
|
FakeWeb.last_request.path.should == "/api/apids/new_device_token"
|
176
176
|
end
|
177
177
|
|
@@ -179,95 +179,95 @@ describe Urbanairship do
|
|
179
179
|
|
180
180
|
describe "::delete_scheduled_push" do
|
181
181
|
before(:each) do
|
182
|
-
|
183
|
-
|
182
|
+
subject.application_key = "my_app_key"
|
183
|
+
subject.master_secret = "my_master_secret"
|
184
184
|
end
|
185
185
|
|
186
186
|
it "raises an error if call is made without an app key and master secret configured" do
|
187
|
-
|
188
|
-
|
187
|
+
subject.application_key = nil
|
188
|
+
subject.master_secret = nil
|
189
189
|
|
190
190
|
lambda {
|
191
|
-
|
191
|
+
subject.delete_scheduled_push("123456789")
|
192
192
|
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
193
193
|
end
|
194
194
|
|
195
195
|
it "uses app key and secret to sign the request" do
|
196
|
-
|
196
|
+
subject.delete_scheduled_push("123456789")
|
197
197
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
198
198
|
end
|
199
199
|
|
200
200
|
it "sends the key that needs to be deleted" do
|
201
|
-
|
201
|
+
subject.delete_scheduled_push("123456789")
|
202
202
|
FakeWeb.last_request.path.should == "/api/push/scheduled/123456789"
|
203
203
|
end
|
204
204
|
|
205
205
|
it "sends the key that needs to be deleted" do
|
206
|
-
|
206
|
+
subject.delete_scheduled_push(123456789)
|
207
207
|
FakeWeb.last_request.path.should == "/api/push/scheduled/123456789"
|
208
208
|
end
|
209
209
|
|
210
210
|
it "sends the alias that needs to be deleted" do
|
211
|
-
|
211
|
+
subject.delete_scheduled_push(:alias => "alias_to_delete")
|
212
212
|
FakeWeb.last_request.path.should == "/api/push/scheduled/alias/alias_to_delete"
|
213
213
|
end
|
214
214
|
|
215
215
|
it "returns true when the push notification is successfully deleted" do
|
216
|
-
|
216
|
+
subject.delete_scheduled_push("123456789").success?.should == true
|
217
217
|
FakeWeb.last_request.body.should be_nil
|
218
218
|
end
|
219
219
|
|
220
220
|
it "returns false when the authorization is invalid" do
|
221
|
-
|
222
|
-
|
221
|
+
subject.application_key = "bad_key"
|
222
|
+
subject.delete_scheduled_push("123456789").success?.should == false
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
226
226
|
describe "::push" do
|
227
227
|
before(:each) do
|
228
228
|
@valid_params = {:device_tokens => ['device_token_one', 'device_token_two'], :aps => {:alert => 'foo'}}
|
229
|
-
|
230
|
-
|
229
|
+
subject.application_key = "my_app_key"
|
230
|
+
subject.master_secret = "my_master_secret"
|
231
231
|
end
|
232
232
|
|
233
233
|
it "raises an error if call is made without an app key and master secret configured" do
|
234
|
-
|
235
|
-
|
234
|
+
subject.application_key = nil
|
235
|
+
subject.master_secret = nil
|
236
236
|
|
237
237
|
lambda {
|
238
|
-
|
238
|
+
subject.push(@valid_params)
|
239
239
|
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
240
240
|
end
|
241
241
|
|
242
242
|
it "uses app key and secret to sign the request" do
|
243
|
-
|
243
|
+
subject.push(@valid_params)
|
244
244
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
245
245
|
end
|
246
246
|
|
247
247
|
it "returns true when it successfully pushes a notification" do
|
248
|
-
|
248
|
+
subject.push(@valid_params).success?.should == true
|
249
249
|
end
|
250
250
|
|
251
251
|
it "returns false when the authorization is invalid" do
|
252
|
-
|
253
|
-
|
252
|
+
subject.application_key = "bad_key"
|
253
|
+
subject.push(@valid_params).success?.should == false
|
254
254
|
end
|
255
255
|
|
256
256
|
it "adds schedule_for to the JSON payload" do
|
257
257
|
time = Time.parse("Oct 17th, 2010, 8:00 PM UTC")
|
258
|
-
|
258
|
+
subject.push(@valid_params.merge(:schedule_for => [time]))
|
259
259
|
request_json['schedule_for'].should == ['2010-10-17T20:00:00Z']
|
260
260
|
end
|
261
261
|
|
262
262
|
it "only attempts to format schedule_for if it is a time object" do
|
263
|
-
|
263
|
+
subject.push(@valid_params.merge(:schedule_for => ["2010-10-10 09:09:09 UTC"]))
|
264
264
|
request_json['schedule_for'].should == ['2010-10-10T09:09:09Z']
|
265
265
|
end
|
266
266
|
|
267
267
|
it "returns false if urbanairship responds with a non-200 response" do
|
268
|
-
|
269
|
-
|
270
|
-
|
268
|
+
subject.application_key = "my_app_key2"
|
269
|
+
subject.master_secret = "my_master_secret2"
|
270
|
+
subject.push.success?.should == false
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
@@ -277,146 +277,146 @@ describe Urbanairship do
|
|
277
277
|
{:device_tokens => ['device_token_one', 'device_token_two'], :aps => {:alert => 'foo'}},
|
278
278
|
{:device_tokens => ['device_token_three', 'device_token_four'], :aps => {:alert => 'bar'}}
|
279
279
|
]
|
280
|
-
|
281
|
-
|
280
|
+
subject.application_key = "my_app_key"
|
281
|
+
subject.master_secret = "my_master_secret"
|
282
282
|
end
|
283
283
|
|
284
284
|
it "raises an error if call is made without an app key and master secret configured" do
|
285
|
-
|
286
|
-
|
285
|
+
subject.application_key = nil
|
286
|
+
subject.master_secret = nil
|
287
287
|
|
288
288
|
lambda {
|
289
|
-
|
289
|
+
subject.batch_push(@valid_params)
|
290
290
|
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
291
291
|
end
|
292
292
|
|
293
293
|
it "uses app key and secret to sign the request" do
|
294
|
-
|
294
|
+
subject.batch_push(@valid_params)
|
295
295
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
296
296
|
end
|
297
297
|
|
298
298
|
it "returns true when it successfully pushes a notification" do
|
299
|
-
|
299
|
+
subject.batch_push(@valid_params).success?.should == true
|
300
300
|
end
|
301
301
|
|
302
302
|
it "returns false when the authorization is invalid" do
|
303
|
-
|
304
|
-
|
303
|
+
subject.application_key = "bad_key"
|
304
|
+
subject.batch_push(@valid_params).success?.should == false
|
305
305
|
end
|
306
306
|
|
307
307
|
it "adds schedule_for to the JSON payload" do
|
308
308
|
time = Time.parse("Oct 17th, 2010, 8:00 PM UTC")
|
309
309
|
@valid_params[0].merge!(:schedule_for => [time])
|
310
|
-
|
310
|
+
subject.batch_push(@valid_params)
|
311
311
|
request_json[0]['schedule_for'].should == ['2010-10-17T20:00:00Z']
|
312
312
|
end
|
313
313
|
|
314
314
|
it "accepts strings as schedule_for values" do
|
315
315
|
@valid_params[0].merge!(:schedule_for => ["2010-10-10 09:09:09 UTC"])
|
316
|
-
|
316
|
+
subject.batch_push(@valid_params)
|
317
317
|
request_json[0]['schedule_for'].should == ['2010-10-10T09:09:09Z']
|
318
318
|
end
|
319
319
|
|
320
320
|
it "returns false if urbanairship responds with a non-200 response" do
|
321
|
-
|
322
|
-
|
323
|
-
|
321
|
+
subject.application_key = "my_app_key2"
|
322
|
+
subject.master_secret = "my_master_secret2"
|
323
|
+
subject.batch_push.success?.should == false
|
324
324
|
end
|
325
325
|
end
|
326
326
|
|
327
327
|
describe "::broadcast_push" do
|
328
328
|
before(:each) do
|
329
329
|
@valid_params = {:aps => {:alert => 'foo'}}
|
330
|
-
|
331
|
-
|
330
|
+
subject.application_key = "my_app_key"
|
331
|
+
subject.master_secret = "my_master_secret"
|
332
332
|
end
|
333
333
|
|
334
334
|
it "raises an error if call is made without an app key and master secret configured" do
|
335
|
-
|
336
|
-
|
335
|
+
subject.application_key = nil
|
336
|
+
subject.master_secret = nil
|
337
337
|
|
338
338
|
lambda {
|
339
|
-
|
339
|
+
subject.broadcast_push(@valid_params)
|
340
340
|
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
341
341
|
end
|
342
342
|
|
343
343
|
it "uses app key and secret to sign the request" do
|
344
|
-
|
344
|
+
subject.broadcast_push(@valid_params)
|
345
345
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
346
346
|
end
|
347
347
|
|
348
348
|
it "returns true when it successfully pushes a notification" do
|
349
|
-
|
349
|
+
subject.broadcast_push(@valid_params).success?.should == true
|
350
350
|
end
|
351
351
|
|
352
352
|
it "returns false when the authorization is invalid" do
|
353
|
-
|
354
|
-
|
353
|
+
subject.application_key = "bad_key"
|
354
|
+
subject.broadcast_push(@valid_params).success?.should == false
|
355
355
|
end
|
356
356
|
|
357
357
|
it "adds schedule_for to the JSON payload" do
|
358
358
|
time = Time.parse("Oct 17th, 2010, 8:00 PM UTC")
|
359
359
|
@valid_params[:schedule_for] = [time]
|
360
|
-
|
360
|
+
subject.broadcast_push(@valid_params)
|
361
361
|
request_json['schedule_for'].should == ['2010-10-17T20:00:00Z']
|
362
362
|
end
|
363
363
|
|
364
364
|
it "accepts strings as schedule_for values" do
|
365
365
|
@valid_params[:schedule_for] = ["2010-10-10 09:09:09 UTC"]
|
366
|
-
|
366
|
+
subject.broadcast_push(@valid_params)
|
367
367
|
request_json['schedule_for'].should == ['2010-10-10T09:09:09Z']
|
368
368
|
end
|
369
369
|
|
370
370
|
it "returns false if urbanairship responds with a non-200 response" do
|
371
|
-
|
372
|
-
|
373
|
-
|
371
|
+
subject.application_key = "my_app_key2"
|
372
|
+
subject.master_secret = "my_master_secret2"
|
373
|
+
subject.broadcast_push.success?.should == false
|
374
374
|
end
|
375
375
|
end
|
376
376
|
|
377
377
|
describe "::feedback" do
|
378
378
|
before(:each) do
|
379
|
-
|
380
|
-
|
379
|
+
subject.application_key = "my_app_key"
|
380
|
+
subject.master_secret = "my_master_secret"
|
381
381
|
end
|
382
382
|
|
383
383
|
it "raises an error if call is made without an app key and master secret configured" do
|
384
|
-
|
385
|
-
|
384
|
+
subject.application_key = nil
|
385
|
+
subject.master_secret = nil
|
386
386
|
|
387
387
|
lambda {
|
388
|
-
|
388
|
+
subject.feedback(Time.now)
|
389
389
|
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
390
390
|
end
|
391
391
|
|
392
392
|
it "uses app key and secret to sign the request" do
|
393
|
-
|
393
|
+
subject.feedback(Time.now)
|
394
394
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
395
395
|
end
|
396
396
|
|
397
397
|
it "encodes the time argument in UTC, ISO 8601 format" do
|
398
398
|
time = Time.parse("October 10, 2010, 8:00pm")
|
399
399
|
formatted_time = time.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
|
400
|
-
|
400
|
+
subject.feedback(time)
|
401
401
|
FakeWeb.last_request.path.should include(formatted_time)
|
402
402
|
end
|
403
403
|
|
404
404
|
it "accepts a string as the time argument" do
|
405
|
-
|
405
|
+
subject.feedback("Oct 07, 2010 8:00AM UTC")
|
406
406
|
FakeWeb.last_request.path.should include("2010-10-07T08:00:00Z")
|
407
407
|
end
|
408
408
|
|
409
409
|
it "returns an array of responses from the feedback API" do
|
410
|
-
response =
|
410
|
+
response = subject.feedback(Time.now)
|
411
411
|
response[0].should include("device_token")
|
412
412
|
response[0].should include("marked_inactive_on")
|
413
413
|
response[0].should include("alias")
|
414
414
|
end
|
415
415
|
|
416
416
|
it "success? is false when the call doesn't return 200" do
|
417
|
-
|
418
|
-
|
419
|
-
|
417
|
+
subject.application_key = "my_app_key2"
|
418
|
+
subject.master_secret = "my_master_secret2"
|
419
|
+
subject.feedback(Time.now).success?.should == false
|
420
420
|
end
|
421
421
|
end
|
422
422
|
|
@@ -424,54 +424,54 @@ describe Urbanairship do
|
|
424
424
|
|
425
425
|
before(:each) do
|
426
426
|
@logger = mock("logger", :info => true)
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
427
|
+
subject.application_key = "my_app_key"
|
428
|
+
subject.application_secret = "my_app_secret"
|
429
|
+
subject.master_secret = "my_master_secret"
|
430
|
+
subject.logger = @logger
|
431
431
|
end
|
432
432
|
|
433
433
|
it "logs request and response information when registering a device" do
|
434
434
|
@logger.should_receive(:info).with(/\/api\/device_tokens\/new_device_token/)
|
435
|
-
|
435
|
+
subject.register_device('new_device_token')
|
436
436
|
end
|
437
437
|
|
438
438
|
it "logs request and response information when sending push notifications" do
|
439
439
|
@logger.should_receive(:info).with(/\/api\/push/)
|
440
|
-
|
440
|
+
subject.push(:device_tokens => ["device_token"], :aps => {:alert => "foo"})
|
441
441
|
end
|
442
442
|
|
443
443
|
it "logs request and response information when sending batch push notifications" do
|
444
444
|
@logger.should_receive(:info).with(/\/api\/push\/batch/)
|
445
|
-
|
445
|
+
subject.batch_push([:device_tokens => ["device_token"], :aps => {:alert => "foo"}])
|
446
446
|
end
|
447
447
|
|
448
448
|
it "logs request and response information when sending feedback requests" do
|
449
449
|
@logger.should_receive(:info).with(/\/api\/device_tokens\/feedback/)
|
450
|
-
|
450
|
+
subject.feedback(Time.now)
|
451
451
|
end
|
452
452
|
|
453
453
|
it "flushes the logger buffer if it's an ActiveSupport::BufferedLogger (Default Rails logger)" do
|
454
454
|
@logger.stub(:flush).and_return("message in the buffer\n")
|
455
455
|
@logger.should_receive(:flush)
|
456
|
-
|
456
|
+
subject.feedback(Time.now)
|
457
457
|
end
|
458
458
|
end
|
459
459
|
|
460
460
|
describe "request timeout" do
|
461
461
|
before(:each) do
|
462
462
|
@logger = mock("logger", :info => true)
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
463
|
+
subject.application_key = "my_app_key"
|
464
|
+
subject.application_secret = "my_app_secret"
|
465
|
+
subject.master_secret = "my_master_secret"
|
466
|
+
subject.logger = @logger
|
467
467
|
end
|
468
468
|
|
469
469
|
it "does not attempt to log if logger is not set" do
|
470
470
|
Urbanairship::Timer.should_receive(:timeout).with(5.0).and_raise(Timeout::Error)
|
471
|
-
|
471
|
+
subject.logger = nil
|
472
472
|
|
473
473
|
lambda {
|
474
|
-
|
474
|
+
subject.register_device('new_device_token')
|
475
475
|
}.should_not raise_exception(NoMethodError)
|
476
476
|
end
|
477
477
|
|
@@ -479,19 +479,27 @@ describe Urbanairship do
|
|
479
479
|
Urbanairship::Timer.should_receive(:timeout).with(5.0).and_raise(Timeout::Error)
|
480
480
|
@logger.should_receive(:error).with(/Urbanairship request timed out/)
|
481
481
|
|
482
|
-
|
482
|
+
subject.register_device('new_device_token')
|
483
483
|
end
|
484
484
|
|
485
485
|
it "accepts a configured request_timeout value" do
|
486
486
|
Urbanairship::Timer.should_receive(:timeout).with(1.23).and_raise(Timeout::Error)
|
487
487
|
@logger.should_receive(:error).with(/Urbanairship request timed out/)
|
488
488
|
|
489
|
-
|
490
|
-
|
489
|
+
subject.request_timeout = 1.23
|
490
|
+
subject.register_device('new_device_token')
|
491
491
|
end
|
492
492
|
end
|
493
493
|
end
|
494
494
|
|
495
|
+
describe Urbanairship do
|
496
|
+
it_should_behave_like "an Urbanairship client"
|
497
|
+
end
|
498
|
+
|
499
|
+
describe Urbanairship::Client do
|
500
|
+
it_should_behave_like "an Urbanairship client"
|
501
|
+
end
|
502
|
+
|
495
503
|
def request_json
|
496
504
|
JSON.parse FakeWeb.last_request.body
|
497
505
|
end
|
metadata
CHANGED
@@ -1,57 +1,75 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: urbanairship
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 2.2.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Groupon, Inc.
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2012-11-08 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: json
|
16
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
25
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
22
33
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
26
36
|
name: rspec
|
27
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
33
47
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
37
50
|
name: fakeweb
|
38
|
-
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
53
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
44
61
|
type: :development
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
(http://urbanairship.com) API.
|
49
|
-
email:
|
62
|
+
version_requirements: *id003
|
63
|
+
description: Urbanairship is a Ruby library for interacting with the Urban Airship (http://urbanairship.com) API.
|
64
|
+
email:
|
50
65
|
- rubygems@groupon.com
|
51
66
|
executables: []
|
67
|
+
|
52
68
|
extensions: []
|
69
|
+
|
53
70
|
extra_rdoc_files: []
|
54
|
-
|
71
|
+
|
72
|
+
files:
|
55
73
|
- README.markdown
|
56
74
|
- LICENSE
|
57
75
|
- Rakefile
|
@@ -60,31 +78,43 @@ files:
|
|
60
78
|
- spec/response_spec.rb
|
61
79
|
- spec/spec_helper.rb
|
62
80
|
- spec/urbanairship_spec.rb
|
81
|
+
has_rdoc: true
|
63
82
|
homepage: http://github.com/groupon/urbanairship
|
64
83
|
licenses: []
|
84
|
+
|
65
85
|
post_install_message:
|
66
86
|
rdoc_options: []
|
67
|
-
|
87
|
+
|
88
|
+
require_paths:
|
68
89
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
91
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 59
|
96
|
+
segments:
|
97
|
+
- 1
|
98
|
+
- 8
|
99
|
+
- 6
|
74
100
|
version: 1.8.6
|
75
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
102
|
none: false
|
77
|
-
requirements:
|
78
|
-
- -
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
81
110
|
requirements: []
|
111
|
+
|
82
112
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 1.6.2
|
84
114
|
signing_key:
|
85
115
|
specification_version: 3
|
86
116
|
summary: A Ruby wrapper for the Urban Airship API
|
87
|
-
test_files:
|
117
|
+
test_files:
|
88
118
|
- spec/response_spec.rb
|
89
119
|
- spec/spec_helper.rb
|
90
120
|
- spec/urbanairship_spec.rb
|