urbanairship 2.2.4 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +30 -0
- data/lib/urbanairship.rb +20 -4
- data/spec/urbanairship_spec.rb +62 -5
- metadata +2 -2
data/README.markdown
CHANGED
@@ -152,6 +152,14 @@ notification = {
|
|
152
152
|
Urbanairship.push_to_segment(notification)
|
153
153
|
```
|
154
154
|
|
155
|
+
### Creating a segment ###
|
156
|
+
``` ruby
|
157
|
+
Urbanairship.create_segment({
|
158
|
+
:display_name => 'segment1',
|
159
|
+
:criteria => {:and => [{:tag => 'one'}, {:tag => 'two'}]}
|
160
|
+
}) # => {}
|
161
|
+
```
|
162
|
+
|
155
163
|
### Listing your segments ###
|
156
164
|
|
157
165
|
```ruby
|
@@ -166,6 +174,28 @@ Urbanairship.segments # =>
|
|
166
174
|
# }
|
167
175
|
# ]
|
168
176
|
# }
|
177
|
+
|
178
|
+
Urbanairship.segment("abcd-efgh-ijkl") # =>
|
179
|
+
# {
|
180
|
+
# "id" => "abcd-efgh-ijkl",
|
181
|
+
# "display_name" => "segment1",
|
182
|
+
# "creation_date" => 1360950614201,
|
183
|
+
# "modification_date" => 1360950614201
|
184
|
+
# }
|
185
|
+
```
|
186
|
+
|
187
|
+
### Modifying a segment ###
|
188
|
+
Note that you must provide both the display name and criteria when updating a segment, even if you are only changing one or the other.
|
189
|
+
``` ruby
|
190
|
+
Urbanairship.update_segment({
|
191
|
+
:display_name => 'segment1',
|
192
|
+
:criteria => {:and => [{:tag => 'asdf'}]}
|
193
|
+
}) # => {}
|
194
|
+
```
|
195
|
+
|
196
|
+
### Deleting a segment ###
|
197
|
+
```ruby
|
198
|
+
Urbanairship.delete_segment("abcd-efgh-ijkl") # => {}
|
169
199
|
```
|
170
200
|
|
171
201
|
Getting a count of your device tokens
|
data/lib/urbanairship.rb
CHANGED
@@ -67,10 +67,6 @@ 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
|
-
|
74
70
|
def add_tag(tag)
|
75
71
|
do_request(:put, "/api/tags/#{tag}", :authenticate_with => :master_secret, :content_type => 'text/plain')
|
76
72
|
end
|
@@ -95,6 +91,26 @@ module Urbanairship
|
|
95
91
|
do_request(:get, "/api/device_tokens/count/", :authenticate_with => :master_secret)
|
96
92
|
end
|
97
93
|
|
94
|
+
def segments
|
95
|
+
do_request(:get, "/api/segments", :authenticate_with => :master_secret)
|
96
|
+
end
|
97
|
+
|
98
|
+
def create_segment(segment)
|
99
|
+
do_request(:post, "/api/segments", :body => segment.to_json, :authenticate_with => :master_secret)
|
100
|
+
end
|
101
|
+
|
102
|
+
def segment(id)
|
103
|
+
do_request(:get, "/api/segments/#{id}", :authenticate_with => :master_secret)
|
104
|
+
end
|
105
|
+
|
106
|
+
def update_segment(id, segment)
|
107
|
+
do_request(:put, "/api/segments/#{id}", :body => segment.to_json, :authenticate_with => :master_secret)
|
108
|
+
end
|
109
|
+
|
110
|
+
def delete_segment(id)
|
111
|
+
do_request(:delete, "/api/segments/#{id}", :authenticate_with => :master_secret)
|
112
|
+
end
|
113
|
+
|
98
114
|
private
|
99
115
|
|
100
116
|
def do_request(http_method, path, options = {})
|
data/spec/urbanairship_spec.rb
CHANGED
@@ -67,9 +67,28 @@ 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
|
-
|
71
|
-
|
72
|
-
FakeWeb.register_uri(:get, /
|
70
|
+
#Get Segment
|
71
|
+
FakeWeb.register_uri(:get, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/segments\/valid_id/, :status => ["200", "OK"], :body => '{"display_name":"Male in NY", "criteria":{"and":[{"tag":"male"}, {"tag":"in NY"}]}}')
|
72
|
+
FakeWeb.register_uri(:get, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/segments\/not_found/, :status => ["404", "OK"])
|
73
|
+
FakeWeb.register_uri(:get, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/segments\/invalid_segment/, :status => ["500", "Internal Server Error"])
|
74
|
+
|
75
|
+
#Get List of Segments
|
76
|
+
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}]}')
|
77
|
+
FakeWeb.register_uri(:get, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/segments$/, :status => ["500", "Internal Server Error"])
|
78
|
+
|
79
|
+
#Create Segment
|
80
|
+
FakeWeb.register_uri(:post, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/segments/, :status => ["201", "OK"])
|
81
|
+
FakeWeb.register_uri(:post, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/segments/, :status => ["500", "Internal Server Error"])
|
82
|
+
|
83
|
+
#Update Segment
|
84
|
+
FakeWeb.register_uri(:put, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/segments\/valid_segment/, :status => ["200", "OK"])
|
85
|
+
FakeWeb.register_uri(:put, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/segments\/invalid_segment/, :status => ["404", "OK"])
|
86
|
+
FakeWeb.register_uri(:put, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/segments\/a_segment/, :status => ["500", "Internal Server Error"])
|
87
|
+
|
88
|
+
#Delete Segment
|
89
|
+
FakeWeb.register_uri(:delete, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/segments\/valid_segment/, :status => ["204", "OK"])
|
90
|
+
FakeWeb.register_uri(:delete, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/segments\/invalid_segment/, :status => ["404", "OK"])
|
91
|
+
FakeWeb.register_uri(:delete, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/segments\/a_segment/, :status => ["500", "Internal Server Error"])
|
73
92
|
|
74
93
|
# push to segment
|
75
94
|
FakeWeb.register_uri(:post, "https://my_app_key:my_master_secret@go.urbanairship.com/api/push/segments", :status => ["200", "OK"])
|
@@ -771,6 +790,7 @@ shared_examples_for "an Urbanairship client" do
|
|
771
790
|
before(:each) do
|
772
791
|
subject.application_key = "my_app_key"
|
773
792
|
subject.master_secret = "my_master_secret"
|
793
|
+
@valid_segment = {:display_name => "Test Male NY", :criteria => {:and => [ {:tag => "male"}, {:tag => "NY"}]} }
|
774
794
|
end
|
775
795
|
|
776
796
|
it "raises an error if call is made without an app key and master secret configured" do
|
@@ -790,11 +810,48 @@ shared_examples_for "an Urbanairship client" do
|
|
790
810
|
it "returns valid segments" do
|
791
811
|
response = subject.segments
|
792
812
|
response.first.should include("segments")
|
793
|
-
response["segments"].each do |s|
|
813
|
+
response["segments"].each do |s|
|
794
814
|
["id", "display_name", "creation_date", "modification_date"].each do |k|
|
795
815
|
s.should include(k)
|
796
816
|
end
|
797
|
-
end
|
817
|
+
end
|
818
|
+
end
|
819
|
+
|
820
|
+
it "can create a valid segment" do
|
821
|
+
response = subject.create_segment(@valid_segment)
|
822
|
+
response.code.should == "201"
|
823
|
+
end
|
824
|
+
|
825
|
+
it "can get a segment given its id" do
|
826
|
+
response = subject.segment("valid_id")
|
827
|
+
response.code.should == "200"
|
828
|
+
response.should include("display_name")
|
829
|
+
response.should include("criteria")
|
830
|
+
end
|
831
|
+
|
832
|
+
it "returns not found if invalid segment id is given" do
|
833
|
+
response = subject.segment("not_found")
|
834
|
+
response.code.should == "404"
|
835
|
+
end
|
836
|
+
|
837
|
+
it "can update a segment given a valid id" do
|
838
|
+
response = subject.update_segment("valid_segment", @valid_segment)
|
839
|
+
response.code.should == "200"
|
840
|
+
end
|
841
|
+
|
842
|
+
it "cant update a segment when given an invalid id" do
|
843
|
+
response = subject.update_segment("invalid_segment", @valid_segment)
|
844
|
+
response.code.should == "404"
|
845
|
+
end
|
846
|
+
|
847
|
+
it "can delete a segment given a valid id" do
|
848
|
+
response = subject.delete_segment("valid_segment")
|
849
|
+
response.code.should == "204"
|
850
|
+
end
|
851
|
+
|
852
|
+
it "cant delete a segment given an invalid id" do
|
853
|
+
response = subject.delete_segment("invalid_segment")
|
854
|
+
response.code.should == "404"
|
798
855
|
end
|
799
856
|
|
800
857
|
it "success? is false when the call doesn't return 200" 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.3.0
|
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-02-
|
12
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|