Skip to content

Commit

Permalink
Merge branch 'master' of github.com:PRX/apn_on_rails
Browse files Browse the repository at this point in the history
  • Loading branch information
PRXci committed Jan 4, 2011
2 parents 672d058 + cc5c412 commit e06e388
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 54 deletions.
8 changes: 4 additions & 4 deletions Gemfile
Expand Up @@ -11,9 +11,9 @@ group :development do
gem 'autotest'
gem 'sqlite3-ruby'
gem "rspec", ">= 2.0.0"
gem "bundler", ">= 1.0.0.rc.5"
gem "jeweler", "~> 1.5.0.pre2"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.0"
gem "rcov", ">= 0"
gem "actionpack", '~> 2.3.8'
gem 'activerecord', "~> 2.3.8", :require => 'active_record'
gem "actionpack", '~> 2.3.0'
gem 'activerecord', "~> 2.3.0", :require => 'active_record'
end
44 changes: 22 additions & 22 deletions Gemfile.lock
@@ -1,47 +1,47 @@
GEM
remote: http://rubygems.org/
specs:
actionpack (2.3.9)
activesupport (= 2.3.9)
ZenTest (4.4.2)
actionpack (2.3.10)
activesupport (= 2.3.10)
rack (~> 1.1.0)
activerecord (2.3.9)
activesupport (= 2.3.9)
activesupport (2.3.9)
autotest (4.3.2)
activerecord (2.3.10)
activesupport (= 2.3.10)
activesupport (2.3.10)
autotest (4.4.6)
ZenTest (>= 4.4.1)
configatron (2.6.4)
yamler (>= 0.1.0)
diff-lcs (1.1.2)
git (1.2.5)
jeweler (1.5.0.pre3)
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
rack (1.1.0)
rake (0.8.7)
rcov (0.9.9)
rspec (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
rspec-mocks (~> 2.0.1)
rspec-core (2.0.1)
rspec-expectations (2.0.1)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
sqlite3-ruby (1.3.1)
rspec (2.4.0)
rspec-core (~> 2.4.0)
rspec-expectations (~> 2.4.0)
rspec-mocks (~> 2.4.0)
rspec-core (2.4.0)
rspec-expectations (2.4.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0)
sqlite3-ruby (1.3.2)
yamler (0.1.0)

PLATFORMS
ruby

DEPENDENCIES
actionpack (~> 2.3.8)
activerecord (~> 2.3.8)
actionpack (~> 2.3.0)
activerecord (~> 2.3.0)
autotest
bundler (>= 1.0.0.rc.5)
bundler (~> 1.0.0)
configatron
jeweler (~> 1.5.0.pre2)
jeweler (~> 1.5.0)
rcov
rspec (>= 2.0.0)
sqlite3-ruby
29 changes: 14 additions & 15 deletions apn_on_rails.gemspec
@@ -1,6 +1,6 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
Expand All @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["markbates", "Rebecca Nesson"]
s.date = %q{2010-11-09}
s.date = %q{2011-01-04}
s.description = %q{APN on Rails is a Ruby on Rails gem that allows you to
easily add Apple Push Notification (iPhone) support to your Rails application.
}
Expand All @@ -20,7 +20,6 @@ easily add Apple Push Notification (iPhone) support to your Rails application.
"README.textile"
]
s.files = [
".gitignore",
".rspec",
".specification",
"Gemfile",
Expand Down Expand Up @@ -113,32 +112,32 @@ easily add Apple Push Notification (iPhone) support to your Rails application.
s.add_development_dependency(%q<autotest>, [">= 0"])
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
s.add_development_dependency(%q<bundler>, [">= 1.0.0.rc.5"])
s.add_development_dependency(%q<jeweler>, ["~> 1.5.0.pre2"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.5.0"])
s.add_development_dependency(%q<rcov>, [">= 0"])
s.add_development_dependency(%q<actionpack>, ["~> 2.3.8"])
s.add_development_dependency(%q<activerecord>, ["~> 2.3.8"])
s.add_development_dependency(%q<actionpack>, ["~> 2.3.0"])
s.add_development_dependency(%q<activerecord>, ["~> 2.3.0"])
else
s.add_dependency(%q<configatron>, [">= 0"])
s.add_dependency(%q<autotest>, [">= 0"])
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
s.add_dependency(%q<rspec>, [">= 2.0.0"])
s.add_dependency(%q<bundler>, [">= 1.0.0.rc.5"])
s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre2"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.0"])
s.add_dependency(%q<rcov>, [">= 0"])
s.add_dependency(%q<actionpack>, ["~> 2.3.8"])
s.add_dependency(%q<activerecord>, ["~> 2.3.8"])
s.add_dependency(%q<actionpack>, ["~> 2.3.0"])
s.add_dependency(%q<activerecord>, ["~> 2.3.0"])
end
else
s.add_dependency(%q<configatron>, [">= 0"])
s.add_dependency(%q<autotest>, [">= 0"])
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
s.add_dependency(%q<rspec>, [">= 2.0.0"])
s.add_dependency(%q<bundler>, [">= 1.0.0.rc.5"])
s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre2"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.0"])
s.add_dependency(%q<rcov>, [">= 0"])
s.add_dependency(%q<actionpack>, ["~> 2.3.8"])
s.add_dependency(%q<activerecord>, ["~> 2.3.8"])
s.add_dependency(%q<actionpack>, ["~> 2.3.0"])
s.add_dependency(%q<activerecord>, ["~> 2.3.0"])
end
end

8 changes: 4 additions & 4 deletions lib/apn_on_rails/app/models/apn/app.rb
Expand Up @@ -31,8 +31,8 @@ def self.send_notifications
apps.each do |app|
app.send_notifications
end
global_cert = File.read(configatron.apn.cert)
if global_cert
if !configatron.apn.cert.blank?
global_cert = File.read(configatron.apn.cert)
send_notifications_for_cert(global_cert, nil)
end
end
Expand Down Expand Up @@ -124,8 +124,8 @@ def self.process_devices
apps.each do |app|
app.process_devices
end
global_cert = File.read(configatron.apn.cert)
if global_cert
if !configatron.apn.cert.blank?
global_cert = File.read(configatron.apn.cert)
APN::App.process_devices_for_cert(global_cert)
end
end
Expand Down
7 changes: 3 additions & 4 deletions lib/apn_on_rails/libs/feedback.rb
Expand Up @@ -13,10 +13,9 @@ class << self
def devices(cert, &block)
devices = []
return if cert.nil?
APN::Connection.open_for_feedback({:cert => cert}) do |conn, sock|
while line = sock.gets # Read lines from the socket
line.strip!
feedback = line.unpack('N1n1H140')
APN::Connection.open_for_feedback({:cert => cert}) do |conn, sock|
while line = conn.read(38) # Read 38 bytes from the SSL socket
feedback = line.unpack('N1n1H140')
token = feedback[2].scan(/.{0,8}/).join(' ').strip
device = APN::Device.find(:first, :conditions => {:token => token})
if device
Expand Down
8 changes: 3 additions & 5 deletions spec/apn_on_rails/libs/feedback_spec.rb
Expand Up @@ -9,14 +9,12 @@
@device = DeviceFactory.create
@cert = mock('cert_mock')

@data_mock = mock('data_mock')
@data_mock.should_receive(:strip!)
@data_mock = mock('data_mock')
@data_mock.should_receive(:unpack).with('N1n1H140').and_return([@time.to_i, 12388, @device.token.delete(' ')])

@ssl_mock = mock('ssl_mock')
@ssl_mock = mock('ssl_mock')
@ssl_mock.should_receive(:read).with(38).twice.and_return(@data_mock, nil)
@sock_mock = mock('sock_mock')
@sock_mock.should_receive(:gets).twice.and_return(@data_mock, nil)

end

it 'should an Array of devices that need to be processed' do
Expand Down

0 comments on commit e06e388

Please sign in to comment.