zeppelin 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +5 -1
- data/lib/zeppelin.rb +3 -4
- data/lib/zeppelin/middleware.rb +2 -1
- data/lib/zeppelin/version.rb +1 -1
- data/spec/zeppelin_spec.rb +19 -19
- data/zeppelin.gemspec +2 -1
- metadata +51 -17
- data/lib/zeppelin/middleware/json_parser.rb +0 -37
- data/spec/middleware/json_parser_spec.rb +0 -34
data/Changelog.md
CHANGED
data/lib/zeppelin.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
2
3
|
require 'time'
|
3
4
|
|
4
5
|
# A very tiny Urban Airship Push Notification API client.
|
@@ -302,13 +303,11 @@ class Zeppelin
|
|
302
303
|
private
|
303
304
|
|
304
305
|
def initialize_connection
|
305
|
-
Faraday::Request::JSON.adapter = MultiJson
|
306
|
-
|
307
306
|
conn = Faraday::Connection.new(BASE_URI, @options) do |builder|
|
308
307
|
builder.request :json
|
309
308
|
|
310
|
-
builder.
|
311
|
-
builder.
|
309
|
+
builder.response :json, :content_type => /\bjson$/
|
310
|
+
builder.response :zeppelin_raise_error
|
312
311
|
|
313
312
|
builder.adapter :net_http
|
314
313
|
end
|
data/lib/zeppelin/middleware.rb
CHANGED
data/lib/zeppelin/version.rb
CHANGED
data/spec/zeppelin_spec.rb
CHANGED
@@ -28,9 +28,9 @@ describe Zeppelin do
|
|
28
28
|
|
29
29
|
it { subject.connection.builder.handlers.should include(Faraday::Adapter::NetHttp) }
|
30
30
|
|
31
|
-
it { subject.connection.builder.handlers.should include(
|
31
|
+
it { subject.connection.builder.handlers.should include(FaradayMiddleware::EncodeJson) }
|
32
32
|
|
33
|
-
it { subject.connection.builder.handlers.should include(
|
33
|
+
it { subject.connection.builder.handlers.should include(FaradayMiddleware::ParseJson) }
|
34
34
|
|
35
35
|
it { subject.connection.builder.handlers.should include(Zeppelin::Middleware::ResponseRaiseError) }
|
36
36
|
|
@@ -76,7 +76,7 @@ describe Zeppelin do
|
|
76
76
|
|
77
77
|
it 'gets information about a device' do
|
78
78
|
stub_requests do |stub|
|
79
|
-
stub.get(uri) { [200, { 'Content-Type' => 'application/json' },
|
79
|
+
stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, JSON.dump(response_body)] }
|
80
80
|
end
|
81
81
|
|
82
82
|
subject.device_token(device_token).should eq(response_body)
|
@@ -139,7 +139,7 @@ describe Zeppelin do
|
|
139
139
|
|
140
140
|
it 'requests a page of device tokens' do
|
141
141
|
stub_requests do |stub|
|
142
|
-
stub.get('/api/device_tokens/?page=') { [200, { 'Content-Type' => 'application/json' },
|
142
|
+
stub.get('/api/device_tokens/?page=') { [200, { 'Content-Type' => 'application/json' }, JSON.dump(results_without_next_page)] }
|
143
143
|
end
|
144
144
|
|
145
145
|
subject.device_tokens.should eq(results_without_next_page)
|
@@ -147,7 +147,7 @@ describe Zeppelin do
|
|
147
147
|
|
148
148
|
it 'includes the page number of the next page' do
|
149
149
|
stub_requests do |stub|
|
150
|
-
stub.get('/api/device_tokens/?page=') { [200, { 'Content-Type' => 'application/json' },
|
150
|
+
stub.get('/api/device_tokens/?page=') { [200, { 'Content-Type' => 'application/json' }, JSON.dump(results_with_next_page)] }
|
151
151
|
end
|
152
152
|
|
153
153
|
subject.device_tokens['next_page'].should eq(2)
|
@@ -155,7 +155,7 @@ describe Zeppelin do
|
|
155
155
|
|
156
156
|
it 'does not include the page number if there are no additional pages' do
|
157
157
|
stub_requests do |stub|
|
158
|
-
stub.get('/api/device_tokens/?page=') { [200, { 'Content-Type' => 'application/json' },
|
158
|
+
stub.get('/api/device_tokens/?page=') { [200, { 'Content-Type' => 'application/json' }, JSON.dump(results_without_next_page)] }
|
159
159
|
end
|
160
160
|
|
161
161
|
subject.device_tokens.should_not have_key('next_page')
|
@@ -163,7 +163,7 @@ describe Zeppelin do
|
|
163
163
|
|
164
164
|
it 'requests a specified page of device_tokens' do
|
165
165
|
stub_requests do |stub|
|
166
|
-
stub.get('/api/device_tokens/?page=4') { [200, { 'Content-Type' => 'application/json' },
|
166
|
+
stub.get('/api/device_tokens/?page=4') { [200, { 'Content-Type' => 'application/json' }, JSON.dump(results_without_next_page)] }
|
167
167
|
end
|
168
168
|
|
169
169
|
subject.device_tokens(4)
|
@@ -195,7 +195,7 @@ describe Zeppelin do
|
|
195
195
|
|
196
196
|
it 'accepts a payload' do
|
197
197
|
stub_requests do |stub|
|
198
|
-
stub.put(uri,
|
198
|
+
stub.put(uri, JSON.dump(payload)) { [200, {}, ''] }
|
199
199
|
end
|
200
200
|
|
201
201
|
subject.register_apid(device_token, payload).should be_true
|
@@ -219,7 +219,7 @@ describe Zeppelin do
|
|
219
219
|
|
220
220
|
it 'responds with information about a device when request is successful' do
|
221
221
|
stub_requests do |stub|
|
222
|
-
stub.get(uri) { [200, { 'Content-Type' => 'application/json' },
|
222
|
+
stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, JSON.dump(response_body)] }
|
223
223
|
end
|
224
224
|
|
225
225
|
subject.apid(device_token).should eq(response_body)
|
@@ -278,7 +278,7 @@ describe Zeppelin do
|
|
278
278
|
|
279
279
|
it 'requests a page of APIDs' do
|
280
280
|
stub_requests do |stub|
|
281
|
-
stub.get('/api/apids/?page=') { [200, { 'Content-Type' => 'application/json' },
|
281
|
+
stub.get('/api/apids/?page=') { [200, { 'Content-Type' => 'application/json' }, JSON.dump(results_without_next_page)] }
|
282
282
|
end
|
283
283
|
|
284
284
|
subject.apids.should eq(results_without_next_page)
|
@@ -286,7 +286,7 @@ describe Zeppelin do
|
|
286
286
|
|
287
287
|
it 'includes the page number of the next page' do
|
288
288
|
stub_requests do |stub|
|
289
|
-
stub.get('/api/apids/?page=') { [200, { 'Content-Type' => 'application/json' },
|
289
|
+
stub.get('/api/apids/?page=') { [200, { 'Content-Type' => 'application/json' }, JSON.dump(results_with_next_page)] }
|
290
290
|
end
|
291
291
|
|
292
292
|
subject.apids['next_page'].should eq(2)
|
@@ -294,7 +294,7 @@ describe Zeppelin do
|
|
294
294
|
|
295
295
|
it 'does not include the page number if there are no additional pages' do
|
296
296
|
stub_requests do |stub|
|
297
|
-
stub.get('/api/apids/?page=') { [200, { 'Content-Type' => 'application/json' },
|
297
|
+
stub.get('/api/apids/?page=') { [200, { 'Content-Type' => 'application/json' }, JSON.dump(results_without_next_page)] }
|
298
298
|
end
|
299
299
|
|
300
300
|
subject.apids.should_not have_key('next_page')
|
@@ -302,7 +302,7 @@ describe Zeppelin do
|
|
302
302
|
|
303
303
|
it 'requests a specified page of APIDs' do
|
304
304
|
stub_requests do |stub|
|
305
|
-
stub.get('/api/apids/?page=4') { [200, { 'Content-Type' => 'application/json' },
|
305
|
+
stub.get('/api/apids/?page=4') { [200, { 'Content-Type' => 'application/json' }, JSON.dump(results_without_next_page)] }
|
306
306
|
end
|
307
307
|
|
308
308
|
subject.apids(4)
|
@@ -326,7 +326,7 @@ describe Zeppelin do
|
|
326
326
|
|
327
327
|
it 'is true when the request is successful' do
|
328
328
|
stub_requests do |stub|
|
329
|
-
stub.post(uri,
|
329
|
+
stub.post(uri, JSON.dump(payload)) { [200, {}, ''] }
|
330
330
|
end
|
331
331
|
|
332
332
|
subject.push(payload).should be_true
|
@@ -364,7 +364,7 @@ describe Zeppelin do
|
|
364
364
|
|
365
365
|
it 'is true when the request was successful' do
|
366
366
|
stub_requests do |stub|
|
367
|
-
stub.post(uri,
|
367
|
+
stub.post(uri, JSON.dump(payload)) { [200, {}, ''] }
|
368
368
|
end
|
369
369
|
|
370
370
|
subject.batch_push(message1, message2).should be_true
|
@@ -388,7 +388,7 @@ describe Zeppelin do
|
|
388
388
|
|
389
389
|
it 'is true when the request is successful' do
|
390
390
|
stub_requests do |stub|
|
391
|
-
stub.post(uri,
|
391
|
+
stub.post(uri, JSON.dump(payload)) { [200, {}, ''] }
|
392
392
|
end
|
393
393
|
|
394
394
|
subject.broadcast(payload).should be_true
|
@@ -414,7 +414,7 @@ describe Zeppelin do
|
|
414
414
|
|
415
415
|
it 'is the response body for a successful request' do
|
416
416
|
stub_requests do |stub|
|
417
|
-
stub.get(uri) { [200, { 'Content-Type' => 'application/json' },
|
417
|
+
stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, JSON.dump(response_body)] }
|
418
418
|
end
|
419
419
|
|
420
420
|
subject.feedback(since)
|
@@ -486,7 +486,7 @@ describe Zeppelin do
|
|
486
486
|
|
487
487
|
it 'is the collection of tags on a device when request is successful' do
|
488
488
|
stub_requests do |stub|
|
489
|
-
stub.get(uri) { [200, { 'Content-Type' => 'application/json' },
|
489
|
+
stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, JSON.dump(response_body)] }
|
490
490
|
end
|
491
491
|
|
492
492
|
subject.device_tags(device_token).should eq(response_body)
|
@@ -558,7 +558,7 @@ describe Zeppelin do
|
|
558
558
|
|
559
559
|
it 'is true when request is successful' do
|
560
560
|
stub_requests do |stub|
|
561
|
-
stub.get(uri) { [200, { 'Content-Type' => 'application/json' },
|
561
|
+
stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, JSON.dump(response_body)] }
|
562
562
|
end
|
563
563
|
|
564
564
|
subject.tags
|
data/zeppelin.gemspec
CHANGED
@@ -15,10 +15,11 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rubyforge_project = 'zeppelin'
|
16
16
|
|
17
17
|
s.add_dependency 'faraday'
|
18
|
-
s.add_dependency '
|
18
|
+
s.add_dependency 'faraday_middleware'
|
19
19
|
|
20
20
|
s.add_development_dependency 'rspec'
|
21
21
|
s.add_development_dependency 'rake'
|
22
|
+
s.add_development_dependency 'json'
|
22
23
|
|
23
24
|
s.files = `git ls-files`.split("\n")
|
24
25
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
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.8.
|
4
|
+
version: 0.8.2
|
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-
|
13
|
+
date: 2012-06-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,21 +22,31 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
-
requirement:
|
32
|
+
name: faraday_middleware
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
|
-
- -
|
36
|
+
- - ! '>='
|
32
37
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
38
|
+
version: '0'
|
34
39
|
type: :runtime
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
37
47
|
- !ruby/object:Gem::Dependency
|
38
48
|
name: rspec
|
39
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
40
50
|
none: false
|
41
51
|
requirements:
|
42
52
|
- - ! '>='
|
@@ -44,10 +54,15 @@ dependencies:
|
|
44
54
|
version: '0'
|
45
55
|
type: :development
|
46
56
|
prerelease: false
|
47
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
48
63
|
- !ruby/object:Gem::Dependency
|
49
64
|
name: rake
|
50
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
51
66
|
none: false
|
52
67
|
requirements:
|
53
68
|
- - ! '>='
|
@@ -55,7 +70,28 @@ dependencies:
|
|
55
70
|
version: '0'
|
56
71
|
type: :development
|
57
72
|
prerelease: false
|
58
|
-
version_requirements:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: json
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
59
95
|
description: Ruby client for the Urban Airship Push Notification API
|
60
96
|
email:
|
61
97
|
- alex@kernul.com
|
@@ -75,10 +111,8 @@ files:
|
|
75
111
|
- Rakefile
|
76
112
|
- lib/zeppelin.rb
|
77
113
|
- lib/zeppelin/middleware.rb
|
78
|
-
- lib/zeppelin/middleware/json_parser.rb
|
79
114
|
- lib/zeppelin/middleware/response_raise_error.rb
|
80
115
|
- lib/zeppelin/version.rb
|
81
|
-
- spec/middleware/json_parser_spec.rb
|
82
116
|
- spec/middleware/response_raise_error_spec.rb
|
83
117
|
- spec/spec_helper.rb
|
84
118
|
- spec/zeppelin_spec.rb
|
@@ -103,12 +137,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
137
|
version: '0'
|
104
138
|
requirements: []
|
105
139
|
rubyforge_project: zeppelin
|
106
|
-
rubygems_version: 1.8.
|
140
|
+
rubygems_version: 1.8.23
|
107
141
|
signing_key:
|
108
142
|
specification_version: 3
|
109
143
|
summary: Urban Airship library for Ruby
|
110
144
|
test_files:
|
111
|
-
- spec/middleware/json_parser_spec.rb
|
112
145
|
- spec/middleware/response_raise_error_spec.rb
|
113
146
|
- spec/spec_helper.rb
|
114
147
|
- spec/zeppelin_spec.rb
|
148
|
+
has_rdoc:
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'multi_json'
|
2
|
-
|
3
|
-
class Zeppelin
|
4
|
-
module Middleware
|
5
|
-
# Middleware for Faraday that parses JSON response bodies. Based on code in
|
6
|
-
# the FaradayMiddleware project.
|
7
|
-
#
|
8
|
-
# @private
|
9
|
-
class JsonParser < Faraday::Middleware
|
10
|
-
CONTENT_TYPE = 'Content-Type'
|
11
|
-
|
12
|
-
def initialize(app=nil)
|
13
|
-
@app = app
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
@app.call(env).on_complete do
|
18
|
-
parse_response(env) if process_content_type?(env) && parse_response?(env)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def parse_response(env)
|
25
|
-
env[:body] = MultiJson.decode(env[:body])
|
26
|
-
end
|
27
|
-
|
28
|
-
def process_content_type?(env)
|
29
|
-
env[:response_headers][CONTENT_TYPE].to_s =~ /application\/(.*)json/
|
30
|
-
end
|
31
|
-
|
32
|
-
def parse_response?(env)
|
33
|
-
env[:body].respond_to? :to_str
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Zeppelin::Middleware::JsonParser do
|
4
|
-
let(:json_body) { "{\"foo\":\"bar\"}" }
|
5
|
-
|
6
|
-
let(:expected_parsed_body) { { 'foo' => 'bar' } }
|
7
|
-
|
8
|
-
it 'parses a standard JSON content type' do
|
9
|
-
process(json_body, 'application/json').body.should eq(expected_parsed_body)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'parses vendor JSON content type' do
|
13
|
-
process(json_body, 'application/vnd.urbanairship+json').body.should eq(expected_parsed_body)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'does not change nil body' do
|
17
|
-
process(nil).body.should be_nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'does not parse non-JSON content types' do
|
21
|
-
process('<hello>world</hello>', 'text/xml').body.should eq('<hello>world</hello>')
|
22
|
-
end
|
23
|
-
|
24
|
-
def process(body, content_type=nil, options={})
|
25
|
-
env = { :body => body, :response_headers => Faraday::Utils::Headers.new }
|
26
|
-
env[:response_headers]['content-type'] = content_type if content_type
|
27
|
-
|
28
|
-
middleware = Zeppelin::Middleware::JsonParser.new(
|
29
|
-
lambda { |env| Faraday::Response.new(env) }
|
30
|
-
)
|
31
|
-
|
32
|
-
middleware.call(env)
|
33
|
-
end
|
34
|
-
end
|