urbanairship 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +15 -0
- data/lib/urbanairship.rb +9 -0
- data/spec/urbanairship_spec.rb +91 -0
- metadata +5 -5
data/README.markdown
CHANGED
@@ -4,6 +4,8 @@ Installation
|
|
4
4
|
============
|
5
5
|
gem install urbanairship
|
6
6
|
|
7
|
+
Note: if you are using Ruby 1.8, you should also install the ```system_timer``` gem for more reliable timeout behaviour. See http://ph7spot.com/musings/system-timer for more information.
|
8
|
+
|
7
9
|
Configuration
|
8
10
|
=============
|
9
11
|
```ruby
|
@@ -60,6 +62,19 @@ notifications = [
|
|
60
62
|
Urbanairship.batch_push notifications # => true
|
61
63
|
```
|
62
64
|
|
65
|
+
Sending broadcoast notifications
|
66
|
+
--------------------------------
|
67
|
+
Urbanairship allows you to send a broadcast notification to all active registered device tokens for your app.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
notification = {
|
71
|
+
:schedule_for => 1.hour.from_now,
|
72
|
+
:aps => {:alert => 'Important announcement!', :badge => 1}
|
73
|
+
}
|
74
|
+
|
75
|
+
Urbanairship.broadcast_push notification # => true
|
76
|
+
```
|
77
|
+
|
63
78
|
Polling the feedback API
|
64
79
|
------------------------
|
65
80
|
The first time you attempt to send a push notification to a device that has uninstalled your app (or has opted-out of notifications), both Apple and Urbanairship will register that token in their feedback API. Urbanairship will prevent further attempted notification sends to that device, but it's a good practice to periodically poll Urbanairship's feedback API and mark those tokens as inactive in your own system as well.
|
data/lib/urbanairship.rb
CHANGED
@@ -44,6 +44,15 @@ module Urbanairship
|
|
44
44
|
response && response.code == "200"
|
45
45
|
end
|
46
46
|
|
47
|
+
def broadcast_push(options = {})
|
48
|
+
response = do_request(:post, "/api/push/broadcast/", :authenticate_with => :master_secret) do |request|
|
49
|
+
request.body = parse_push_options(options).to_json
|
50
|
+
request.add_field "Content-Type", "application/json"
|
51
|
+
end
|
52
|
+
|
53
|
+
response && response.code == "200"
|
54
|
+
end
|
55
|
+
|
47
56
|
def feedback(time)
|
48
57
|
response = do_request(:get, "/api/device_tokens/feedback/?since=#{format_time(time)}", :authenticate_with => :master_secret)
|
49
58
|
response && response.code == "200" ? JSON.parse(response.body) : false
|
data/spec/urbanairship_spec.rb
CHANGED
@@ -21,6 +21,10 @@ describe Urbanairship do
|
|
21
21
|
FakeWeb.register_uri(:post, "https://my_app_key:my_master_secret@go.urbanairship.com/api/push/batch/", :status => ["200", "OK"])
|
22
22
|
FakeWeb.register_uri(:post, "https://my_app_key2:my_master_secret2@go.urbanairship.com/api/push/batch/", :status => ["400", "Bad Request"])
|
23
23
|
|
24
|
+
# broadcast push
|
25
|
+
FakeWeb.register_uri(:post, "https://my_app_key:my_master_secret@go.urbanairship.com/api/push/broadcast/", :status => ["200", "OK"])
|
26
|
+
FakeWeb.register_uri(:post, "https://my_app_key2:my_master_secret2@go.urbanairship.com/api/push/broadcast/", :status => ["400", "Bad Request"])
|
27
|
+
|
24
28
|
# feedback
|
25
29
|
FakeWeb.register_uri(:get, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/device_tokens\/feedback/, :status => ["200", "OK"], :body => "[{\"device_token\":\"token\",\"marked_inactive_on\":\"2010-10-14T19:15:13Z\",\"alias\":\"my_alias\"}]")
|
26
30
|
FakeWeb.register_uri(:get, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/device_tokens\/feedback/, :status => ["500", "Internal Server Error"])
|
@@ -320,6 +324,93 @@ describe Urbanairship do
|
|
320
324
|
|
321
325
|
end
|
322
326
|
|
327
|
+
describe "sending broadcast push notifications" do
|
328
|
+
|
329
|
+
before(:each) do
|
330
|
+
@valid_params = {:aps => {:alert => 'foo'}}
|
331
|
+
Urbanairship.application_key = "my_app_key"
|
332
|
+
Urbanairship.master_secret = "my_master_secret"
|
333
|
+
end
|
334
|
+
|
335
|
+
it "raises an error if call is made without an app key and master secret configured" do
|
336
|
+
Urbanairship.application_key = nil
|
337
|
+
Urbanairship.master_secret = nil
|
338
|
+
|
339
|
+
lambda {
|
340
|
+
Urbanairship.broadcast_push(@valid_params)
|
341
|
+
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
342
|
+
end
|
343
|
+
|
344
|
+
it "uses app key and secret to sign the request" do
|
345
|
+
Urbanairship.broadcast_push(@valid_params)
|
346
|
+
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
347
|
+
end
|
348
|
+
|
349
|
+
it "returns true when it successfully pushes a notification" do
|
350
|
+
Urbanairship.broadcast_push(@valid_params).should == true
|
351
|
+
end
|
352
|
+
|
353
|
+
it "returns false when the authorization is invalid" do
|
354
|
+
Urbanairship.application_key = "bad_key"
|
355
|
+
Urbanairship.broadcast_push(@valid_params).should == false
|
356
|
+
end
|
357
|
+
|
358
|
+
it "sets the content-type header to application/json" do
|
359
|
+
Urbanairship.broadcast_push(@valid_params)
|
360
|
+
FakeWeb.last_request['content-type'].should == 'application/json'
|
361
|
+
end
|
362
|
+
|
363
|
+
it "adds aliases to the JSON payload" do
|
364
|
+
@valid_params[:aliases] = ["one", "two"]
|
365
|
+
Urbanairship.broadcast_push(@valid_params)
|
366
|
+
request_json['aliases'].should == ["one", "two"]
|
367
|
+
end
|
368
|
+
|
369
|
+
it "adds tags to the JSON payload" do
|
370
|
+
@valid_params[:tags] = ["one", "two"]
|
371
|
+
Urbanairship.broadcast_push(@valid_params)
|
372
|
+
request_json['tags'].should == ["one", "two"]
|
373
|
+
end
|
374
|
+
|
375
|
+
it "adds schedule_for to the JSON payload" do
|
376
|
+
time = Time.parse("Oct 17th, 2010, 8:00 PM UTC")
|
377
|
+
@valid_params[:schedule_for] = [time]
|
378
|
+
Urbanairship.broadcast_push(@valid_params)
|
379
|
+
request_json['schedule_for'].should == ['2010-10-17T20:00:00Z']
|
380
|
+
end
|
381
|
+
|
382
|
+
it "accepts strings as schedule_for values" do
|
383
|
+
@valid_params[:schedule_for] = ["2010-10-10 09:09:09 UTC"]
|
384
|
+
Urbanairship.broadcast_push(@valid_params)
|
385
|
+
request_json['schedule_for'].should == ['2010-10-10T09:09:09Z']
|
386
|
+
end
|
387
|
+
|
388
|
+
it "adds exclude_tokens to the JSON payload" do
|
389
|
+
@valid_params[:exclude_tokens] = ["one", "two"]
|
390
|
+
Urbanairship.broadcast_push(@valid_params)
|
391
|
+
request_json['exclude_tokens'].should == ["one", "two"]
|
392
|
+
end
|
393
|
+
|
394
|
+
it "adds aps parameters to the JSON payload" do
|
395
|
+
@valid_params[:aps] = {:badge => 10, :alert => "Hi!", :sound => "cat.caf"}
|
396
|
+
Urbanairship.broadcast_push(@valid_params)
|
397
|
+
request_json['aps'].should == {'badge' => 10, 'alert' => 'Hi!', 'sound' => 'cat.caf'}
|
398
|
+
end
|
399
|
+
|
400
|
+
it "excludes invalid parameters from the JSON payload" do
|
401
|
+
@valid_params[:foo] = 'bar'
|
402
|
+
Urbanairship.broadcast_push(@valid_params)
|
403
|
+
request_json['foo'].should be_nil
|
404
|
+
end
|
405
|
+
|
406
|
+
it "returns false if urbanairship responds with a non-200 response" do
|
407
|
+
Urbanairship.application_key = "my_app_key2"
|
408
|
+
Urbanairship.master_secret = "my_master_secret2"
|
409
|
+
Urbanairship.broadcast_push.should == false
|
410
|
+
end
|
411
|
+
|
412
|
+
end
|
413
|
+
|
323
414
|
describe "feedback service" do
|
324
415
|
|
325
416
|
before(:each) do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: urbanairship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Groupon, Inc.
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-14 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
requirements: []
|
109
109
|
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 1.6.
|
111
|
+
rubygems_version: 1.6.2
|
112
112
|
signing_key:
|
113
113
|
specification_version: 3
|
114
114
|
summary: A Ruby wrapper for the Urbanairship API
|