From 5c508005cf8fcb4176ef0b2749c1344c4b0d89e0 Mon Sep 17 00:00:00 2001 From: Jeremy Tregunna Date: Thu, 17 Mar 2011 22:20:52 -0400 Subject: [PATCH] replaced ActiveSupport with Yajl --- Gemfile | 5 ++--- Gemfile.lock | 6 ++---- README.textile | 9 ++++++++- lib/apnserver/notification.rb | 7 +++---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index bf16f02..21a099d 100644 --- a/Gemfile +++ b/Gemfile @@ -2,9 +2,8 @@ source "http://rubygems.org" gem "eventmachine" gem "daemons" -gem "activesupport", ">= 3.0.0" -gem "i18n" # active support whines without this +gem "yajl-ruby" group :spec do gem "rspec" -end \ No newline at end of file +end diff --git a/Gemfile.lock b/Gemfile.lock index 408394e..74704f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,11 +1,9 @@ GEM remote: http://rubygems.org/ specs: - activesupport (3.0.3) daemons (1.0.10) diff-lcs (1.1.2) eventmachine (0.12.10) - i18n (0.5.0) rspec (2.3.0) rspec-core (~> 2.3.0) rspec-expectations (~> 2.3.0) @@ -14,13 +12,13 @@ GEM rspec-expectations (2.3.0) diff-lcs (~> 1.1.2) rspec-mocks (2.3.0) + yajl-ruby (0.8.1) PLATFORMS ruby DEPENDENCIES - activesupport (>= 3.0.0) daemons eventmachine - i18n rspec + yajl-ruby diff --git a/README.textile b/README.textile index 8546420..1e3af0b 100644 --- a/README.textile +++ b/README.textile @@ -2,6 +2,13 @@ h1. Apple Push Notification Server Toolkit * http://github.com/bpoweski/apnserver +This is an independent fork of the above repository, to run with the Fracas web service. Some +changes have been made, notably the JSON encoding/decoding. I've pulled out the dependency on +ActiveSupport, and introduced a dependency on Yajl. As such, I've rewritten all JSON decoding +and encoding to use Yajl. + +Other changes will be forthcoming. + h2. Description apnserver is a server and set of command line programs to send push notifications to the iPhone. @@ -20,7 +27,7 @@ h2. Issues Fixed * second attempt at retry logic, SSL Errors close down sockets now * apnsend --badge option correctly sends integer number rather than string of number for aps json payload * connections are properly closed in Notification#push method now - * removed json gem in favor of ActiveSupport + * removed ActiveSupport in favor of Yajl * Rails 3.x support * drop the erroneous puts statements in favor a configurable logger * moved to Rspec diff --git a/lib/apnserver/notification.rb b/lib/apnserver/notification.rb index 1a66189..34b457b 100644 --- a/lib/apnserver/notification.rb +++ b/lib/apnserver/notification.rb @@ -1,7 +1,6 @@ require 'apnserver/payload' require 'base64' -require 'active_support/ordered_hash' -require 'active_support/json' +require 'yajl' module ApnServer class Config @@ -26,7 +25,7 @@ def payload end def json_payload - j = ActiveSupport::JSON.encode(payload) + j = Yajl::Encoder.encode(payload) raise PayloadInvalid.new("The payload is larger than allowed: #{j.length}") if j.size > 256 j end @@ -77,7 +76,7 @@ def self.parse(p) # parse json payload payload_len = buffer.slice!(0, 2).unpack('CC') j = buffer.slice!(0, payload_len.last) - result = ActiveSupport::JSON.decode(j) + result = Yajl::Parser.parse(j) ['alert', 'badge', 'sound'].each do |k| notification.send("#{k}=", result['aps'][k]) if result['aps'] && result['aps'][k]