zeppelin 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/zeppelin.rb CHANGED
@@ -67,6 +67,41 @@ class Zeppelin
67
67
  successful?(response)
68
68
  end
69
69
 
70
+ # Registers an APID.
71
+ #
72
+ # @param [String] apid
73
+ # @param [Hash] payload the payload to send during registration
74
+ # @return [Boolean] whether or not the registration was successful
75
+ def register_apid(apid, payload = {})
76
+ uri = apid_uri(apid)
77
+
78
+ if payload.empty?
79
+ response = @connection.put(uri)
80
+ else
81
+ response = @connection.put(uri, payload, JSON_HEADERS)
82
+ end
83
+
84
+ successful?(response)
85
+ end
86
+
87
+ # Retrieves information on an APID.
88
+ #
89
+ # @param [String] apid
90
+ # @return [Hash, nil]
91
+ def apid(apid)
92
+ response = @connection.get(apid_uri(apid))
93
+ successful?(response) ? Yajl::Parser.parse(response.body) : nil
94
+ end
95
+
96
+ # Deletes an APID.
97
+ #
98
+ # @param [String] apid
99
+ # @return [Boolean] whether or not the deletion was successful
100
+ def delete_apid(apid)
101
+ response = @connection.delete(apid_uri(apid))
102
+ successful?(response)
103
+ end
104
+
70
105
  # Pushes a message.
71
106
  #
72
107
  # @param [Hash] payload the payload of the message
@@ -111,6 +146,10 @@ class Zeppelin
111
146
  "/api/device_tokens/#{device_token}"
112
147
  end
113
148
 
149
+ def apid_uri(apid)
150
+ "/api/apids/#{apid}"
151
+ end
152
+
114
153
  def feedback_uri(since)
115
154
  "/api/device_tokens/feedback/?since=#{since.utc.iso8601}"
116
155
  end
@@ -1,3 +1,3 @@
1
1
  class Zeppelin
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  require 'bundler/setup'
2
2
  require 'minitest/autorun'
3
+ require 'journo'
3
4
  require 'mocha'
4
5
  require 'test_declarative'
5
6
  require 'zeppelin'
6
7
 
7
8
  Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
8
9
 
9
- class Zeppelin::TestCase < MiniTest::Unit::TestCase; end
10
+ class Zeppelin::TestCase < MiniTest::Unit::TestCase; end
11
+
12
+ MiniTest::Unit.runner = Journo::SuiteRunner.new
13
+ MiniTest::Unit.runner.reporters << Journo::Reporters::ProgressReporter.new
@@ -105,6 +105,85 @@ class ZeppelinTest < Zeppelin::TestCase
105
105
  refute response
106
106
  end
107
107
 
108
+ test '#register_apid without a payload' do
109
+ stub_requests @client.connection do |stub|
110
+ stub.put("/api/apids/#{@apid}") do [201, {}, '']
111
+ end
112
+ end
113
+
114
+ response = @client.register_apid(@apid)
115
+ assert response
116
+ end
117
+
118
+ test '#register_apid an already registered APID' do
119
+ stub_requests @client.connection do |stub|
120
+ stub.put("/api/apids/#{@apid}") do
121
+ [200, {}, '']
122
+ end
123
+ end
124
+
125
+ response = @client.register_apid(@apid)
126
+ assert response
127
+ end
128
+
129
+ test '#register_apid with payload' do
130
+ payload = { :alias => 'CapnKernul' }
131
+
132
+ stub_requests @client.connection do |stub|
133
+ stub.put("/api/apids/#{@apid}", Yajl::Encoder.encode(payload)) do
134
+ [200, {}, '']
135
+ end
136
+ end
137
+
138
+ response = @client.register_apid(@apid, payload)
139
+ assert response
140
+ end
141
+
142
+ test '#register_apid with an error' do
143
+ stub_requests @client.connection do |stub|
144
+ stub.put("/api/apids/#{@apid}", nil) do
145
+ [500, {}, '']
146
+ end
147
+ end
148
+
149
+ response = @client.register_apid(@apid)
150
+ refute response
151
+ end
152
+
153
+ test '#apid' do
154
+ response_body = { 'foo' => 'bar' }
155
+ stub_requests @client.connection do |stub|
156
+ stub.get("/api/apids/#{@apid}") do
157
+ [200, {}, Yajl::Encoder.encode(response_body)]
158
+ end
159
+ end
160
+
161
+ response = @client.apid(@apid)
162
+ assert_equal response_body, response
163
+ end
164
+
165
+ test '#delete_apid with a valid APID' do
166
+ stub_requests @client.connection do |stub|
167
+ stub.delete("/api/apids/#{@apid}") do
168
+ [204, {}, '']
169
+ end
170
+ end
171
+
172
+ response = @client.delete_apid(@apid)
173
+ assert response
174
+ end
175
+
176
+ test '#delete_apid with an unknown APID' do
177
+ stub_requests @client.connection do |stub|
178
+ stub.delete("/api/apids/#{@apid}") do
179
+ [404, {}, '']
180
+ end
181
+ end
182
+
183
+ response = @client.delete_apid(@apid)
184
+ refute response
185
+ end
186
+
108
187
  test '#push with a valid payload' do
109
188
  payload = {
110
189
  :device_tokens => [@device_token],
data/zeppelin.gemspec CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency 'faraday'
18
18
  s.add_dependency 'yajl-ruby'
19
19
 
20
- s.add_development_dependency 'ansi'
21
20
  s.add_development_dependency 'minitest', '~> 2.0'
21
+ s.add_development_dependency 'journo'
22
22
  s.add_development_dependency 'mocha'
23
23
  s.add_development_dependency 'test_declarative'
24
24
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: zeppelin
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alexander Kern
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-15 00:00:00 -07:00
13
+ date: 2011-05-27 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -36,25 +36,25 @@ dependencies:
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: ansi
39
+ name: minitest
40
40
  prerelease: false
41
41
  requirement: &id003 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - ">="
44
+ - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: "0"
46
+ version: "2.0"
47
47
  type: :development
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
50
- name: minitest
50
+ name: journo
51
51
  prerelease: false
52
52
  requirement: &id004 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
- - - ~>
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: "2.0"
57
+ version: "0"
58
58
  type: :development
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
@@ -99,7 +99,6 @@ files:
99
99
  - Rakefile
100
100
  - lib/zeppelin.rb
101
101
  - lib/zeppelin/version.rb
102
- - test/support/spec_reporter.rb
103
102
  - test/test_helper.rb
104
103
  - test/zeppelin_test.rb
105
104
  - zeppelin.gemspec
@@ -132,6 +131,5 @@ signing_key:
132
131
  specification_version: 3
133
132
  summary: Urban Airship library for Ruby
134
133
  test_files:
135
- - test/support/spec_reporter.rb
136
134
  - test/test_helper.rb
137
135
  - test/zeppelin_test.rb
@@ -1,222 +0,0 @@
1
- require 'minitest/unit'
2
- require 'ansi'
3
-
4
- # Code for this runner has been borrowed and modified from MiniTest, written by
5
- # Ryan Davis of Seattle.rb. MiniTest is licensed under the MIT License, and can
6
- # be found on GitHub at https://github.com/seattlerb/minitest.
7
- #
8
- # This code is also heavily based upon these gists as well, which don't appear
9
- # to have a license:
10
- # * https://gist.github.com/356945
11
- # * https://gist.github.com/960669
12
- #
13
- # @abstract
14
- # @todo Add documentation to everything.
15
- module MiniTest
16
- class Reporter
17
- attr_accessor :runner
18
-
19
- def print(*args)
20
- runner.output.print(*args)
21
- end
22
-
23
- def puts(*args)
24
- runner.output.puts(*args)
25
- end
26
-
27
- def before_suites(suites); end
28
- def after_suites(suites); end
29
- def before_suite(suite); end
30
- def after_suite(suite); end
31
- def before_test(suite, test); end
32
- def pass(suite, test); end
33
- def skip(suite, test, e); end
34
- def failure(suite, test, e); end
35
- def error(suite, test, e); end
36
- end
37
- end
38
-
39
- module MiniTest
40
- class SpecReporter < Reporter
41
- include ANSI::Code
42
-
43
- TEST_PADDING = 2
44
- INFO_PADDING = 8
45
- MARK_SIZE = 5
46
-
47
- def before_suites(suites)
48
- @suites_start_time = Time.now
49
- puts 'Started'
50
- puts
51
- end
52
-
53
- def after_suites(suites)
54
- total_time = Time.now - @suites_start_time
55
-
56
- puts('Finished in %.5fs' % total_time)
57
- print('%d tests, %d assertions, ' % [runner.test_count, runner.assertion_count])
58
- print(red { '%d failures, %d errors, ' } % [runner.failures, runner.errors])
59
- print(yellow { '%d skips' } % runner.skips)
60
- puts
61
- end
62
-
63
- def before_suite(suite)
64
- puts suite
65
- end
66
-
67
- def after_suite(suite)
68
- puts
69
- end
70
-
71
- def before_test(suite, test)
72
- @test_start_time = Time.now
73
- end
74
-
75
- def pass(suite, test)
76
- print(green { pad_mark('PASS') })
77
- print_test_with_time(test)
78
- puts
79
- end
80
-
81
- def skip(suite, test, e)
82
- print(yellow { pad_mark('SKIP') })
83
- print_test_with_time(test)
84
- puts
85
- end
86
-
87
- def failure(suite, test, e)
88
- print(red { pad_mark('FAIL') })
89
- print_test_with_time(test)
90
- puts
91
- print_info(e)
92
- puts
93
- end
94
-
95
- def error(suite, test, e)
96
- print(red { pad_mark('ERROR') })
97
- print_test_with_time(test)
98
- puts
99
- print_info(e)
100
- puts
101
- end
102
-
103
- private
104
-
105
- def print_test_with_time(test)
106
- total_time = Time.now - @test_start_time
107
- print(" #{test} (%.2fs)" % total_time)
108
- end
109
-
110
- def print_info(e)
111
- e.message.each_line { |line| puts pad(line, INFO_PADDING) }
112
-
113
- trace = MiniTest.filter_backtrace(e.backtrace)
114
- trace.each { |line| puts pad(line, INFO_PADDING) }
115
- end
116
-
117
- def pad(str, size)
118
- ' ' * size + str
119
- end
120
-
121
- def pad_mark(str)
122
- pad("%#{MARK_SIZE}s" % str, TEST_PADDING)
123
- end
124
- end
125
- end
126
-
127
- module MiniTest
128
- class RunnerWithReporter < Unit
129
- def initialize(new_reporter)
130
- super()
131
- @reporter = new_reporter
132
- @reporter.runner = self
133
- end
134
-
135
- def puke(suite, method, e)
136
- case e
137
- when MiniTest::Skip then
138
- @skips += 1
139
- [:skip, e]
140
- when MiniTest::Assertion then
141
- @failures += 1
142
- [:failure, e]
143
- else
144
- @errors += 1
145
- [:error, e]
146
- end
147
- end
148
-
149
- def _run_anything(type)
150
- @test_count = @assertion_count = 0
151
- suites = TestCase.send("#{type}_suites")
152
- return if suites.empty?
153
-
154
- @reporter.before_suites(suites)
155
-
156
- sync = output.respond_to?(:'sync=') # stupid emacs
157
- old_sync, output.sync = output.sync, true if sync
158
- _run_suites(suites, type)
159
- output.sync = old_sync if sync
160
-
161
- @reporter.after_suites(suites)
162
- end
163
-
164
- def _run_suites(suites, type)
165
- suites.map { |suite| _run_suite(suite, type) }
166
- end
167
-
168
- def _run_suite(suite, type)
169
- run_suite_header(suite, type)
170
-
171
- filter = options[:filter] || '/./'
172
- filter = Regexp.new($1) if filter =~ /\/(.*)\//
173
-
174
- tests = suite.send("#{type}_methods").grep(filter)
175
-
176
- unless tests.empty?
177
- @reporter.before_suite(suite)
178
- run_suite_tests(suite, tests)
179
- @reporter.after_suite(suite)
180
- end
181
- end
182
-
183
- private
184
-
185
- def run_suite_header(suite, type)
186
- header_method = "#{type}_suite_header"
187
- send(header_method, suite) if respond_to?(header_method)
188
- end
189
-
190
- def run_suite_tests(suite, tests)
191
- suite.startup if suite.respond_to?(:startup)
192
-
193
- tests.each do |test|
194
- @reporter.before_test(suite, test)
195
- response, e = run_suite_test(suite, test)
196
-
197
- case response
198
- when :pass then @reporter.pass(suite, test)
199
- when :skip then @reporter.skip(suite, test, e)
200
- when :failure then @reporter.failure(suite, test, e)
201
- else @reporter.error(suite, test, e)
202
- end
203
- end
204
- ensure
205
- suite.shutdown if suite.respond_to?(:shutdown)
206
- end
207
-
208
- def run_suite_test(suite, test)
209
- suite_instance = suite.new(test)
210
- suite_instance._assertions = 0
211
-
212
- result = suite_instance.run(self)
213
-
214
- @test_count += 1
215
- @assertion_count += suite_instance._assertions
216
-
217
- result == '.' ? :pass : result
218
- end
219
- end
220
- end
221
-
222
- MiniTest::Unit.runner = MiniTest::RunnerWithReporter.new(MiniTest::SpecReporter.new)