grocer 0.0.10 → 0.0.11

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/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/highgroove/grocer.png)](http://travis-ci.org/highgroove/grocer)
4
4
  [![Dependency Status](https://gemnasium.com/highgroove/grocer.png)](https://gemnasium.com/highgroove/grocer)
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/highgroove/grocer)
5
6
 
6
7
  **grocer** interfaces with the [Apple Push Notification
7
8
  Service](http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html)
@@ -12,7 +13,8 @@ cleanest, most extensible, and friendliest.
12
13
 
13
14
  ## Requirements
14
15
 
15
- * Ruby/MRI 1.9.x *or* Rubinius in 1.9 mode (JRuby in 1.9 is broken due to some problem with 'json' not being in the stdlib?)
16
+ * Ruby/MRI 1.9.x *or* Rubinius in 1.9 mode (JRuby in 1.9 is broken due to some
17
+ problem with `json` not being in the stdlib?)
16
18
 
17
19
  ## Installation
18
20
 
@@ -46,7 +48,7 @@ pusher = Grocer.pusher(
46
48
  * `gateway`: Defaults to different values depending on the `RAILS_ENV` or
47
49
  `RACK_ENV` environment variables. If set to `production`, defaults to
48
50
  `gateway.push.apple.com`, if set to `test`, defaults to `localhost` (see
49
- "Acceptance Testing" later), otherwise defaults to
51
+ [Acceptance Testing](#acceptance-testing) later), otherwise defaults to
50
52
  `gateway.sandbox.push.apple.com`.
51
53
  * `retries`: The number of times **grocer** will retry writing to or reading
52
54
  from the Apple Push Notification Service before raising any errors to client
@@ -127,7 +129,7 @@ end
127
129
  from the Apple Push Notification Service before raising any errors to client
128
130
  code.
129
131
 
130
- ## Acceptance Testing
132
+ ### Acceptance Testing
131
133
 
132
134
  Grocer ships with framework to setup a real looking APNS server. It listens on
133
135
  a real SSL-capable socket bound to localhost.
@@ -165,7 +167,7 @@ describe "apple push notifications" do
165
167
  end
166
168
  ```
167
169
 
168
- ### Device Token
170
+ ## Device Token
169
171
 
170
172
  A device token is obtained from within the iOS app. More details are in Apple's
171
173
  [Registering for Remote
@@ -191,15 +193,17 @@ The key code for this purpose is:
191
193
  }
192
194
  ```
193
195
 
194
- ### Certificate File
196
+ ## Certificate File
195
197
 
196
198
  Login to the [iOS Provisioning Portal (App IDs)](https://developer.apple.com/ios/manage/bundles/index.action).
197
199
 
198
- Configure the appropriate certificate for push notifications and download the certificate:
200
+ Configure the appropriate certificate for push notifications and download the
201
+ certificate:
199
202
 
200
203
  ![Downloading the Push Notification Certificate](https://img.skitch.com/20120402-gtj3bkqi1kq92kgw2pbr5puk5d.png)
201
204
 
202
- Open the file in Keychain Access, then expand the certificate to show both the certificate *and* the private key. Command select so both are highlighted:
205
+ Open the file in Keychain Access, then expand the certificate to show both the
206
+ certificate *and* the private key. Command select so both are highlighted:
203
207
 
204
208
  ![Selecting both the certificate and private key](https://img.skitch.com/20120402-e8deartr2uhimaiatgccttkggi.png)
205
209
 
@@ -207,7 +211,8 @@ Control click and select to export the 2 items:
207
211
 
208
212
  ![Exporting the certificate and private key](https://img.skitch.com/20120402-mbmgjrybyym846cy58a9kpyxp5.png)
209
213
 
210
- Save the items as a `.p12` file. Open a terminal window and run the following command:
214
+ Save the items as a `.p12` file. Open a terminal window and run the following
215
+ command:
211
216
 
212
217
  ```bash
213
218
  openssl pkcs12 -in exported_certificate.p12 -out certificate.pem -nodes -clcerts
data/lib/grocer.rb CHANGED
@@ -1,10 +1,10 @@
1
- require_relative 'grocer/feedback'
2
- require_relative 'grocer/notification'
3
- require_relative 'grocer/feedback_connection'
4
- require_relative 'grocer/push_connection'
5
- require_relative 'grocer/pusher'
6
- require_relative 'grocer/version'
7
- require_relative 'grocer/server'
1
+ require 'grocer/feedback'
2
+ require 'grocer/notification'
3
+ require 'grocer/feedback_connection'
4
+ require 'grocer/push_connection'
5
+ require 'grocer/pusher'
6
+ require 'grocer/version'
7
+ require 'grocer/server'
8
8
 
9
9
  module Grocer
10
10
 
@@ -0,0 +1,16 @@
1
+ module Grocer
2
+ module Extensions
3
+ module DeepSymbolizeKeys
4
+
5
+ def deep_symbolize_keys
6
+ result = {}
7
+ each do |key, value|
8
+ result[(key.to_sym rescue key)] = value.is_a?(Hash) ?
9
+ (value.extend DeepSymbolizeKeys).deep_symbolize_keys : value
10
+ end
11
+ result
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,4 @@
1
- require_relative 'invalid_format_error'
1
+ require 'grocer/invalid_format_error'
2
2
 
3
3
  module Grocer
4
4
  class FailedDeliveryAttempt
@@ -1,4 +1,4 @@
1
- require_relative 'failed_delivery_attempt'
1
+ require 'grocer/failed_delivery_attempt'
2
2
 
3
3
  module Grocer
4
4
  class Feedback
@@ -1,5 +1,6 @@
1
1
  require 'delegate'
2
- require_relative 'connection'
2
+ require 'grocer/extensions/deep_symbolize_keys'
3
+ require 'grocer/connection'
3
4
 
4
5
  module Grocer
5
6
  class FeedbackConnection < SimpleDelegator
@@ -8,7 +9,8 @@ module Grocer
8
9
  SANDBOX_GATEWAY = 'feedback.sandbox.push.apple.com'
9
10
 
10
11
  def initialize(options)
11
- options = defaults.merge(options)
12
+ options.extend Extensions::DeepSymbolizeKeys
13
+ options = defaults.merge(options.deep_symbolize_keys)
12
14
  super(Connection.new(options))
13
15
  end
14
16
 
@@ -1,5 +1,5 @@
1
1
  require 'json'
2
- require_relative 'no_payload_error'
2
+ require 'grocer/no_payload_error'
3
3
 
4
4
  module Grocer
5
5
  class Notification
@@ -1,5 +1,5 @@
1
1
  require 'json'
2
- require_relative 'notification'
2
+ require 'grocer/notification'
3
3
 
4
4
  module Grocer
5
5
  class NotificationReader
@@ -1,5 +1,6 @@
1
1
  require 'delegate'
2
- require_relative 'connection'
2
+ require 'grocer/extensions/deep_symbolize_keys'
3
+ require 'grocer/connection'
3
4
 
4
5
  module Grocer
5
6
  class PushConnection < SimpleDelegator
@@ -9,7 +10,8 @@ module Grocer
9
10
  SANDBOX_GATEWAY = 'gateway.sandbox.push.apple.com'
10
11
 
11
12
  def initialize(options)
12
- options = defaults.merge(options)
13
+ options.extend Extensions::DeepSymbolizeKeys
14
+ options = defaults.merge(options.deep_symbolize_keys)
13
15
  super(Connection.new(options))
14
16
  end
15
17
 
data/lib/grocer/server.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'thread'
2
- require_relative 'notification_reader'
3
- require_relative 'ssl_server'
2
+ require 'grocer/notification_reader'
3
+ require 'grocer/ssl_server'
4
4
 
5
5
  module Grocer
6
6
  class Server
@@ -20,7 +20,7 @@ module Grocer
20
20
  end
21
21
 
22
22
  def connect
23
- context = OpenSSL::SSL::SSLContext.new
23
+ context = OpenSSL::SSL::SSLContext.new
24
24
 
25
25
  if certificate
26
26
  cert_data = File.read(certificate)
@@ -1,13 +1,15 @@
1
1
  require 'openssl'
2
2
  require 'socket'
3
3
  require 'thread'
4
+ require 'grocer/extensions/deep_symbolize_keys'
4
5
 
5
6
  module Grocer
6
7
  class SSLServer
7
8
  attr_accessor :port
8
9
 
9
10
  def initialize(options = {})
10
- options = defaults.merge(options)
11
+ options.extend Extensions::DeepSymbolizeKeys
12
+ options = defaults.merge(options.deep_symbolize_keys)
11
13
  options.each { |k, v| send("#{k}=", v) }
12
14
  end
13
15
 
@@ -1,3 +1,3 @@
1
1
  module Grocer
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
@@ -0,0 +1,36 @@
1
+ require 'grocer/extensions/deep_symbolize_keys'
2
+
3
+ describe Grocer::Extensions::DeepSymbolizeKeys do
4
+ let(:nested_strings) { { 'a' => { 'b' => { 'c' => 3 } } } }
5
+ let(:nested_symbols) { { :a => { :b => { :c => 3 } } } }
6
+ let(:nested_mixed) { { 'a' => { :b => { 'c' => 3 } } } }
7
+ let(:nested_fixnums) { { 0 => { 1 => { 2 => 3} } } }
8
+ let(:nested_illegal_symbols) { { [] => { [] => 3} } }
9
+ before do
10
+ nested_symbols.extend described_class
11
+ nested_strings.extend described_class
12
+ nested_mixed.extend described_class
13
+ nested_fixnums.extend described_class
14
+ nested_illegal_symbols.extend described_class
15
+ end
16
+
17
+ it 'does not change nested symbols' do
18
+ nested_symbols.deep_symbolize_keys.should == nested_symbols
19
+ end
20
+
21
+ it 'symbolizes nested strings' do
22
+ nested_strings.deep_symbolize_keys.should == nested_symbols
23
+ end
24
+
25
+ it 'symbolizes a mix of nested strings and symbols' do
26
+ nested_mixed.deep_symbolize_keys.should == nested_symbols
27
+ end
28
+
29
+ it 'preserves fixnum keys' do
30
+ nested_fixnums.deep_symbolize_keys.should == nested_fixnums
31
+ end
32
+
33
+ it 'preserves keys that cannot be symbolized' do
34
+ nested_illegal_symbols.deep_symbolize_keys.should == nested_illegal_symbols
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grocer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-06-12 00:00:00.000000000 Z
14
+ date: 2012-06-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -117,6 +117,7 @@ files:
117
117
  - grocer.gemspec
118
118
  - lib/grocer.rb
119
119
  - lib/grocer/connection.rb
120
+ - lib/grocer/extensions/deep_symbolize_keys.rb
120
121
  - lib/grocer/failed_delivery_attempt.rb
121
122
  - lib/grocer/feedback.rb
122
123
  - lib/grocer/feedback_connection.rb
@@ -139,6 +140,7 @@ files:
139
140
  - spec/fixtures/example.key
140
141
  - spec/fixtures/example.pem
141
142
  - spec/grocer/connection_spec.rb
143
+ - spec/grocer/extensions/deep_symbolize_keys_spec.rb
142
144
  - spec/grocer/failed_delivery_attempt_spec.rb
143
145
  - spec/grocer/feedback_connection_spec.rb
144
146
  - spec/grocer/feedback_spec.rb
@@ -163,18 +165,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
165
  - - ! '>='
164
166
  - !ruby/object:Gem::Version
165
167
  version: '0'
166
- segments:
167
- - 0
168
- hash: -3763223415178507043
169
168
  required_rubygems_version: !ruby/object:Gem::Requirement
170
169
  none: false
171
170
  requirements:
172
171
  - - ! '>='
173
172
  - !ruby/object:Gem::Version
174
173
  version: '0'
175
- segments:
176
- - 0
177
- hash: -3763223415178507043
178
174
  requirements: []
179
175
  rubyforge_project:
180
176
  rubygems_version: 1.8.24
@@ -186,6 +182,7 @@ test_files:
186
182
  - spec/fixtures/example.key
187
183
  - spec/fixtures/example.pem
188
184
  - spec/grocer/connection_spec.rb
185
+ - spec/grocer/extensions/deep_symbolize_keys_spec.rb
189
186
  - spec/grocer/failed_delivery_attempt_spec.rb
190
187
  - spec/grocer/feedback_connection_spec.rb
191
188
  - spec/grocer/feedback_spec.rb