urbanairship 2.2.3 → 2.2.4

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 CHANGED
@@ -47,6 +47,20 @@ notification = {
47
47
  :aps => {:alert => 'You have a new message!', :badge => 1}
48
48
  }
49
49
 
50
+ Urbanairship.push(notification) # =>
51
+ # {
52
+ # "scheduled_notifications" => ["https://go.urbanairship.com/api/push/scheduled/123456"]
53
+ # }
54
+ ```
55
+ ### Using aliases instead of device tokens ###
56
+
57
+ ```ruby
58
+ notification = {
59
+ :schedule_for => [1.hour.from_now],
60
+ :aliases => ['ALIAS-ONE', 'ALIAS-TWO'],
61
+ :aps => {:alert => 'You have a new message!', :badge => 1}
62
+ }
63
+
50
64
  Urbanairship.push(notification) # =>
51
65
  # {
52
66
  # "scheduled_notifications" => ["https://go.urbanairship.com/api/push/scheduled/123456"]
@@ -72,27 +86,6 @@ notifications = [
72
86
  Urbanairship.batch_push(notifications)
73
87
  ```
74
88
 
75
- Sending notifications to a segment
76
- ---------------------------
77
- Urban Airship segments let you send a push notification to a subset of relevant users based on location, time, preferences, and behavior. You can read more about segments in the [Urban Airship docs](https://docs.urbanairship.com/display/DOCS/Server%3A+Segments+API).
78
-
79
- ```ruby
80
- notification = {
81
- :schedule_for => [1.hour.from_now],
82
- :segments => ['SEGMENT-ID'],
83
- :ios => {
84
- :aps => {
85
- :alert => 'You have a new message!', :badge => 1
86
- }
87
- },
88
- :android => {
89
- :alert => 'You have a new message!', :badge => 1
90
- }
91
- }
92
-
93
- Urbanairship.push_to_segment(notification)
94
- ```
95
-
96
89
  Sending broadcast notifications
97
90
  -------------------------------
98
91
  Urban Airship allows you to send a broadcast notification to all active registered device tokens for your app.
@@ -138,6 +131,43 @@ Urbanairship.delete_scheduled_push(123456789)
138
131
  Urbanairship.delete_scheduled_push(:alias => "deadbeef")
139
132
  ```
140
133
 
134
+ Segments
135
+ ---------------------------
136
+ Urban Airship segments let you send a push notification to a subset of relevant users based on location, time, preferences, and behavior. You can read more about segments in the [Urban Airship docs](https://docs.urbanairship.com/display/DOCS/Server%3A+Segments+API).
137
+
138
+ ```ruby
139
+ notification = {
140
+ :schedule_for => [1.hour.from_now],
141
+ :segments => ['SEGMENT-ID'],
142
+ :ios => {
143
+ :aps => {
144
+ :alert => 'You have a new message!', :badge => 1
145
+ }
146
+ },
147
+ :android => {
148
+ :alert => 'You have a new message!', :badge => 1
149
+ }
150
+ }
151
+
152
+ Urbanairship.push_to_segment(notification)
153
+ ```
154
+
155
+ ### Listing your segments ###
156
+
157
+ ```ruby
158
+ Urbanairship.segments # =>
159
+ # {
160
+ # "segments" => [
161
+ # {
162
+ # "id" => "abcd-efgh-ijkl",
163
+ # "display_name" => "segment1",
164
+ # "creation_date" => 1360950614201,
165
+ # "modification_date" => 1360950614201
166
+ # }
167
+ # ]
168
+ # }
169
+ ```
170
+
141
171
  Getting a count of your device tokens
142
172
  -------------------------------------
143
173
  ```ruby
data/lib/urbanairship.rb CHANGED
@@ -67,6 +67,10 @@ module Urbanairship
67
67
  do_request(:get, "/api/tags/", :authenticate_with => :master_secret)
68
68
  end
69
69
 
70
+ def segments
71
+ do_request(:get, "/api/segments", :authenticate_with => :master_secret)
72
+ end
73
+
70
74
  def add_tag(tag)
71
75
  do_request(:put, "/api/tags/#{tag}", :authenticate_with => :master_secret, :content_type => 'text/plain')
72
76
  end
@@ -67,6 +67,10 @@ shared_examples_for "an Urbanairship client" do
67
67
  FakeWeb.register_uri(:delete, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/device_tokens\/valid_device_token\/tags\/non_existant_tag/, :status => ["404", "OK"])
68
68
  FakeWeb.register_uri(:delete, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/device_tokens\/a_device_token\/tags\/a_tag/, :status => ["500", "Internal Server Error"])
69
69
 
70
+ #Segments
71
+ FakeWeb.register_uri(:get, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/segments/, :status => ["200", "OK"], :body => '{"segments":[{"id":"abcd-efgh-ijkl", "display_name":"test1", "creation_date":1360950614201, "modification_date":1360950614201}, {"id": "mnop-qrst-uvwx", "display_name": "test2", "creation_date":1360950614202, "modification_date":1360950614202}]}')
72
+ FakeWeb.register_uri(:get, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/segments/, :status => ["500", "Internal Server Error"])
73
+
70
74
  # push to segment
71
75
  FakeWeb.register_uri(:post, "https://my_app_key:my_master_secret@go.urbanairship.com/api/push/segments", :status => ["200", "OK"])
72
76
  FakeWeb.register_uri(:post, "https://my_app_key2:my_master_secret2@go.urbanairship.com/api/push/segments", :status => ["400", "Bad Request"])
@@ -763,6 +767,45 @@ shared_examples_for "an Urbanairship client" do
763
767
 
764
768
  end
765
769
 
770
+ describe "::segments" do
771
+ before(:each) do
772
+ subject.application_key = "my_app_key"
773
+ subject.master_secret = "my_master_secret"
774
+ end
775
+
776
+ it "raises an error if call is made without an app key and master secret configured" do
777
+ subject.application_key = nil
778
+ subject.master_secret = nil
779
+
780
+ lambda {
781
+ subject.segments
782
+ }.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
783
+ end
784
+
785
+ it "uses app key and secret to sign the request" do
786
+ subject.segments
787
+ FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
788
+ end
789
+
790
+ it "returns valid segments" do
791
+ response = subject.segments
792
+ response.first.should include("segments")
793
+ response["segments"].each do |s|
794
+ ["id", "display_name", "creation_date", "modification_date"].each do |k|
795
+ s.should include(k)
796
+ end
797
+ end
798
+ end
799
+
800
+ it "success? is false when the call doesn't return 200" do
801
+ subject.application_key = "my_app_key2"
802
+ subject.master_secret = "my_master_secret2"
803
+ subject.segments.success?.should == false
804
+ end
805
+
806
+ end
807
+
808
+
766
809
  describe "logging" do
767
810
 
768
811
  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.3
4
+ version: 2.2.4
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-31 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json