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 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
- class << self
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
@@ -1,4 +1,4 @@
1
- describe Urbanairship do
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
- Urbanairship.application_key.should be_nil
43
- Urbanairship.application_key = "asdf1234"
44
- Urbanairship.application_key.should == "asdf1234"
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
- Urbanairship.application_secret.should be_nil
49
- Urbanairship.application_secret = "asdf1234"
50
- Urbanairship.application_secret.should == "asdf1234"
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
- Urbanairship.master_secret.should be_nil
55
- Urbanairship.master_secret = "asdf1234"
56
- Urbanairship.master_secret.should == "asdf1234"
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
- Urbanairship.application_key = "my_app_key"
64
- Urbanairship.application_secret = "my_app_secret"
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
- Urbanairship.application_key = nil
69
- Urbanairship.application_secret = nil
68
+ subject.application_key = nil
69
+ subject.application_secret = nil
70
70
 
71
71
  lambda {
72
- Urbanairship.register_device("asdf1234")
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
- Urbanairship.register_device("new_device_token")
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
- Urbanairship.register_device("new_device_token")
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
- Urbanairship.register_device("new_device_token").success?.should == true
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
- Urbanairship.register_device("existing_device_token").success?.should == true
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
- Urbanairship.application_key = "bad_key"
96
- Urbanairship.register_device("new_device_token").success?.should == false
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
- Urbanairship.register_device("device_token_one", @valid_params).success?.should == true
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
- Urbanairship.register_device("device_token_one", @valid_params)
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
- Urbanairship.register_device("device_token_one", :alias => 11)
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
- Urbanairship.register_device("new_device_token")
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
- Urbanairship.provider = :android
120
- Urbanairship.register_device("new_device_token")
119
+ subject.provider = :android
120
+ subject.register_device("new_device_token")
121
121
  FakeWeb.last_request.path.should == "/api/apids/new_device_token"
122
- Urbanairship.provider = nil
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
- Urbanairship.register_device("new_device_token", :provider => :android)
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
- Urbanairship.application_key = "my_app_key"
134
- Urbanairship.application_secret = "my_app_secret"
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
- Urbanairship.application_key = nil
139
- Urbanairship.application_secret = nil
138
+ subject.application_key = nil
139
+ subject.application_secret = nil
140
140
 
141
141
  lambda {
142
- Urbanairship.unregister_device("asdf1234")
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
- Urbanairship.unregister_device("key_to_delete")
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
- Urbanairship.unregister_device("key_to_delete")
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
- Urbanairship.unregister_device("key_to_delete").success?.should == true
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
- Urbanairship.application_key = "bad_key"
163
- Urbanairship.unregister_device("key_to_delete").success?.should == false
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
- Urbanairship.provider = :android
168
- Urbanairship.unregister_device("new_device_token")
167
+ subject.provider = :android
168
+ subject.unregister_device("new_device_token")
169
169
  FakeWeb.last_request.path.should == "/api/apids/new_device_token"
170
- Urbanairship.provider = nil
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
- Urbanairship.unregister_device("new_device_token", :provider => :android)
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
- Urbanairship.application_key = "my_app_key"
183
- Urbanairship.master_secret = "my_master_secret"
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
- Urbanairship.application_key = nil
188
- Urbanairship.master_secret = nil
187
+ subject.application_key = nil
188
+ subject.master_secret = nil
189
189
 
190
190
  lambda {
191
- Urbanairship.delete_scheduled_push("123456789")
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
- Urbanairship.delete_scheduled_push("123456789")
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
- Urbanairship.delete_scheduled_push("123456789")
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
- Urbanairship.delete_scheduled_push(123456789)
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
- Urbanairship.delete_scheduled_push(:alias => "alias_to_delete")
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
- Urbanairship.delete_scheduled_push("123456789").success?.should == true
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
- Urbanairship.application_key = "bad_key"
222
- Urbanairship.delete_scheduled_push("123456789").success?.should == false
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
- Urbanairship.application_key = "my_app_key"
230
- Urbanairship.master_secret = "my_master_secret"
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
- Urbanairship.application_key = nil
235
- Urbanairship.master_secret = nil
234
+ subject.application_key = nil
235
+ subject.master_secret = nil
236
236
 
237
237
  lambda {
238
- Urbanairship.push(@valid_params)
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
- Urbanairship.push(@valid_params)
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
- Urbanairship.push(@valid_params).success?.should == true
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
- Urbanairship.application_key = "bad_key"
253
- Urbanairship.push(@valid_params).success?.should == false
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
- Urbanairship.push(@valid_params.merge(:schedule_for => [time]))
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
- Urbanairship.push(@valid_params.merge(:schedule_for => ["2010-10-10 09:09:09 UTC"]))
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
- Urbanairship.application_key = "my_app_key2"
269
- Urbanairship.master_secret = "my_master_secret2"
270
- Urbanairship.push.success?.should == false
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
- Urbanairship.application_key = "my_app_key"
281
- Urbanairship.master_secret = "my_master_secret"
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
- Urbanairship.application_key = nil
286
- Urbanairship.master_secret = nil
285
+ subject.application_key = nil
286
+ subject.master_secret = nil
287
287
 
288
288
  lambda {
289
- Urbanairship.batch_push(@valid_params)
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
- Urbanairship.batch_push(@valid_params)
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
- Urbanairship.batch_push(@valid_params).success?.should == true
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
- Urbanairship.application_key = "bad_key"
304
- Urbanairship.batch_push(@valid_params).success?.should == false
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
- Urbanairship.batch_push(@valid_params)
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
- Urbanairship.batch_push(@valid_params)
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
- Urbanairship.application_key = "my_app_key2"
322
- Urbanairship.master_secret = "my_master_secret2"
323
- Urbanairship.batch_push.success?.should == false
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
- Urbanairship.application_key = "my_app_key"
331
- Urbanairship.master_secret = "my_master_secret"
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
- Urbanairship.application_key = nil
336
- Urbanairship.master_secret = nil
335
+ subject.application_key = nil
336
+ subject.master_secret = nil
337
337
 
338
338
  lambda {
339
- Urbanairship.broadcast_push(@valid_params)
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
- Urbanairship.broadcast_push(@valid_params)
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
- Urbanairship.broadcast_push(@valid_params).success?.should == true
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
- Urbanairship.application_key = "bad_key"
354
- Urbanairship.broadcast_push(@valid_params).success?.should == false
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
- Urbanairship.broadcast_push(@valid_params)
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
- Urbanairship.broadcast_push(@valid_params)
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
- Urbanairship.application_key = "my_app_key2"
372
- Urbanairship.master_secret = "my_master_secret2"
373
- Urbanairship.broadcast_push.success?.should == false
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
- Urbanairship.application_key = "my_app_key"
380
- Urbanairship.master_secret = "my_master_secret"
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
- Urbanairship.application_key = nil
385
- Urbanairship.master_secret = nil
384
+ subject.application_key = nil
385
+ subject.master_secret = nil
386
386
 
387
387
  lambda {
388
- Urbanairship.feedback(Time.now)
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
- Urbanairship.feedback(Time.now)
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
- Urbanairship.feedback(time)
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
- Urbanairship.feedback("Oct 07, 2010 8:00AM UTC")
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 = Urbanairship.feedback(Time.now)
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
- Urbanairship.application_key = "my_app_key2"
418
- Urbanairship.master_secret = "my_master_secret2"
419
- Urbanairship.feedback(Time.now).success?.should == false
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
- Urbanairship.application_key = "my_app_key"
428
- Urbanairship.application_secret = "my_app_secret"
429
- Urbanairship.master_secret = "my_master_secret"
430
- Urbanairship.logger = @logger
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
- Urbanairship.register_device('new_device_token')
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
- Urbanairship.push(:device_tokens => ["device_token"], :aps => {:alert => "foo"})
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
- Urbanairship.batch_push([:device_tokens => ["device_token"], :aps => {:alert => "foo"}])
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
- Urbanairship.feedback(Time.now)
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
- Urbanairship.feedback(Time.now)
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
- Urbanairship.application_key = "my_app_key"
464
- Urbanairship.application_secret = "my_app_secret"
465
- Urbanairship.master_secret = "my_master_secret"
466
- Urbanairship.logger = @logger
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
- Urbanairship.logger = nil
471
+ subject.logger = nil
472
472
 
473
473
  lambda {
474
- Urbanairship.register_device('new_device_token')
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
- Urbanairship.register_device('new_device_token')
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
- Urbanairship.request_timeout = 1.23
490
- Urbanairship.register_device('new_device_token')
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
- version: 2.1.2
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
- date: 2012-10-03 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
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
- requirement: &70132667901780 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
17
25
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
22
33
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70132667901780
25
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
26
36
  name: rspec
27
- requirement: &70132667901340 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
28
39
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
33
47
  type: :development
34
- prerelease: false
35
- version_requirements: *70132667901340
36
- - !ruby/object:Gem::Dependency
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
37
50
  name: fakeweb
38
- requirement: &70132667900900 !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
39
53
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
44
61
  type: :development
45
- prerelease: false
46
- version_requirements: *70132667900900
47
- description: Urbanairship is a Ruby library for interacting with the Urban Airship
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
- files:
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
- require_paths:
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
- version: '0'
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.8.6
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