apn_on_rails 0.4.1 → 0.4.2

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/Gemfile CHANGED
@@ -11,9 +11,9 @@ group :development do
11
11
  gem 'autotest'
12
12
  gem 'sqlite3-ruby'
13
13
  gem "rspec", ">= 2.0.0"
14
- gem "bundler", ">= 1.0.0.rc.5"
15
- gem "jeweler", "~> 1.5.0.pre2"
14
+ gem "bundler", "~> 1.0.0"
15
+ gem "jeweler", "~> 1.5.0"
16
16
  gem "rcov", ">= 0"
17
- gem "actionpack", '~> 2.3.8'
18
- gem 'activerecord', "~> 2.3.8", :require => 'active_record'
17
+ gem "actionpack", '~> 2.3.0'
18
+ gem 'activerecord', "~> 2.3.0", :require => 'active_record'
19
19
  end
@@ -1,47 +1,47 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- actionpack (2.3.9)
5
- activesupport (= 2.3.9)
4
+ ZenTest (4.4.2)
5
+ actionpack (2.3.10)
6
+ activesupport (= 2.3.10)
6
7
  rack (~> 1.1.0)
7
- activerecord (2.3.9)
8
- activesupport (= 2.3.9)
9
- activesupport (2.3.9)
10
- autotest (4.3.2)
8
+ activerecord (2.3.10)
9
+ activesupport (= 2.3.10)
10
+ activesupport (2.3.10)
11
+ autotest (4.4.6)
12
+ ZenTest (>= 4.4.1)
11
13
  configatron (2.6.4)
12
14
  yamler (>= 0.1.0)
13
15
  diff-lcs (1.1.2)
14
16
  git (1.2.5)
15
- jeweler (1.5.0.pre3)
17
+ jeweler (1.5.2)
16
18
  bundler (~> 1.0.0)
17
19
  git (>= 1.2.5)
18
20
  rake
19
21
  rack (1.1.0)
20
22
  rake (0.8.7)
21
23
  rcov (0.9.9)
22
- rspec (2.0.1)
23
- rspec-core (~> 2.0.1)
24
- rspec-expectations (~> 2.0.1)
25
- rspec-mocks (~> 2.0.1)
26
- rspec-core (2.0.1)
27
- rspec-expectations (2.0.1)
28
- diff-lcs (>= 1.1.2)
29
- rspec-mocks (2.0.1)
30
- rspec-core (~> 2.0.1)
31
- rspec-expectations (~> 2.0.1)
32
- sqlite3-ruby (1.3.1)
24
+ rspec (2.4.0)
25
+ rspec-core (~> 2.4.0)
26
+ rspec-expectations (~> 2.4.0)
27
+ rspec-mocks (~> 2.4.0)
28
+ rspec-core (2.4.0)
29
+ rspec-expectations (2.4.0)
30
+ diff-lcs (~> 1.1.2)
31
+ rspec-mocks (2.4.0)
32
+ sqlite3-ruby (1.3.2)
33
33
  yamler (0.1.0)
34
34
 
35
35
  PLATFORMS
36
36
  ruby
37
37
 
38
38
  DEPENDENCIES
39
- actionpack (~> 2.3.8)
40
- activerecord (~> 2.3.8)
39
+ actionpack (~> 2.3.0)
40
+ activerecord (~> 2.3.0)
41
41
  autotest
42
- bundler (>= 1.0.0.rc.5)
42
+ bundler (~> 1.0.0)
43
43
  configatron
44
- jeweler (~> 1.5.0.pre2)
44
+ jeweler (~> 1.5.0)
45
45
  rcov
46
46
  rspec (>= 2.0.0)
47
47
  sqlite3-ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{apn_on_rails}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["markbates", "Rebecca Nesson"]
12
- s.date = %q{2010-11-09}
12
+ s.date = %q{2011-01-04}
13
13
  s.description = %q{APN on Rails is a Ruby on Rails gem that allows you to
14
14
  easily add Apple Push Notification (iPhone) support to your Rails application.
15
15
  }
@@ -20,7 +20,6 @@ easily add Apple Push Notification (iPhone) support to your Rails application.
20
20
  "README.textile"
21
21
  ]
22
22
  s.files = [
23
- ".gitignore",
24
23
  ".rspec",
25
24
  ".specification",
26
25
  "Gemfile",
@@ -44,6 +43,7 @@ easily add Apple Push Notification (iPhone) support to your Rails application.
44
43
  "generators/templates/apn_migrations/009_create_pull_notifications.rb",
45
44
  "generators/templates/apn_migrations/010_alter_apn_notifications.rb",
46
45
  "generators/templates/apn_migrations/011_make_device_token_index_nonunique.rb",
46
+ "generators/templates/apn_migrations/012_add_launch_notification_to_apn_pull_notifications.rb",
47
47
  "lib/apn_on_rails.rb",
48
48
  "lib/apn_on_rails/apn_on_rails.rb",
49
49
  "lib/apn_on_rails/app/models/apn/app.rb",
@@ -113,32 +113,32 @@ easily add Apple Push Notification (iPhone) support to your Rails application.
113
113
  s.add_development_dependency(%q<autotest>, [">= 0"])
114
114
  s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
115
115
  s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
116
- s.add_development_dependency(%q<bundler>, [">= 1.0.0.rc.5"])
117
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.0.pre2"])
116
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
117
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.0"])
118
118
  s.add_development_dependency(%q<rcov>, [">= 0"])
119
- s.add_development_dependency(%q<actionpack>, ["~> 2.3.8"])
120
- s.add_development_dependency(%q<activerecord>, ["~> 2.3.8"])
119
+ s.add_development_dependency(%q<actionpack>, ["~> 2.3.0"])
120
+ s.add_development_dependency(%q<activerecord>, ["~> 2.3.0"])
121
121
  else
122
122
  s.add_dependency(%q<configatron>, [">= 0"])
123
123
  s.add_dependency(%q<autotest>, [">= 0"])
124
124
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
125
125
  s.add_dependency(%q<rspec>, [">= 2.0.0"])
126
- s.add_dependency(%q<bundler>, [">= 1.0.0.rc.5"])
127
- s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre2"])
126
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
127
+ s.add_dependency(%q<jeweler>, ["~> 1.5.0"])
128
128
  s.add_dependency(%q<rcov>, [">= 0"])
129
- s.add_dependency(%q<actionpack>, ["~> 2.3.8"])
130
- s.add_dependency(%q<activerecord>, ["~> 2.3.8"])
129
+ s.add_dependency(%q<actionpack>, ["~> 2.3.0"])
130
+ s.add_dependency(%q<activerecord>, ["~> 2.3.0"])
131
131
  end
132
132
  else
133
133
  s.add_dependency(%q<configatron>, [">= 0"])
134
134
  s.add_dependency(%q<autotest>, [">= 0"])
135
135
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
136
136
  s.add_dependency(%q<rspec>, [">= 2.0.0"])
137
- s.add_dependency(%q<bundler>, [">= 1.0.0.rc.5"])
138
- s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre2"])
137
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
138
+ s.add_dependency(%q<jeweler>, ["~> 1.5.0"])
139
139
  s.add_dependency(%q<rcov>, [">= 0"])
140
- s.add_dependency(%q<actionpack>, ["~> 2.3.8"])
141
- s.add_dependency(%q<activerecord>, ["~> 2.3.8"])
140
+ s.add_dependency(%q<actionpack>, ["~> 2.3.0"])
141
+ s.add_dependency(%q<activerecord>, ["~> 2.3.0"])
142
142
  end
143
143
  end
144
144
 
@@ -0,0 +1,9 @@
1
+ class AddLaunchNotificationToApnPullNotifications < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :apn_pull_notifications, :launch_notification, :boolean
4
+ end
5
+
6
+ def self.down
7
+ remove_column :apn_pull_notifications, :launch_notification
8
+ end
9
+ end
@@ -31,8 +31,8 @@ class APN::App < APN::Base
31
31
  apps.each do |app|
32
32
  app.send_notifications
33
33
  end
34
- global_cert = File.read(configatron.apn.cert)
35
- if global_cert
34
+ if !configatron.apn.cert.blank?
35
+ global_cert = File.read(configatron.apn.cert)
36
36
  send_notifications_for_cert(global_cert, nil)
37
37
  end
38
38
  end
@@ -54,7 +54,8 @@ class APN::App < APN::Base
54
54
  end
55
55
  end
56
56
  end
57
- rescue
57
+ rescue Exception => e
58
+ log_connection_exception(e)
58
59
  end
59
60
  # end
60
61
  end
@@ -123,8 +124,8 @@ class APN::App < APN::Base
123
124
  apps.each do |app|
124
125
  app.process_devices
125
126
  end
126
- global_cert = File.read(configatron.apn.cert)
127
- if global_cert
127
+ if !configatron.apn.cert.blank?
128
+ global_cert = File.read(configatron.apn.cert)
128
129
  APN::App.process_devices_for_cert(global_cert)
129
130
  end
130
131
  end
@@ -140,5 +141,11 @@ class APN::App < APN::Base
140
141
  end
141
142
  end
142
143
  end
144
+
145
+
146
+ protected
147
+ def log_connection_exception(ex)
148
+ puts ex.message
149
+ end
143
150
 
144
151
  end
@@ -4,12 +4,25 @@ class APN::PullNotification < APN::Base
4
4
  validates_presence_of :app_id
5
5
 
6
6
  def self.latest_since(app_id, since_date=nil)
7
- conditions = if since_date
8
- ["app_id = ? AND created_at > ?", app_id, since_date]
9
- else
10
- ["app_id = ?", app_id]
11
- end
12
-
13
- first(:order => "created_at DESC", :conditions => conditions)
7
+ if since_date
8
+ res = first(:order => "created_at DESC",
9
+ :conditions => ["app_id = ? AND created_at > ? AND launch_notification = ?", app_id, since_date, false])
10
+ else
11
+ res = first(:order => "created_at DESC",
12
+ :conditions => ["app_id = ? AND launch_notification = ?", app_id, true])
13
+ res = first(:order => "created_at DESC",
14
+ :conditions => ["app_id = ? AND launch_notification = ?", app_id, false]) unless res
15
+ end
16
+ res
17
+ end
18
+
19
+ def self.all_since(app_id, since_date=nil)
20
+ if since_date
21
+ res = all(:order => "created_at DESC",
22
+ :conditions => ["app_id = ? AND created_at > ? AND launch_notification = ?", app_id, since_date, false])
23
+ else
24
+ res = all(:order => "created_at DESC",
25
+ :conditions => ["app_id = ? AND launch_notification = ?", app_id, false])
26
+ end
14
27
  end
15
28
  end
@@ -13,10 +13,9 @@ module APN
13
13
  def devices(cert, &block)
14
14
  devices = []
15
15
  return if cert.nil?
16
- APN::Connection.open_for_feedback({:cert => cert}) do |conn, sock|
17
- while line = sock.gets # Read lines from the socket
18
- line.strip!
19
- feedback = line.unpack('N1n1H140')
16
+ APN::Connection.open_for_feedback({:cert => cert}) do |conn, sock|
17
+ while line = conn.read(38) # Read 38 bytes from the SSL socket
18
+ feedback = line.unpack('N1n1H140')
20
19
  token = feedback[2].scan(/.{0,8}/).join(' ').strip
21
20
  device = APN::Device.find(:first, :conditions => {:token => token})
22
21
  if device
@@ -21,12 +21,14 @@ describe APN::PullNotification do
21
21
  noty1 = PullNotificationFactory.create({:app_id => app.id})
22
22
  noty1.created_at = Time.now + 1.week
23
23
  noty1.save
24
- APN::PullNotification.latest_since(app.id,Time.now - 1.week).should == noty1
24
+ latest = APN::PullNotification.latest_since(app.id,Time.now - 1.week)
25
+ puts "latest is #{latest}"
26
+ latest.should == noty1
25
27
  end
26
28
 
27
29
  end
28
30
 
29
- describe 'latest_since_with_no_date' do
31
+ describe 'latest_since_with_no_date_when_there_is_no_launch_notification' do
30
32
  it 'should return the most recent pull notification because no date is given' do
31
33
  app = APN::App.first
32
34
  noty1 = APN::PullNotification.find(:first, :order => "created_at DESC")
@@ -34,4 +36,65 @@ describe APN::PullNotification do
34
36
  end
35
37
  end
36
38
 
39
+ describe 'latest_since_with_no_date_when_there_is_a_launch_notification' do
40
+ it 'should return the launch notification even though there is a more recent notification' do
41
+ app = APN::App.first
42
+ noty_launch = PullNotificationFactory.create({:app_id => app.id, :launch_notification => true})
43
+ noty_launch.created_at = Time.now - 1.week
44
+ noty_launch.save
45
+ noty_nonlaunch = PullNotificationFactory.create({:app_id => app.id})
46
+ APN::PullNotification.latest_since(app.id).should == noty_launch
47
+ end
48
+ end
49
+
50
+ describe 'older_non_launch_noty_with_newer_launch_noty' do
51
+ it 'should return the older non launch notification even though a newer launch notification exists' do
52
+ APN::PullNotification.all.each { |n| n.destroy }
53
+ app = APN::App.first
54
+ noty_launch = PullNotificationFactory.create({:app_id => app.id, :launch_notification => true})
55
+ puts "noty_launch id is #{noty_launch.id}"
56
+ noty_nonlaunch = PullNotificationFactory.create({:app_id => app.id})
57
+ noty_nonlaunch.created_at = Time.now - 1.week
58
+ noty_nonlaunch.save
59
+ puts "noty_nonlaunch id is #{noty_nonlaunch.id}"
60
+ APN::PullNotification.latest_since(app.id, Time.now - 2.weeks).should == noty_nonlaunch
61
+ end
62
+ end
63
+
64
+ describe 'all_since_date_with_date_given' do
65
+ it 'should return all the non-launch notifications after the given date but not the ones before it' do
66
+ APN::PullNotification.all.each { |n| n.destroy }
67
+ app = APN::App.first
68
+ noty_launch = PullNotificationFactory.create({:app_id => app.id, :launch_notification => true})
69
+ noty_launch.created_at = Time.now - 2.weeks
70
+ noty_launch.save
71
+ old_noty = PullNotificationFactory.create({:app_id => app.id})
72
+ old_noty.created_at = Time.now - 2.weeks
73
+ old_noty.save
74
+ new_noty_one = PullNotificationFactory.create({:app_id => app.id})
75
+ new_noty_one.created_at = Time.now - 1.day
76
+ new_noty_one.save
77
+ new_noty_two = PullNotificationFactory.create({:app_id => app.id})
78
+ APN::PullNotification.all_since(app.id, Time.now - 1.week).should == [new_noty_two,new_noty_one]
79
+ end
80
+ end
81
+
82
+ describe 'all_since_with_no_since_date_given' do
83
+ it 'should return all of the non-launch notifications' do
84
+ APN::PullNotification.all.each { |n| n.destroy }
85
+ app = APN::App.first
86
+ noty_launch = PullNotificationFactory.create({:app_id => app.id, :launch_notification => true})
87
+ noty_launch.created_at = Time.now - 2.weeks
88
+ noty_launch.save
89
+ old_noty = PullNotificationFactory.create({:app_id => app.id})
90
+ old_noty.created_at = Time.now - 2.weeks
91
+ old_noty.save
92
+ new_noty_one = PullNotificationFactory.create({:app_id => app.id})
93
+ new_noty_one.created_at = Time.now - 1.day
94
+ new_noty_one.save
95
+ new_noty_two = PullNotificationFactory.create({:app_id => app.id})
96
+ APN::PullNotification.all_since(app.id, Time.now - 3.weeks).should == [new_noty_two,new_noty_one,old_noty]
97
+ end
98
+ end
99
+
37
100
  end
@@ -9,14 +9,12 @@ describe APN::Feedback do
9
9
  @device = DeviceFactory.create
10
10
  @cert = mock('cert_mock')
11
11
 
12
- @data_mock = mock('data_mock')
13
- @data_mock.should_receive(:strip!)
12
+ @data_mock = mock('data_mock')
14
13
  @data_mock.should_receive(:unpack).with('N1n1H140').and_return([@time.to_i, 12388, @device.token.delete(' ')])
15
14
 
16
- @ssl_mock = mock('ssl_mock')
15
+ @ssl_mock = mock('ssl_mock')
16
+ @ssl_mock.should_receive(:read).with(38).twice.and_return(@data_mock, nil)
17
17
  @sock_mock = mock('sock_mock')
18
- @sock_mock.should_receive(:gets).twice.and_return(@data_mock, nil)
19
-
20
18
  end
21
19
 
22
20
  it 'should an Array of devices that need to be processed' do
@@ -5,7 +5,7 @@ module PullNotificationFactory
5
5
  def new(options = {})
6
6
  app = APN::App.first
7
7
  options = {:app_id => app.id, :title => 'Pull Notification Title',
8
- :content => 'blah blah blah', :link => 'http://www.prx.org'}.merge(options)
8
+ :content => 'blah blah blah', :link => 'http://www.prx.org', :launch_notification => false}.merge(options)
9
9
  return APN::PullNotification.new(options)
10
10
  end
11
11
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apn_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - markbates
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-09 00:00:00 -05:00
19
+ date: 2011-01-04 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -83,16 +83,14 @@ dependencies:
83
83
  requirement: &id005 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
- - - ">="
86
+ - - ~>
87
87
  - !ruby/object:Gem::Version
88
- hash: 15424063
88
+ hash: 23
89
89
  segments:
90
90
  - 1
91
91
  - 0
92
92
  - 0
93
- - rc
94
- - 5
95
- version: 1.0.0.rc.5
93
+ version: 1.0.0
96
94
  type: :development
97
95
  version_requirements: *id005
98
96
  - !ruby/object:Gem::Dependency
@@ -103,13 +101,12 @@ dependencies:
103
101
  requirements:
104
102
  - - ~>
105
103
  - !ruby/object:Gem::Version
106
- hash: -1876988199
104
+ hash: 3
107
105
  segments:
108
106
  - 1
109
107
  - 5
110
108
  - 0
111
- - pre2
112
- version: 1.5.0.pre2
109
+ version: 1.5.0
113
110
  type: :development
114
111
  version_requirements: *id006
115
112
  - !ruby/object:Gem::Dependency
@@ -134,12 +131,12 @@ dependencies:
134
131
  requirements:
135
132
  - - ~>
136
133
  - !ruby/object:Gem::Version
137
- hash: 19
134
+ hash: 3
138
135
  segments:
139
136
  - 2
140
137
  - 3
141
- - 8
142
- version: 2.3.8
138
+ - 0
139
+ version: 2.3.0
143
140
  type: :development
144
141
  version_requirements: *id008
145
142
  - !ruby/object:Gem::Dependency
@@ -150,12 +147,12 @@ dependencies:
150
147
  requirements:
151
148
  - - ~>
152
149
  - !ruby/object:Gem::Version
153
- hash: 19
150
+ hash: 3
154
151
  segments:
155
152
  - 2
156
153
  - 3
157
- - 8
158
- version: 2.3.8
154
+ - 0
155
+ version: 2.3.0
159
156
  type: :development
160
157
  version_requirements: *id009
161
158
  description: |
@@ -172,7 +169,6 @@ extra_rdoc_files:
172
169
  - README
173
170
  - README.textile
174
171
  files:
175
- - .gitignore
176
172
  - .rspec
177
173
  - .specification
178
174
  - Gemfile
@@ -196,6 +192,7 @@ files:
196
192
  - generators/templates/apn_migrations/009_create_pull_notifications.rb
197
193
  - generators/templates/apn_migrations/010_alter_apn_notifications.rb
198
194
  - generators/templates/apn_migrations/011_make_device_token_index_nonunique.rb
195
+ - generators/templates/apn_migrations/012_add_launch_notification_to_apn_pull_notifications.rb
199
196
  - lib/apn_on_rails.rb
200
197
  - lib/apn_on_rails/apn_on_rails.rb
201
198
  - lib/apn_on_rails/app/models/apn/app.rb
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.log
2
- .DS_Store
3
- doc
4
- tmp
5
- pkg
6
- *.gem
7
- *.pid
8
- coverage
9
- coverage.data
10
- build/*
11
- *.pbxuser
12
- *.mode1v3
13
- .svn
14
- profile
15
- spec/active_record/test.db
16
- .bundle
17
- **/.svn