urbanairship 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/urbanairship.rb +2 -2
- data/spec/response_spec.rb +2 -0
- data/spec/urbanairship_spec.rb +39 -35
- metadata +2 -2
data/lib/urbanairship.rb
CHANGED
@@ -68,7 +68,7 @@ module Urbanairship
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def add_tag(tag)
|
71
|
-
do_request(:put, "/api/tags/#{tag}", :authenticate_with => :master_secret)
|
71
|
+
do_request(:put, "/api/tags/#{tag}", :authenticate_with => :master_secret, :content_type => 'text/plain')
|
72
72
|
end
|
73
73
|
|
74
74
|
def remove_tag(tag)
|
@@ -96,7 +96,7 @@ module Urbanairship
|
|
96
96
|
|
97
97
|
request = klass.new(path)
|
98
98
|
request.basic_auth @application_key, instance_variable_get("@#{options[:authenticate_with]}")
|
99
|
-
request.add_field "Content-Type", "application/json"
|
99
|
+
request.add_field "Content-Type", options[:content_type] || "application/json"
|
100
100
|
request.body = options[:body] if options[:body]
|
101
101
|
|
102
102
|
Timer.timeout(request_timeout) do
|
data/spec/response_spec.rb
CHANGED
data/spec/urbanairship_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
shared_examples_for "an Urbanairship client" do
|
2
4
|
before(:all) do
|
3
5
|
FakeWeb.allow_net_connect = false
|
@@ -35,41 +37,40 @@ shared_examples_for "an Urbanairship client" do
|
|
35
37
|
# feedback
|
36
38
|
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\"}]")
|
37
39
|
FakeWeb.register_uri(:get, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/device_tokens\/feedback/, :status => ["500", "Internal Server Error"])
|
38
|
-
|
40
|
+
|
39
41
|
#tags
|
40
42
|
FakeWeb.register_uri(:get, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/tags/, :status => ["200", "OK"], :body => "[{\"tags\":[\"tag1\",\"tag2\"]}]")
|
41
43
|
FakeWeb.register_uri(:get, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/tags/, :status => ["500", "Internal Server Error"])
|
42
|
-
|
44
|
+
|
43
45
|
#add_tag
|
44
46
|
FakeWeb.register_uri(:put, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/tags\/new_tag/, :status => ["200", "OK"])
|
45
47
|
FakeWeb.register_uri(:put, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/tags\/existing_tag/, :status => ["201", "OK"])
|
46
48
|
FakeWeb.register_uri(:put, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/tags\/a_tag/, :status => ["500", "Internal Server Error"])
|
47
|
-
|
49
|
+
|
48
50
|
#remove_tag
|
49
51
|
FakeWeb.register_uri(:delete, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/tags\/non_deleted_tag/, :status => ["204", "OK"])
|
50
52
|
FakeWeb.register_uri(:delete, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/tags\/deleted_tag/, :status => ["404", "OK"])
|
51
53
|
FakeWeb.register_uri(:delete, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/tags\/a_tag/, :status => ["500", "Internal Server Error"])
|
52
|
-
|
54
|
+
|
53
55
|
#tags_for_device_tokens
|
54
56
|
FakeWeb.register_uri(:get, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/device_tokens\/valid_device_token\/tags/, :status => ["200", "OK"], :body => "[{\"tags\":[\"tag1\",\"tag2\"]}]")
|
55
57
|
FakeWeb.register_uri(:get, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/device_tokens\/invalid_device_token\/tags/, :status => ["404", "OK"])
|
56
58
|
FakeWeb.register_uri(:get, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/device_tokens\/a_device_token\/tags/, :status => ["500", "Internal Server Error"])
|
57
|
-
|
59
|
+
|
58
60
|
##tag_device
|
59
61
|
FakeWeb.register_uri(:put, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/device_tokens\/valid_device_token\/tags\/new_tag/, :status => ["201", "OK"])
|
60
62
|
FakeWeb.register_uri(:put, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/device_tokens\/valid_device_token\/tags\/existing_tag/, :status => ["200", "OK"])
|
61
63
|
FakeWeb.register_uri(:put, /my_app_key2\:my_master_secret2\@go\.urbanairship.com\/api\/device_tokens\/a_device_token\/tags\/a_tag/, :status => ["500", "Internal Server Error"])
|
62
|
-
|
64
|
+
|
63
65
|
#untag_device
|
64
66
|
FakeWeb.register_uri(:delete, /my_app_key\:my_master_secret\@go\.urbanairship.com\/api\/device_tokens\/valid_device_token\/tags\/existing_tag/, :status => ["204", "OK"])
|
65
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"])
|
66
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"])
|
67
|
-
|
69
|
+
|
68
70
|
# push to segment
|
69
71
|
FakeWeb.register_uri(:post, "https://my_app_key:my_master_secret@go.urbanairship.com/api/push/segments", :status => ["200", "OK"])
|
70
72
|
FakeWeb.register_uri(:post, "https://my_app_key2:my_master_secret2@go.urbanairship.com/api/push/segments", :status => ["400", "Bad Request"])
|
71
73
|
FakeWeb.register_uri(:post, /bad_key\:my_master_secret\@go\.urbanairship\.com/, :status => ["401", "Unauthorized"])
|
72
|
-
|
73
74
|
end
|
74
75
|
|
75
76
|
describe "configuration" do
|
@@ -91,7 +92,7 @@ shared_examples_for "an Urbanairship client" do
|
|
91
92
|
subject.master_secret.should == "asdf1234"
|
92
93
|
end
|
93
94
|
end
|
94
|
-
|
95
|
+
|
95
96
|
describe "::tags" do
|
96
97
|
before(:each) do
|
97
98
|
subject.application_key = "my_app_key"
|
@@ -106,27 +107,27 @@ shared_examples_for "an Urbanairship client" do
|
|
106
107
|
subject.tags
|
107
108
|
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
108
109
|
end
|
109
|
-
|
110
|
+
|
110
111
|
it "uses app key and secret to sign the request" do
|
111
112
|
subject.tags
|
112
113
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
113
114
|
end
|
114
|
-
|
115
|
+
|
115
116
|
it "returns valid tags" do
|
116
117
|
response = subject.tags
|
117
118
|
response.first.should include("tags")
|
118
119
|
response.first["tags"].should include("tag1")
|
119
120
|
response.first["tags"].should include("tag2")
|
120
121
|
end
|
121
|
-
|
122
|
+
|
122
123
|
it "success? is false when the call doesn't return 200" do
|
123
124
|
subject.application_key = "my_app_key2"
|
124
125
|
subject.master_secret = "my_master_secret2"
|
125
126
|
subject.tags.success?.should == false
|
126
127
|
end
|
127
|
-
|
128
|
+
|
128
129
|
end
|
129
|
-
|
130
|
+
|
130
131
|
describe "::add_tag" do
|
131
132
|
before(:each) do
|
132
133
|
subject.application_key = "my_app_key"
|
@@ -141,30 +142,34 @@ shared_examples_for "an Urbanairship client" do
|
|
141
142
|
subject.add_tag('a_tag')
|
142
143
|
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
143
144
|
end
|
144
|
-
|
145
|
+
|
145
146
|
it "uses app key and secret to sign the request" do
|
146
147
|
subject.add_tag('new_tag')
|
147
148
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
148
149
|
end
|
149
|
-
|
150
|
+
|
150
151
|
it "adds a new tag" do
|
151
152
|
subject.add_tag('new_tag').success?.should == true
|
152
153
|
subject.add_tag('new_tag').code.should == "200"
|
153
154
|
end
|
154
|
-
|
155
|
+
|
155
156
|
it "adds an exisiting tag" do
|
156
157
|
subject.add_tag('existing_tag').success?.should == true
|
157
158
|
subject.add_tag('existing_tag').code.should == "201"
|
158
159
|
end
|
159
|
-
|
160
|
+
|
160
161
|
it "success? is false when the call doesn't return 200 or 201" do
|
161
162
|
subject.application_key = "my_app_key2"
|
162
163
|
subject.master_secret = "my_master_secret2"
|
163
164
|
subject.add_tag('a_tag').success?.should == false
|
164
165
|
end
|
165
|
-
|
166
|
+
|
167
|
+
it "sets the content-type to text/plain" do
|
168
|
+
subject.add_tag('new_tag')
|
169
|
+
FakeWeb.last_request['content-type'].should == "text/plain"
|
170
|
+
end
|
166
171
|
end
|
167
|
-
|
172
|
+
|
168
173
|
describe "::remove_tag" do
|
169
174
|
before(:each) do
|
170
175
|
subject.application_key = "my_app_key"
|
@@ -194,20 +199,20 @@ shared_examples_for "an Urbanairship client" do
|
|
194
199
|
subject.remove_tag('deleted_tag').success?.should == false
|
195
200
|
subject.remove_tag('deleted_tag').code.should == "404"
|
196
201
|
end
|
197
|
-
|
202
|
+
|
198
203
|
it "success? is false when the call doesn't return 204" do
|
199
204
|
subject.application_key = "my_app_key2"
|
200
205
|
subject.master_secret = "my_master_secret2"
|
201
206
|
subject.add_tag('a_tag').success?.should == false
|
202
207
|
end
|
203
208
|
end
|
204
|
-
|
209
|
+
|
205
210
|
describe "::tags_for_device" do
|
206
211
|
before(:each) do
|
207
212
|
subject.application_key = "my_app_key"
|
208
213
|
subject.master_secret = "my_master_secret"
|
209
214
|
end
|
210
|
-
|
215
|
+
|
211
216
|
it "raises an error if call is made without an app key and master secret configured" do
|
212
217
|
subject.application_key = nil
|
213
218
|
subject.master_secret = nil
|
@@ -216,12 +221,12 @@ shared_examples_for "an Urbanairship client" do
|
|
216
221
|
subject.tags_for_device('a_device_token')
|
217
222
|
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
218
223
|
end
|
219
|
-
|
224
|
+
|
220
225
|
it "uses app key and secret to sign the request" do
|
221
226
|
subject.tags_for_device('valid_device_token')
|
222
227
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
223
228
|
end
|
224
|
-
|
229
|
+
|
225
230
|
it "returns valid tags for a device" do
|
226
231
|
response = subject.tags_for_device('valid_device_token')
|
227
232
|
response.first.should include("tags")
|
@@ -229,25 +234,25 @@ shared_examples_for "an Urbanairship client" do
|
|
229
234
|
response.first["tags"].should include("tag2")
|
230
235
|
response.code.should == "200"
|
231
236
|
end
|
232
|
-
|
237
|
+
|
233
238
|
it "returns invalid response for device token that is not found or registered" do
|
234
239
|
response = subject.tags_for_device('invalid_device_token')
|
235
240
|
response.code.should == "404"
|
236
241
|
end
|
237
|
-
|
242
|
+
|
238
243
|
it "success? is false when the call doesn't return 200" do
|
239
244
|
subject.application_key = "my_app_key2"
|
240
245
|
subject.master_secret = "my_master_secret2"
|
241
246
|
subject.tags_for_device('a_device_token').success?.should == false
|
242
247
|
end
|
243
248
|
end
|
244
|
-
|
249
|
+
|
245
250
|
describe "::tag_device" do
|
246
251
|
before(:each) do
|
247
252
|
subject.application_key = "my_app_key"
|
248
253
|
subject.master_secret = "my_master_secret"
|
249
254
|
end
|
250
|
-
|
255
|
+
|
251
256
|
it "raises an error if call is made without an app key and master secret configured" do
|
252
257
|
subject.application_key = nil
|
253
258
|
subject.master_secret = nil
|
@@ -256,25 +261,25 @@ shared_examples_for "an Urbanairship client" do
|
|
256
261
|
subject.tag_device({:device_token => 'a_device_token', :tag => 'a_tag'})
|
257
262
|
}.should raise_error(RuntimeError, "Must configure application_key, master_secret before making this request.")
|
258
263
|
end
|
259
|
-
|
264
|
+
|
260
265
|
it "uses app key and secret to sign the request" do
|
261
266
|
subject.tag_device({:device_token => 'valid_device_token', :tag => 'new_tag'})
|
262
267
|
FakeWeb.last_request['authorization'].should == "Basic #{Base64::encode64('my_app_key:my_master_secret').chomp}"
|
263
268
|
end
|
264
|
-
|
269
|
+
|
265
270
|
it "adds a valid device token to tag" do
|
266
271
|
response = subject.tag_device({:device_token => 'valid_device_token', :tag => 'new_tag'})
|
267
272
|
response.code.should == "201"
|
268
273
|
response.success?.should == true
|
269
274
|
end
|
270
|
-
|
275
|
+
|
271
276
|
it "adds a valid device token to an existing tag" do
|
272
277
|
response = subject.tag_device({:device_token => 'valid_device_token', :tag => 'existing_tag'})
|
273
278
|
response.code.should == "200"
|
274
279
|
response.success?.should == true
|
275
280
|
end
|
276
281
|
end
|
277
|
-
|
282
|
+
|
278
283
|
describe "::untag_device" do
|
279
284
|
before(:each) do
|
280
285
|
subject.application_key = "my_app_key"
|
@@ -307,7 +312,6 @@ shared_examples_for "an Urbanairship client" do
|
|
307
312
|
response.success?.should == false
|
308
313
|
end
|
309
314
|
end
|
310
|
-
|
311
315
|
|
312
316
|
describe "::register_device" do
|
313
317
|
before(:each) do
|
@@ -522,7 +526,7 @@ shared_examples_for "an Urbanairship client" do
|
|
522
526
|
subject.push.success?.should == false
|
523
527
|
end
|
524
528
|
end
|
525
|
-
|
529
|
+
|
526
530
|
describe "::push_to_segment" do
|
527
531
|
before(:each) do
|
528
532
|
@valid_params = {:segments => ['segment-id'], :aps => {:alert => 'foo'}}
|
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.
|
4
|
+
version: 2.2.2
|
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-
|
12
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|