zeppelin 0.6.0 → 0.7.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/Changelog.md +11 -0
- data/Guardfile +1 -1
- data/README.md +2 -6
- data/Rakefile +1 -2
- data/lib/zeppelin.rb +52 -5
- data/lib/zeppelin/middleware/json_parser.rb +1 -1
- data/lib/zeppelin/version.rb +1 -1
- data/spec/zeppelin_spec.rb +201 -111
- metadata +11 -11
data/Changelog.md
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -24,11 +24,6 @@ With bundler:
|
|
24
24
|
|
25
25
|
Check out the docs for more ways of querying the API.
|
26
26
|
|
27
|
-
## TODO ##
|
28
|
-
|
29
|
-
* Add support for the statistics API.
|
30
|
-
* Add support for the device token list API.
|
31
|
-
|
32
27
|
## Note on Patches/Pull Requests ##
|
33
28
|
|
34
29
|
* Fork the project.
|
@@ -41,7 +36,8 @@ Check out the docs for more ways of querying the API.
|
|
41
36
|
|
42
37
|
* [GitHub Repository](https://github.com/CapnKernul/zeppelin)
|
43
38
|
* [Documentation](http://rubydoc.info/github/CapnKernul/zeppelin)
|
39
|
+
* [Issues](https://github.com/CapnKernul/zeppelin/issues)
|
44
40
|
|
45
41
|
## License ##
|
46
42
|
|
47
|
-
Zeppelin is licensed under the MIT License. See `LICENSE` for details.
|
43
|
+
Zeppelin is licensed under the MIT License. See `LICENSE` for details.
|
data/Rakefile
CHANGED
data/lib/zeppelin.rb
CHANGED
@@ -67,6 +67,21 @@ class Zeppelin
|
|
67
67
|
delete_request(uri)
|
68
68
|
end
|
69
69
|
|
70
|
+
# Retrieve a page of device tokens
|
71
|
+
#
|
72
|
+
# @param [Integer] page (nil) Page of device tokens to retrieve
|
73
|
+
#
|
74
|
+
# @return [Hash] result set. See documentation for details
|
75
|
+
#
|
76
|
+
# @Note that the next page number is included in the result set instead of the
|
77
|
+
# raw URI to request for the next page
|
78
|
+
#
|
79
|
+
# @raise [Zeppelin::ClientError] invalid request
|
80
|
+
def device_tokens(page=nil)
|
81
|
+
uri = device_token_uri(nil, :page => page)
|
82
|
+
get_paged_request(uri)
|
83
|
+
end
|
84
|
+
|
70
85
|
# Registers an APID.
|
71
86
|
#
|
72
87
|
# @param [String] apid
|
@@ -105,6 +120,21 @@ class Zeppelin
|
|
105
120
|
delete_request(uri)
|
106
121
|
end
|
107
122
|
|
123
|
+
# Retrieve a page of APIDs
|
124
|
+
#
|
125
|
+
# @param [Integer] page (nil) Page of APIDs to retrieve
|
126
|
+
#
|
127
|
+
# @return [Hash] result set. See documentation for details
|
128
|
+
#
|
129
|
+
# @Note that the next page number is included in the result set instead of the
|
130
|
+
# raw URI to request for the next page
|
131
|
+
#
|
132
|
+
# @raise [Zeppelin::ClientError] invalid request
|
133
|
+
def apids(page=nil)
|
134
|
+
uri = apid_uri(nil, :page => page)
|
135
|
+
get_paged_request(uri)
|
136
|
+
end
|
137
|
+
|
108
138
|
# Pushes a message.
|
109
139
|
#
|
110
140
|
# @param [Hash] payload the payload of the message
|
@@ -252,7 +282,7 @@ class Zeppelin
|
|
252
282
|
|
253
283
|
def put_request(uri, payload={})
|
254
284
|
if !(payload.nil? || payload.empty?)
|
255
|
-
response =connection.put(uri, payload, JSON_HEADERS)
|
285
|
+
response = connection.put(uri, payload, JSON_HEADERS)
|
256
286
|
else
|
257
287
|
response = connection.put(uri)
|
258
288
|
end
|
@@ -269,16 +299,33 @@ class Zeppelin
|
|
269
299
|
response.body if response.success?
|
270
300
|
end
|
271
301
|
|
302
|
+
def get_paged_request(uri)
|
303
|
+
results = get_request(uri)
|
304
|
+
md = results['next_page'] && results['next_page'].match(/(start|page)=(\d+)/)
|
305
|
+
|
306
|
+
results['next_page'] = md[2].to_i unless md.nil?
|
307
|
+
|
308
|
+
results
|
309
|
+
end
|
310
|
+
|
272
311
|
def post_request(uri, payload)
|
273
312
|
connection.post(uri, payload, JSON_HEADERS).success?
|
274
313
|
end
|
275
314
|
|
276
|
-
def
|
277
|
-
"
|
315
|
+
def query_string(query)
|
316
|
+
'?' + query.map { |k, v| "#{k}=#{v}" }.join('&')
|
317
|
+
end
|
318
|
+
|
319
|
+
def device_token_uri(device_token, query={})
|
320
|
+
uri = "/api/device_tokens/#{device_token}"
|
321
|
+
uri << query_string(query) unless query.empty?
|
322
|
+
uri
|
278
323
|
end
|
279
324
|
|
280
|
-
def apid_uri(apid)
|
281
|
-
"/api/apids/#{apid}"
|
325
|
+
def apid_uri(apid, query={})
|
326
|
+
uri = "/api/apids/#{apid}"
|
327
|
+
uri << query_string(query) unless query.empty?
|
328
|
+
uri
|
282
329
|
end
|
283
330
|
|
284
331
|
def feedback_uri(since)
|
data/lib/zeppelin/version.rb
CHANGED
data/spec/zeppelin_spec.rb
CHANGED
@@ -38,13 +38,13 @@ describe Zeppelin do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
describe '#register_device_token' do
|
41
|
+
let(:uri) { "/api/device_tokens/#{device_token}" }
|
42
|
+
|
41
43
|
let(:payload) { { :alias => 'CapnKernul' } }
|
42
44
|
|
43
45
|
it 'registers a device with the service' do
|
44
46
|
stub_requests do |stub|
|
45
|
-
stub.put(
|
46
|
-
[201, {}, '']
|
47
|
-
end
|
47
|
+
stub.put(uri) { [201, {}, ''] }
|
48
48
|
end
|
49
49
|
|
50
50
|
subject.register_device_token(device_token).should be_true
|
@@ -52,19 +52,15 @@ describe Zeppelin do
|
|
52
52
|
|
53
53
|
it 'accepts a payload' do
|
54
54
|
stub_requests do |stub|
|
55
|
-
stub.put(
|
56
|
-
[200, {}, '']
|
57
|
-
end
|
55
|
+
stub.put(uri) { [201, {}, ''] }
|
58
56
|
end
|
59
57
|
|
60
|
-
subject.register_device_token(device_token, payload)
|
58
|
+
subject.register_device_token(device_token, payload)
|
61
59
|
end
|
62
60
|
|
63
61
|
it 'responds with false when an error occurs' do
|
64
62
|
stub_requests do |stub|
|
65
|
-
stub.put(
|
66
|
-
[500, {}, '']
|
67
|
-
end
|
63
|
+
stub.put(uri) { [500, {}, ''] }
|
68
64
|
end
|
69
65
|
|
70
66
|
expect {
|
@@ -74,23 +70,21 @@ describe Zeppelin do
|
|
74
70
|
end
|
75
71
|
|
76
72
|
describe '#device_token' do
|
73
|
+
let(:uri) { "/api/device_tokens/#{device_token}" }
|
74
|
+
|
77
75
|
let(:response_body) { { 'foo' => 'bar' } }
|
78
76
|
|
79
77
|
it 'gets information about a device' do
|
80
78
|
stub_requests do |stub|
|
81
|
-
stub.get(
|
82
|
-
[200, { 'Content-Type' => 'application/json' }, MultiJson.encode(response_body)]
|
83
|
-
end
|
79
|
+
stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(response_body)] }
|
84
80
|
end
|
85
81
|
|
86
82
|
subject.device_token(device_token).should eq(response_body)
|
87
83
|
end
|
88
84
|
|
89
|
-
it '
|
85
|
+
it 'raises an error when the request fails' do
|
90
86
|
stub_requests do |stub|
|
91
|
-
stub.get(
|
92
|
-
[404, {}, '']
|
93
|
-
end
|
87
|
+
stub.get(uri) { [404, {}, ''] }
|
94
88
|
end
|
95
89
|
|
96
90
|
expect {
|
@@ -100,21 +94,19 @@ describe Zeppelin do
|
|
100
94
|
end
|
101
95
|
|
102
96
|
describe '#delete_device_token' do
|
97
|
+
let(:uri) { "/api/device_tokens/#{device_token}" }
|
98
|
+
|
103
99
|
it 'is true when successful' do
|
104
100
|
stub_requests do |stub|
|
105
|
-
stub.delete(
|
106
|
-
[204, {}, '']
|
107
|
-
end
|
101
|
+
stub.delete(uri) { [204, {}, ''] }
|
108
102
|
end
|
109
103
|
|
110
104
|
subject.delete_device_token(device_token).should be_true
|
111
105
|
end
|
112
106
|
|
113
|
-
it '
|
107
|
+
it 'raises an error when the request fails' do
|
114
108
|
stub_requests do |stub|
|
115
|
-
stub.delete(
|
116
|
-
[404, {}, '']
|
117
|
-
end
|
109
|
+
stub.delete(uri) { [404, {}, ''] }
|
118
110
|
end
|
119
111
|
|
120
112
|
expect {
|
@@ -123,14 +115,79 @@ describe Zeppelin do
|
|
123
115
|
end
|
124
116
|
end
|
125
117
|
|
118
|
+
describe '#device_tokens' do
|
119
|
+
let(:results_without_next_page) {
|
120
|
+
{
|
121
|
+
'device_tokens_count' => 1,
|
122
|
+
'device_tokens' => [
|
123
|
+
{
|
124
|
+
'device_token' => 'example device token',
|
125
|
+
'active' => true,
|
126
|
+
'alias' => nil,
|
127
|
+
'last_registration' => Time.mktime(2009, 6, 26, 19, 4, 43).to_s
|
128
|
+
}
|
129
|
+
],
|
130
|
+
'current_page' => 1,
|
131
|
+
'num_pages' => 1,
|
132
|
+
'active_device_tokens' => 1
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
let(:results_with_next_page) {
|
137
|
+
results_without_next_page.merge('next_page' => 'https://go.urbanairship.com/api/device_tokens/?page=2&limit=5000')
|
138
|
+
}
|
139
|
+
|
140
|
+
it 'requests a page of device tokens' do
|
141
|
+
stub_requests do |stub|
|
142
|
+
stub.get('/api/device_tokens/?page=') { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(results_without_next_page)] }
|
143
|
+
end
|
144
|
+
|
145
|
+
subject.device_tokens.should eq(results_without_next_page)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'includes the page number of the next page' do
|
149
|
+
stub_requests do |stub|
|
150
|
+
stub.get('/api/device_tokens/?page=') { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(results_with_next_page)] }
|
151
|
+
end
|
152
|
+
|
153
|
+
subject.device_tokens['next_page'].should eq(2)
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'does not include the page number if there are no additional pages' do
|
157
|
+
stub_requests do |stub|
|
158
|
+
stub.get('/api/device_tokens/?page=') { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(results_without_next_page)] }
|
159
|
+
end
|
160
|
+
|
161
|
+
subject.device_tokens.should_not have_key('next_page')
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'requests a specified page of device_tokens' do
|
165
|
+
stub_requests do |stub|
|
166
|
+
stub.get('/api/device_tokens/?page=4') { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(results_without_next_page)] }
|
167
|
+
end
|
168
|
+
|
169
|
+
subject.device_tokens(4)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'raises an error when the request fails' do
|
173
|
+
stub_requests do |stub|
|
174
|
+
stub.get('/api/device_tokens/?page=') { [500, {}, ''] }
|
175
|
+
end
|
176
|
+
|
177
|
+
expect {
|
178
|
+
subject.device_tokens
|
179
|
+
}.to raise_error(Zeppelin::ClientError)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
126
183
|
describe '#register_apid' do
|
184
|
+
let(:uri) { "/api/apids/#{device_token}" }
|
185
|
+
|
127
186
|
let(:payload) { { :alias => 'CapnKernul' } }
|
128
187
|
|
129
188
|
it 'registers a device with the service' do
|
130
189
|
stub_requests do |stub|
|
131
|
-
stub.put(
|
132
|
-
[201, {}, '']
|
133
|
-
end
|
190
|
+
stub.put(uri) { [201, {}, ''] }
|
134
191
|
end
|
135
192
|
|
136
193
|
subject.register_apid(device_token).should be_true
|
@@ -138,19 +195,15 @@ describe Zeppelin do
|
|
138
195
|
|
139
196
|
it 'accepts a payload' do
|
140
197
|
stub_requests do |stub|
|
141
|
-
stub.put(
|
142
|
-
[200, {}, '']
|
143
|
-
end
|
198
|
+
stub.put(uri, MultiJson.encode(payload)) { [200, {}, ''] }
|
144
199
|
end
|
145
200
|
|
146
201
|
subject.register_apid(device_token, payload).should be_true
|
147
202
|
end
|
148
203
|
|
149
|
-
it '
|
204
|
+
it 'raises an error when the request fails' do
|
150
205
|
stub_requests do |stub|
|
151
|
-
stub.put(
|
152
|
-
[500, {}, '']
|
153
|
-
end
|
206
|
+
stub.put(uri) { [500, {}, ''] }
|
154
207
|
end
|
155
208
|
|
156
209
|
expect {
|
@@ -160,23 +213,21 @@ describe Zeppelin do
|
|
160
213
|
end
|
161
214
|
|
162
215
|
describe '#apid' do
|
216
|
+
let(:uri) { "/api/apids/#{device_token}" }
|
217
|
+
|
163
218
|
let(:response_body) { { 'foo' => 'bar' } }
|
164
219
|
|
165
220
|
it 'responds with information about a device when request is successful' do
|
166
221
|
stub_requests do |stub|
|
167
|
-
stub.get(
|
168
|
-
[200, { 'Content-Type' => 'application/json' }, MultiJson.encode(response_body)]
|
169
|
-
end
|
222
|
+
stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(response_body)] }
|
170
223
|
end
|
171
224
|
|
172
225
|
subject.apid(device_token).should eq(response_body)
|
173
226
|
end
|
174
227
|
|
175
|
-
it '
|
228
|
+
it 'raises an error when the request fails' do
|
176
229
|
stub_requests do |stub|
|
177
|
-
stub.get("/api/apids/#{device_token}")
|
178
|
-
[404, {}, '']
|
179
|
-
end
|
230
|
+
stub.get("/api/apids/#{device_token}") { [404, {}, ''] }
|
180
231
|
end
|
181
232
|
|
182
233
|
expect {
|
@@ -186,21 +237,19 @@ describe Zeppelin do
|
|
186
237
|
end
|
187
238
|
|
188
239
|
describe '#delete_apid' do
|
240
|
+
let(:uri) { "/api/apids/#{device_token}" }
|
241
|
+
|
189
242
|
it 'responds with true when request successful' do
|
190
243
|
stub_requests do |stub|
|
191
|
-
stub.delete(
|
192
|
-
[204, {}, '']
|
193
|
-
end
|
244
|
+
stub.delete(uri) { [204, {}, ''] }
|
194
245
|
end
|
195
246
|
|
196
247
|
subject.delete_apid(device_token).should be_true
|
197
248
|
end
|
198
249
|
|
199
|
-
it '
|
250
|
+
it 'raises an error when the request fails' do
|
200
251
|
stub_requests do |stub|
|
201
|
-
stub.delete(
|
202
|
-
[404, {}, '']
|
203
|
-
end
|
252
|
+
stub.delete(uri) { [404, {}, ''] }
|
204
253
|
end
|
205
254
|
|
206
255
|
expect {
|
@@ -209,24 +258,83 @@ describe Zeppelin do
|
|
209
258
|
end
|
210
259
|
end
|
211
260
|
|
261
|
+
describe '#apids' do
|
262
|
+
let(:results_without_next_page) {
|
263
|
+
{
|
264
|
+
'apids' => [
|
265
|
+
{
|
266
|
+
'apid' => 'example apid',
|
267
|
+
'active' => true,
|
268
|
+
'alias' => '',
|
269
|
+
'tags' => []
|
270
|
+
}
|
271
|
+
]
|
272
|
+
}
|
273
|
+
}
|
274
|
+
|
275
|
+
let(:results_with_next_page) {
|
276
|
+
results_without_next_page.merge('next_page' => 'https://go.urbanairship.com/api/apids/?start=2&limit=5000')
|
277
|
+
}
|
278
|
+
|
279
|
+
it 'requests a page of APIDs' do
|
280
|
+
stub_requests do |stub|
|
281
|
+
stub.get('/api/apids/?page=') { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(results_without_next_page)] }
|
282
|
+
end
|
283
|
+
|
284
|
+
subject.apids.should eq(results_without_next_page)
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'includes the page number of the next page' do
|
288
|
+
stub_requests do |stub|
|
289
|
+
stub.get('/api/apids/?page=') { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(results_with_next_page)] }
|
290
|
+
end
|
291
|
+
|
292
|
+
subject.apids['next_page'].should eq(2)
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'does not include the page number if there are no additional pages' do
|
296
|
+
stub_requests do |stub|
|
297
|
+
stub.get('/api/apids/?page=') { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(results_without_next_page)] }
|
298
|
+
end
|
299
|
+
|
300
|
+
subject.apids.should_not have_key('next_page')
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'requests a specified page of APIDs' do
|
304
|
+
stub_requests do |stub|
|
305
|
+
stub.get('/api/apids/?page=4') { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(results_without_next_page)] }
|
306
|
+
end
|
307
|
+
|
308
|
+
subject.apids(4)
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'raises an error when the request fails' do
|
312
|
+
stub_requests do |stub|
|
313
|
+
stub.get('/api/apids/?page=') { [500, {}, ''] }
|
314
|
+
end
|
315
|
+
|
316
|
+
expect {
|
317
|
+
subject.apids
|
318
|
+
}.to raise_error(Zeppelin::ClientError)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
212
322
|
describe '#push' do
|
323
|
+
let(:uri) { '/api/push/' }
|
324
|
+
|
213
325
|
let(:payload) { { :device_tokens => [device_token], :aps => { :alert => 'Hello from Urban Airship!' } } }
|
214
326
|
|
215
327
|
it 'is true when the request is successful' do
|
216
328
|
stub_requests do |stub|
|
217
|
-
stub.post(
|
218
|
-
[200, {}, '']
|
219
|
-
end
|
329
|
+
stub.post(uri, MultiJson.encode(payload)) { [200, {}, ''] }
|
220
330
|
end
|
221
331
|
|
222
332
|
subject.push(payload).should be_true
|
223
333
|
end
|
224
334
|
|
225
|
-
it '
|
335
|
+
it 'raises an error when the request fails' do
|
226
336
|
stub_requests do |stub|
|
227
|
-
stub.post(
|
228
|
-
[400, {}, '']
|
229
|
-
end
|
337
|
+
stub.post(uri, '{}') { [400, {}, ''] }
|
230
338
|
end
|
231
339
|
|
232
340
|
expect {
|
@@ -252,21 +360,19 @@ describe Zeppelin do
|
|
252
360
|
|
253
361
|
let(:payload) { [message1, message2] }
|
254
362
|
|
363
|
+
let(:uri) { '/api/push/batch/' }
|
364
|
+
|
255
365
|
it 'is true when the request was successful' do
|
256
366
|
stub_requests do |stub|
|
257
|
-
stub.post(
|
258
|
-
[200, {}, '']
|
259
|
-
end
|
367
|
+
stub.post(uri, MultiJson.encode(payload)) { [200, {}, ''] }
|
260
368
|
end
|
261
369
|
|
262
370
|
subject.batch_push(message1, message2).should be_true
|
263
371
|
end
|
264
372
|
|
265
|
-
it '
|
373
|
+
it 'raises an error when the request fails' do
|
266
374
|
stub_requests do |stub|
|
267
|
-
stub.post('/api/push/batch/', '[{},{}]')
|
268
|
-
[400, {}, '']
|
269
|
-
end
|
375
|
+
stub.post('/api/push/batch/', '[{},{}]') { [400, {}, ''] }
|
270
376
|
end
|
271
377
|
|
272
378
|
expect {
|
@@ -278,21 +384,19 @@ describe Zeppelin do
|
|
278
384
|
describe '#broadcast' do
|
279
385
|
let(:payload) { { :aps => { :alert => 'Hello from Urban Airship!' } } }
|
280
386
|
|
387
|
+
let(:uri) { '/api/push/broadcast/' }
|
388
|
+
|
281
389
|
it 'is true when the request is successful' do
|
282
390
|
stub_requests do |stub|
|
283
|
-
stub.post(
|
284
|
-
[200, {}, '']
|
285
|
-
end
|
391
|
+
stub.post(uri, MultiJson.encode(payload)) { [200, {}, ''] }
|
286
392
|
end
|
287
393
|
|
288
394
|
subject.broadcast(payload).should be_true
|
289
395
|
end
|
290
396
|
|
291
|
-
it '
|
397
|
+
it 'raises an error when the request fails' do
|
292
398
|
stub_requests do |stub|
|
293
|
-
stub.post(
|
294
|
-
[400, {}, '']
|
295
|
-
end
|
399
|
+
stub.post(uri, '{}') { [400, {}, ''] }
|
296
400
|
end
|
297
401
|
|
298
402
|
expect {
|
@@ -306,21 +410,19 @@ describe Zeppelin do
|
|
306
410
|
|
307
411
|
let(:since) { Time.at(0) }
|
308
412
|
|
413
|
+
let(:uri) { '/api/device_tokens/feedback/?since=1970-01-01T00%3A00%3A00Z' }
|
414
|
+
|
309
415
|
it 'is the response body for a successful request' do
|
310
416
|
stub_requests do |stub|
|
311
|
-
stub.get('
|
312
|
-
[200, { 'Content-Type' => 'application/json' }, MultiJson.encode(response_body)]
|
313
|
-
end
|
417
|
+
stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(response_body)] }
|
314
418
|
end
|
315
419
|
|
316
420
|
subject.feedback(since)
|
317
421
|
end
|
318
422
|
|
319
|
-
it '
|
423
|
+
it 'raises an error when the request fails' do
|
320
424
|
stub_requests do |stub|
|
321
|
-
stub.get('
|
322
|
-
[400, {}, '']
|
323
|
-
end
|
425
|
+
stub.get(uri) { [400, {}, ''] }
|
324
426
|
end
|
325
427
|
|
326
428
|
expect {
|
@@ -336,9 +438,7 @@ describe Zeppelin do
|
|
336
438
|
|
337
439
|
it 'requets to modify device tokens on a tag' do
|
338
440
|
stub_requests do |stub|
|
339
|
-
stub.post("/api/tags/#{tag_name}")
|
340
|
-
[200, {}, 'OK']
|
341
|
-
end
|
441
|
+
stub.post("/api/tags/#{tag_name}") { [200, {}, 'OK'] }
|
342
442
|
end
|
343
443
|
|
344
444
|
subject.modify_device_tokens_on_tag(tag_name, { 'device_tokens' => { 'add' => [device_token] } }).should be
|
@@ -350,9 +450,7 @@ describe Zeppelin do
|
|
350
450
|
|
351
451
|
it 'is true when the request is successful' do
|
352
452
|
stub_requests do |stub|
|
353
|
-
stub.put("/api/tags/#{tag_name}")
|
354
|
-
[201, {}, '']
|
355
|
-
end
|
453
|
+
stub.put("/api/tags/#{tag_name}") { [201, {}, ''] }
|
356
454
|
end
|
357
455
|
|
358
456
|
subject.add_tag(tag_name).should be_true
|
@@ -364,9 +462,7 @@ describe Zeppelin do
|
|
364
462
|
|
365
463
|
it 'is true when the request is successful' do
|
366
464
|
stub_requests do |stub|
|
367
|
-
stub.delete("/api/tags/#{tag_name}")
|
368
|
-
[204, {}, '']
|
369
|
-
end
|
465
|
+
stub.delete("/api/tags/#{tag_name}") { [204, {}, ''] }
|
370
466
|
end
|
371
467
|
|
372
468
|
subject.remove_tag(tag_name).should be_true
|
@@ -374,9 +470,7 @@ describe Zeppelin do
|
|
374
470
|
|
375
471
|
it 'is false when the request fails' do
|
376
472
|
stub_requests do |stub|
|
377
|
-
stub.delete("/api/tags/#{tag_name}")
|
378
|
-
[404, {}, '']
|
379
|
-
end
|
473
|
+
stub.delete("/api/tags/#{tag_name}") { [404, {}, ''] }
|
380
474
|
end
|
381
475
|
|
382
476
|
expect {
|
@@ -388,21 +482,19 @@ describe Zeppelin do
|
|
388
482
|
describe '#device_tags' do
|
389
483
|
let(:response_body) { { 'tags' => ['tag1', 'some_tag'] } }
|
390
484
|
|
485
|
+
let(:uri) { "/api/device_tokens/#{device_token}/tags/" }
|
486
|
+
|
391
487
|
it 'is the collection of tags on a device when request is successful' do
|
392
488
|
stub_requests do |stub|
|
393
|
-
stub.get(
|
394
|
-
[200, { 'Content-Type' => 'application/json' }, MultiJson.encode(response_body)]
|
395
|
-
end
|
489
|
+
stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, MultiJson.encode(response_body)] }
|
396
490
|
end
|
397
491
|
|
398
492
|
subject.device_tags(device_token).should eq(response_body)
|
399
493
|
end
|
400
494
|
|
401
|
-
it '
|
495
|
+
it 'raises an error when the request fails' do
|
402
496
|
stub_requests do |stub|
|
403
|
-
stub.get(
|
404
|
-
[404, {}, 'Not Found']
|
405
|
-
end
|
497
|
+
stub.get(uri) { [404, {}, 'Not Found'] }
|
406
498
|
end
|
407
499
|
|
408
500
|
expect {
|
@@ -414,21 +506,19 @@ describe Zeppelin do
|
|
414
506
|
describe '#add_tag_to_device' do
|
415
507
|
let(:tag_name) { 'radio.head' }
|
416
508
|
|
509
|
+
let(:uri) { "/api/device_tokens/#{device_token}/tags/#{tag_name}" }
|
510
|
+
|
417
511
|
it 'is true when the request is successful' do
|
418
512
|
stub_requests do |stub|
|
419
|
-
stub.put(
|
420
|
-
[201, {}, 'Created']
|
421
|
-
end
|
513
|
+
stub.put(uri) { [201, {}, 'Created'] }
|
422
514
|
end
|
423
515
|
|
424
516
|
subject.add_tag_to_device(device_token, tag_name).should be_true
|
425
517
|
end
|
426
518
|
|
427
|
-
it '
|
519
|
+
it 'raises an error when the request fails' do
|
428
520
|
stub_requests do |stub|
|
429
|
-
stub.put(
|
430
|
-
[404, {}, '']
|
431
|
-
end
|
521
|
+
stub.put(uri) { [404, {}, ''] }
|
432
522
|
end
|
433
523
|
|
434
524
|
expect {
|
@@ -440,21 +530,19 @@ describe Zeppelin do
|
|
440
530
|
describe '#remove_tag_from_device' do
|
441
531
|
let(:tag_name) { 'martin.fowler' }
|
442
532
|
|
533
|
+
let(:uri) { "/api/device_tokens/#{device_token}/tags/#{tag_name}" }
|
534
|
+
|
443
535
|
it 'is true when the request is successful' do
|
444
536
|
stub_requests do |stub|
|
445
|
-
stub.delete(
|
446
|
-
[204, {}, 'No Content']
|
447
|
-
end
|
537
|
+
stub.delete(uri) { [204, {}, 'No Content'] }
|
448
538
|
end
|
449
539
|
|
450
540
|
subject.remove_tag_from_device(device_token, tag_name).should be_true
|
451
541
|
end
|
452
542
|
|
453
|
-
it '
|
543
|
+
it 'raises an error when the request fails' do
|
454
544
|
stub_requests do |stub|
|
455
|
-
stub.delete(
|
456
|
-
[404, {}, '']
|
457
|
-
end
|
545
|
+
stub.delete(uri) { [404, {}, ''] }
|
458
546
|
end
|
459
547
|
|
460
548
|
expect {
|
@@ -463,8 +551,10 @@ describe Zeppelin do
|
|
463
551
|
end
|
464
552
|
end
|
465
553
|
|
466
|
-
def stub_requests
|
554
|
+
def stub_requests
|
467
555
|
subject.connection.builder.handlers.delete(Faraday::Adapter::NetHttp)
|
468
|
-
subject.connection.adapter
|
556
|
+
subject.connection.adapter :test do |stubs|
|
557
|
+
yield(stubs)
|
558
|
+
end
|
469
559
|
end
|
470
560
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zeppelin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-02-
|
13
|
+
date: 2012-02-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
17
|
-
requirement: &
|
17
|
+
requirement: &70196652109980 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70196652109980
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: multi_json
|
28
|
-
requirement: &
|
28
|
+
requirement: &70196652109320 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '1.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70196652109320
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70196652108780 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70196652108780
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rake
|
50
|
-
requirement: &
|
50
|
+
requirement: &70196652108000 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70196652108000
|
59
59
|
description: Ruby client for the Urban Airship Push Notification API
|
60
60
|
email:
|
61
61
|
- alex@kernul.com
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project: zeppelin
|
106
|
-
rubygems_version: 1.8.
|
106
|
+
rubygems_version: 1.8.15
|
107
107
|
signing_key:
|
108
108
|
specification_version: 3
|
109
109
|
summary: Urban Airship library for Ruby
|