urbanairship 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -138,6 +138,16 @@ Urbanairship.delete_scheduled_push(123456789)
138
138
  Urbanairship.delete_scheduled_push(:alias => "deadbeef")
139
139
  ```
140
140
 
141
+ Getting a count of your device tokens
142
+ -------------------------------------
143
+ ```ruby
144
+ Urbanairship.device_tokens_count # =>
145
+ # {
146
+ # "device_tokens_count" => 3,
147
+ # "active_device_tokens_count" => 1
148
+ # }
149
+ ```
150
+
141
151
  Tags
142
152
  ----
143
153
 
data/lib/urbanairship.rb CHANGED
@@ -76,7 +76,7 @@ module Urbanairship
76
76
  end
77
77
 
78
78
  def tags_for_device(device_token)
79
- do_request(:get, "/api/device_tokens/#{device_token}/tags", :authenticate_with => :master_secret)
79
+ do_request(:get, "/api/device_tokens/#{device_token}/tags/", :authenticate_with => :master_secret)
80
80
  end
81
81
 
82
82
  def tag_device(params)
@@ -87,6 +87,10 @@ module Urbanairship
87
87
  do_request(:delete, "/api/device_tokens/#{params[:device_token]}/tags/#{params[:tag]}", :authenticate_with => :master_secret)
88
88
  end
89
89
 
90
+ def device_tokens_count
91
+ do_request(:get, "/api/device_tokens/count/", :authenticate_with => :master_secret)
92
+ end
93
+
90
94
  private
91
95
 
92
96
  def do_request(http_method, path, options = {})
@@ -71,6 +71,10 @@ shared_examples_for "an Urbanairship client" do
71
71
  FakeWeb.register_uri(:post, "https://my_app_key:my_master_secret@go.urbanairship.com/api/push/segments", :status => ["200", "OK"])
72
72
  FakeWeb.register_uri(:post, "https://my_app_key2:my_master_secret2@go.urbanairship.com/api/push/segments", :status => ["400", "Bad Request"])
73
73
  FakeWeb.register_uri(:post, /bad_key\:my_master_secret\@go\.urbanairship\.com/, :status => ["401", "Unauthorized"])
74
+
75
+ #device_tokens_count
76
+ FakeWeb.register_uri(:get, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/device_tokens\/count/, :status => ["200", "OK"], :body => "{\"device_tokens_count\":50, \"active_device_tokens_count\":55}")
77
+ FakeWeb.register_uri(:get, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/device_tokens\/count/, :status => ["500", "Internal Server Error"])
74
78
  end
75
79
 
76
80
  describe "configuration" do
@@ -724,6 +728,41 @@ shared_examples_for "an Urbanairship client" do
724
728
  end
725
729
  end
726
730
 
731
+ describe "::device_tokens_count" do
732
+
733
+ before(:each) do
734
+ subject.application_key = "my_app_key"
735
+ subject.master_secret = "my_master_secret"
736
+ end
737
+
738
+ it "raises an error if call is made without an app key and master secret configured" do
739
+ subject.application_key = nil
740
+ subject.master_secret = nil
741
+
742
+ lambda {
743
+ subject.device_tokens_count
744
+ }.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
745
+ end
746
+
747
+ it "uses app key and secret to sign the request" do
748
+ subject.device_tokens_count
749
+ FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
750
+ end
751
+
752
+ it "returns a hash as response from the Device Token List API" do
753
+ response = subject.device_tokens_count
754
+ response["device_tokens_count"].should == 50
755
+ response["active_device_tokens_count"].should == 55
756
+ end
757
+
758
+ it "success? is false when the call doesn't return 200" do
759
+ subject.application_key = "my_app_key2"
760
+ subject.master_secret = "my_master_secret2"
761
+ subject.device_tokens_count.success?.should == false
762
+ end
763
+
764
+ end
765
+
727
766
  describe "logging" do
728
767
 
729
768
  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.2.2
4
+ version: 2.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 1.8.24
98
+ rubygems_version: 1.8.25
99
99
  signing_key:
100
100
  specification_version: 3
101
101
  summary: A Ruby wrapper for the Urban Airship API