urbanairship 2.3.3 → 2.4.0
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 +23 -0
- data/lib/urbanairship.rb +21 -3
- data/lib/urbanairship/response.rb +1 -1
- data/spec/urbanairship_spec.rb +112 -0
- metadata +4 -3
data/README.markdown
CHANGED
@@ -38,6 +38,12 @@ Unregistering a device token
|
|
38
38
|
Urbanairship.unregister_device('DEVICE-TOKEN')
|
39
39
|
```
|
40
40
|
|
41
|
+
Retrieving Device Info
|
42
|
+
----------------------------
|
43
|
+
```ruby
|
44
|
+
Urbanairship.device_info('DEVICE-TOKEN')
|
45
|
+
```
|
46
|
+
|
41
47
|
Sending a push notification
|
42
48
|
---------------------------
|
43
49
|
```ruby
|
@@ -52,6 +58,12 @@ Urbanairship.push(notification) # =>
|
|
52
58
|
# "scheduled_notifications" => ["https://go.urbanairship.com/api/push/scheduled/123456"]
|
53
59
|
# }
|
54
60
|
```
|
61
|
+
|
62
|
+
If you wish to use v3 of the Urbanairship API, just add `version: 3` as an option:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
Urbanairship.push(notification, version: 3)
|
66
|
+
```
|
55
67
|
### Using aliases instead of device tokens ###
|
56
68
|
|
57
69
|
```ruby
|
@@ -198,6 +210,17 @@ Urbanairship.update_segment('abcd-efgh-ijkl', {
|
|
198
210
|
Urbanairship.delete_segment("abcd-efgh-ijkl") # => {}
|
199
211
|
```
|
200
212
|
|
213
|
+
Getting your device tokens
|
214
|
+
-------------------------------------
|
215
|
+
```ruby
|
216
|
+
Urbanairship.device_tokens # =>
|
217
|
+
# {
|
218
|
+
# "device_tokens" => {"device_token"=>"<token>", "active"=>true, "alias"=>"<alias>", "tags"=>[]},
|
219
|
+
# "device_tokens_count" => 3,
|
220
|
+
# "active_device_tokens_count" => 1
|
221
|
+
# }
|
222
|
+
```
|
223
|
+
|
201
224
|
Getting a count of your device tokens
|
202
225
|
-------------------------------------
|
203
226
|
```ruby
|
data/lib/urbanairship.rb
CHANGED
@@ -34,27 +34,39 @@ module Urbanairship
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def device_info(device_token, options = {})
|
38
|
+
if ( (options[:provider] || @provider) == :android ) || ( (options[:provider] || @provider) == 'android' )
|
39
|
+
do_request(:get, "/api/apids/#{device_token}", :authenticate_with => :application_secret)
|
40
|
+
else
|
41
|
+
do_request(:get, "/api/device_tokens/#{device_token}", :authenticate_with => :application_secret)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
37
45
|
def delete_scheduled_push(param)
|
46
|
+
warn "[DEPRECATED] http://docs.urbanairship.com/reference/api/v3/api-v3-migration-guide.html#api-push-batch"
|
38
47
|
path = param.is_a?(Hash) ? "/api/push/scheduled/alias/#{param[:alias].to_s}" : "/api/push/scheduled/#{param.to_s}"
|
39
48
|
do_request(:delete, path, :authenticate_with => :master_secret)
|
40
49
|
end
|
41
50
|
|
42
51
|
def push(options = {})
|
43
|
-
body = parse_push_options(options).to_json
|
44
|
-
do_request(:post, "/api/push/", :body => body, :authenticate_with => :master_secret)
|
52
|
+
body = parse_push_options(options.dup).to_json
|
53
|
+
do_request(:post, "/api/push/", :body => body, :authenticate_with => :master_secret, :version => options[:version])
|
45
54
|
end
|
46
55
|
|
47
56
|
def push_to_segment(options = {})
|
57
|
+
warn "[DEPRECATED] http://docs.urbanairship.com/reference/api/v3/api-v3-migration-guide.html#api-push-segments"
|
48
58
|
body = parse_push_options(options).to_json
|
49
59
|
do_request(:post, "/api/push/segments", :body => body, :authenticate_with => :master_secret)
|
50
60
|
end
|
51
61
|
|
52
62
|
def batch_push(notifications = [])
|
63
|
+
warn "[DEPRECATION] http://docs.urbanairship.com/reference/api/v3/api-v3-migration-guide.html#api-push-batch"
|
53
64
|
body = notifications.map{|notification| parse_push_options(notification)}.to_json
|
54
65
|
do_request(:post, "/api/push/batch/", :body => body, :authenticate_with => :master_secret)
|
55
66
|
end
|
56
67
|
|
57
68
|
def broadcast_push(options = {})
|
69
|
+
warn "[DEPRECATED] http://docs.urbanairship.com/reference/api/v3/api-v3-migration-guide.html#api-push-broadcast"
|
58
70
|
body = parse_push_options(options).to_json
|
59
71
|
do_request(:post, "/api/push/broadcast/", :body => body, :authenticate_with => :master_secret)
|
60
72
|
end
|
@@ -89,6 +101,10 @@ module Urbanairship
|
|
89
101
|
do_request(:post, "/api/tags/#{params[:tag]}", :body => {provider_field => {:remove => [params[:device_token]]}}.to_json, :authenticate_with => :master_secret)
|
90
102
|
end
|
91
103
|
|
104
|
+
def device_tokens
|
105
|
+
do_request(:get, "/api/device_tokens/", :authenticate_with => :master_secret)
|
106
|
+
end
|
107
|
+
|
92
108
|
def device_tokens_count
|
93
109
|
do_request(:get, "/api/device_tokens/count/", :authenticate_with => :master_secret)
|
94
110
|
end
|
@@ -124,6 +140,7 @@ module Urbanairship
|
|
124
140
|
request.basic_auth @application_key, instance_variable_get("@#{options[:authenticate_with]}")
|
125
141
|
request.add_field "Content-Type", options[:content_type] || "application/json"
|
126
142
|
request.body = options[:body] if options[:body]
|
143
|
+
request["Accept"] = "application/vnd.urbanairship+json; version=#{options[:version]};" if options[:version]
|
127
144
|
|
128
145
|
Timer.timeout(request_timeout) do
|
129
146
|
start_time = Time.now
|
@@ -135,7 +152,7 @@ module Urbanairship
|
|
135
152
|
unless logger.nil?
|
136
153
|
logger.error "Urbanairship request timed out after #{request_timeout} seconds: [#{http_method} #{request.path} #{request.body}]"
|
137
154
|
end
|
138
|
-
Urbanairship::Response.wrap(nil, :body => {
|
155
|
+
Urbanairship::Response.wrap(nil, :body => {'error' => 'Request timeout'}, :code => '503')
|
139
156
|
end
|
140
157
|
|
141
158
|
def verify_configuration_values(*symbols)
|
@@ -155,6 +172,7 @@ module Urbanairship
|
|
155
172
|
def parse_push_options(hash = {})
|
156
173
|
hash[:aliases] = hash[:aliases].map{|a| a.to_s} unless hash[:aliases].nil?
|
157
174
|
hash[:schedule_for] = hash[:schedule_for].map{|elem| process_scheduled_elem(elem)} unless hash[:schedule_for].nil?
|
175
|
+
hash.delete(:version)
|
158
176
|
hash
|
159
177
|
end
|
160
178
|
|
data/spec/urbanairship_spec.rb
CHANGED
@@ -16,6 +16,15 @@ shared_examples_for "an Urbanairship client" do
|
|
16
16
|
FakeWeb.register_uri(:delete, /my_app_key\:my_app_secret\@go\.urbanairship.com\/api\/device_tokens\/.+/, :status => ["204", "No Content"])
|
17
17
|
FakeWeb.register_uri(:delete, /bad_key\:my_app_secret\@go\.urbanairship.com\/api\/device_tokens\/.+/, :status => ["401", "Unauthorized"])
|
18
18
|
|
19
|
+
# device_info
|
20
|
+
FakeWeb.register_uri(:get, /my_app_key\:my_app_secret\@go\.urbanairship.com\/api\/apids\/.+/, :status => ["200", "OK"], :body => "{\"active\":true,\"alias\":null}")
|
21
|
+
FakeWeb.register_uri(:get, /my_app_key\:my_app_secret\@go\.urbanairship.com\/api\/device_tokens\/.+/, :status => ["200", "OK"], :body => "{\"active\":true,\"alias\":null}")
|
22
|
+
FakeWeb.register_uri(:get, /bad_key\:my_app_secret\@go\.urbanairship.com\/api\/device_tokens\/.+/, :status => ["401", "Unauthorized"])
|
23
|
+
|
24
|
+
# device_tokens
|
25
|
+
FakeWeb.register_uri(:get, "https://my_app_key:my_master_secret@go.urbanairship.com/api/device_tokens/", :status => ["200", "OK"], :body => '{"device_tokens":[{"device_token": "0101F9929660BAD9FFF31A0B5FA32620FA988507DFFA52BD6C1C1F4783EDA2DB","active": false,"alias": null, "tags": []}], "device_tokens_count":50, "active_device_tokens_count":55}')
|
26
|
+
FakeWeb.register_uri(:get, "https://my_app_key2:my_master_secret2@go.urbanairship.com/api/device_tokens/", :status => ["401", "OK"])
|
27
|
+
|
19
28
|
# push
|
20
29
|
FakeWeb.register_uri(:post, "https://my_app_key:my_master_secret@go.urbanairship.com/api/push/", :status => ["200", "OK"])
|
21
30
|
FakeWeb.register_uri(:post, "https://my_app_key2:my_master_secret2@go.urbanairship.com/api/push/", :status => ["400", "Bad Request"])
|
@@ -485,6 +494,68 @@ shared_examples_for "an Urbanairship client" do
|
|
485
494
|
|
486
495
|
end
|
487
496
|
|
497
|
+
describe "::device_info" do
|
498
|
+
before(:each) do
|
499
|
+
@valid_params = {:alias => 'one'}
|
500
|
+
subject.application_key = "my_app_key"
|
501
|
+
subject.application_secret = "my_app_secret"
|
502
|
+
end
|
503
|
+
|
504
|
+
it "raises an error if call is made without an app key and secret configured" do
|
505
|
+
subject.application_key = nil
|
506
|
+
subject.application_secret = nil
|
507
|
+
|
508
|
+
lambda {
|
509
|
+
subject.device_info("asdf1234")
|
510
|
+
}.should raise_error(RuntimeError, "Must configure application_key, application_secret before making this request.")
|
511
|
+
end
|
512
|
+
|
513
|
+
it "uses app key and secret to sign the request" do
|
514
|
+
subject.device_info("device_token")
|
515
|
+
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_app_secret').chomp}"
|
516
|
+
end
|
517
|
+
|
518
|
+
it "takes and sends a device token" do
|
519
|
+
subject.device_info("device_token")
|
520
|
+
FakeWeb.last_request.path.should == "/api/device_tokens/device_token"
|
521
|
+
end
|
522
|
+
|
523
|
+
it "returns false when the authorization is invalid" do
|
524
|
+
subject.application_key = "bad_key"
|
525
|
+
subject.device_info("device_token").success?.should == false
|
526
|
+
end
|
527
|
+
|
528
|
+
it "uses the iOS interface by default" do
|
529
|
+
subject.device_info("device_token")
|
530
|
+
FakeWeb.last_request.path.should == "/api/device_tokens/device_token"
|
531
|
+
end
|
532
|
+
|
533
|
+
it "uses the android interface if 'provider' configuration option is set to :android Symbol" do
|
534
|
+
subject.provider = :android
|
535
|
+
subject.device_info("device_token")
|
536
|
+
FakeWeb.last_request.path.should == "/api/apids/device_token"
|
537
|
+
subject.provider = nil
|
538
|
+
end
|
539
|
+
|
540
|
+
it "uses the android interface if 'provider' configuration option is set to 'android' String" do
|
541
|
+
subject.provider = 'android'
|
542
|
+
subject.device_info("device_token")
|
543
|
+
FakeWeb.last_request.path.should == "/api/apids/device_token"
|
544
|
+
subject.provider = nil
|
545
|
+
end
|
546
|
+
|
547
|
+
it "uses the android interface if :provider Symbol key is passed an :android Symbol value" do
|
548
|
+
subject.device_info("device_token", :provider => :android)
|
549
|
+
FakeWeb.last_request.path.should == "/api/apids/device_token"
|
550
|
+
end
|
551
|
+
|
552
|
+
it "uses the android interface if 'provider' Symbol key is passed an 'android' String value" do
|
553
|
+
subject.device_info("device_token", :provider => "android")
|
554
|
+
FakeWeb.last_request.path.should == "/api/apids/device_token"
|
555
|
+
end
|
556
|
+
|
557
|
+
end
|
558
|
+
|
488
559
|
describe "::delete_scheduled_push" do
|
489
560
|
before(:each) do
|
490
561
|
subject.application_key = "my_app_key"
|
@@ -561,6 +632,11 @@ shared_examples_for "an Urbanairship client" do
|
|
561
632
|
subject.push(@valid_params).success?.should == false
|
562
633
|
end
|
563
634
|
|
635
|
+
it "uses v3 of the API when requested" do
|
636
|
+
subject.push(@valid_params.merge(:version => 3)).success?.should == true
|
637
|
+
FakeWeb.last_request["Accept"].should == "application/vnd.urbanairship+json; version=3;"
|
638
|
+
end
|
639
|
+
|
564
640
|
it "adds schedule_for to the JSON payload" do
|
565
641
|
time = Time.parse("Oct 17th, 2010, 8:00 PM UTC")
|
566
642
|
subject.push(@valid_params.merge(:schedule_for => [time]))
|
@@ -781,6 +857,42 @@ shared_examples_for "an Urbanairship client" do
|
|
781
857
|
end
|
782
858
|
end
|
783
859
|
|
860
|
+
describe "::device_tokens" do
|
861
|
+
|
862
|
+
before(:each) do
|
863
|
+
subject.application_key = "my_app_key"
|
864
|
+
subject.master_secret = "my_master_secret"
|
865
|
+
end
|
866
|
+
|
867
|
+
it "raises an error if call is made without an app key and master secret configured" do
|
868
|
+
subject.application_key = nil
|
869
|
+
subject.master_secret = nil
|
870
|
+
|
871
|
+
lambda {
|
872
|
+
subject.device_tokens_count
|
873
|
+
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
874
|
+
end
|
875
|
+
|
876
|
+
it "uses app key and secret to sign the request" do
|
877
|
+
subject.device_tokens_count
|
878
|
+
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
879
|
+
end
|
880
|
+
|
881
|
+
it "returns a hash as response from the Device Token List API with an array of device tokens" do
|
882
|
+
response = subject.device_tokens
|
883
|
+
response["device_tokens"].class.should == Array
|
884
|
+
response["device_tokens_count"].should == 50
|
885
|
+
response["active_device_tokens_count"].should == 55
|
886
|
+
end
|
887
|
+
|
888
|
+
it "success? is false when the call doesn't return 200" do
|
889
|
+
subject.application_key = "my_app_key2"
|
890
|
+
subject.master_secret = "my_master_secret2"
|
891
|
+
subject.device_tokens.success?.should == false
|
892
|
+
end
|
893
|
+
|
894
|
+
end
|
895
|
+
|
784
896
|
describe "::device_tokens_count" do
|
785
897
|
|
786
898
|
before(:each) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: urbanairship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -76,7 +76,8 @@ files:
|
|
76
76
|
- spec/spec_helper.rb
|
77
77
|
- spec/urbanairship_spec.rb
|
78
78
|
homepage: http://github.com/groupon/urbanairship
|
79
|
-
licenses:
|
79
|
+
licenses:
|
80
|
+
- BSD
|
80
81
|
post_install_message:
|
81
82
|
rdoc_options: []
|
82
83
|
require_paths:
|
@@ -95,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
96
|
version: '0'
|
96
97
|
requirements: []
|
97
98
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.8.
|
99
|
+
rubygems_version: 1.8.23
|
99
100
|
signing_key:
|
100
101
|
specification_version: 3
|
101
102
|
summary: A Ruby wrapper for the Urban Airship API
|