apn_on_rails 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +3 -18
  3. data/Gemfile.lock +52 -19
  4. data/Rakefile +3 -17
  5. data/apn_on_rails.gemspec +23 -135
  6. data/generators/apn_migrations_generator.rb +13 -11
  7. data/lib/apn_on_rails/apn_on_rails.rb +19 -19
  8. data/lib/apn_on_rails/app/models/apn/app.rb +30 -29
  9. data/lib/apn_on_rails/tasks/db.rake +4 -0
  10. data/lib/apn_on_rails/version.rb +3 -0
  11. data/lib/generators/apn_on_rails/install/USAGE +8 -0
  12. data/lib/generators/apn_on_rails/install/install_generator.rb +38 -0
  13. data/lib/generators/apn_on_rails/install/templates/001_create_apn_devices.rb +13 -0
  14. data/lib/generators/apn_on_rails/install/templates/002_create_apn_notifications.rb +23 -0
  15. data/lib/generators/apn_on_rails/install/templates/003_alter_apn_devices.rb +25 -0
  16. data/lib/generators/apn_on_rails/install/templates/004_create_apn_apps.rb +18 -0
  17. data/lib/generators/apn_on_rails/install/templates/005_create_groups.rb +23 -0
  18. data/lib/generators/apn_on_rails/install/templates/006_alter_apn_groups.rb +11 -0
  19. data/lib/generators/apn_on_rails/install/templates/007_create_device_groups.rb +27 -0
  20. data/lib/generators/apn_on_rails/install/templates/008_create_apn_group_notifications.rb +23 -0
  21. data/lib/generators/apn_on_rails/install/templates/009_create_pull_notifications.rb +16 -0
  22. data/lib/generators/apn_on_rails/install/templates/010_alter_apn_notifications.rb +21 -0
  23. data/lib/generators/apn_on_rails/install/templates/011_make_device_token_index_nonunique.rb +11 -0
  24. data/lib/generators/apn_on_rails/install/templates/012_add_launch_notification_to_apn_pull_notifications.rb +9 -0
  25. metadata +57 -55
@@ -0,0 +1,17 @@
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
data/Gemfile CHANGED
@@ -1,19 +1,4 @@
1
- source :gemcutter
2
- gem 'configatron'
1
+ source "http://rubygems.org"
3
2
 
4
- # Add dependencies required to use your gem here.
5
- # Example:
6
- # gem "activesupport", ">= 2.3.5"
7
-
8
- # Add dependencies to develop your gem here.
9
- # Include everything needed to run rake, tests, features, etc.
10
- group :development do
11
- gem 'autotest'
12
- gem 'sqlite3-ruby'
13
- gem "rspec", ">= 2.0.0"
14
- gem "bundler", "~> 1.0.0"
15
- gem "jeweler", "~> 1.5.0"
16
- gem "rcov", ">= 0"
17
- gem "actionpack", '~> 2.3.0'
18
- gem 'activerecord', "~> 2.3.0", :require => 'active_record'
19
- end
3
+ # Specify your gem's dependencies in apn_on_rails.gemspec
4
+ gemspec
@@ -1,24 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ apn_on_rails (0.5.0)
5
+ actionpack
6
+ activerecord
7
+ configatron
8
+
1
9
  GEM
2
10
  remote: http://rubygems.org/
3
11
  specs:
4
12
  ZenTest (4.4.2)
5
- actionpack (2.3.10)
6
- activesupport (= 2.3.10)
7
- rack (~> 1.1.0)
8
- activerecord (2.3.10)
9
- activesupport (= 2.3.10)
10
- activesupport (2.3.10)
13
+ actionpack (3.2.1)
14
+ activemodel (= 3.2.1)
15
+ activesupport (= 3.2.1)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.1)
19
+ rack (~> 1.4.0)
20
+ rack-cache (~> 1.1)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.1.2)
23
+ activemodel (3.2.1)
24
+ activesupport (= 3.2.1)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.1)
27
+ activemodel (= 3.2.1)
28
+ activesupport (= 3.2.1)
29
+ arel (~> 3.0.0)
30
+ tzinfo (~> 0.3.29)
31
+ activesupport (3.2.1)
32
+ i18n (~> 0.6)
33
+ multi_json (~> 1.0)
34
+ arel (3.0.0)
11
35
  autotest (4.4.6)
12
36
  ZenTest (>= 4.4.1)
13
- configatron (2.6.4)
37
+ builder (3.0.0)
38
+ configatron (2.9.0)
14
39
  yamler (>= 0.1.0)
15
40
  diff-lcs (1.1.2)
16
- git (1.2.5)
17
- jeweler (1.5.2)
18
- bundler (~> 1.0.0)
19
- git (>= 1.2.5)
20
- rake
21
- rack (1.1.0)
41
+ erubis (2.7.0)
42
+ hike (1.2.1)
43
+ i18n (0.6.0)
44
+ journey (1.0.1)
45
+ multi_json (1.0.4)
46
+ rack (1.4.1)
47
+ rack-cache (1.1)
48
+ rack (>= 0.4)
49
+ rack-test (0.6.1)
50
+ rack (>= 1.0)
22
51
  rake (0.8.7)
23
52
  rcov (0.9.9)
24
53
  rspec (2.4.0)
@@ -29,19 +58,23 @@ GEM
29
58
  rspec-expectations (2.4.0)
30
59
  diff-lcs (~> 1.1.2)
31
60
  rspec-mocks (2.4.0)
61
+ sprockets (2.1.2)
62
+ hike (~> 1.2)
63
+ rack (~> 1.0)
64
+ tilt (!= 1.3.0, ~> 1.1)
32
65
  sqlite3-ruby (1.3.2)
66
+ tilt (1.3.3)
67
+ tzinfo (0.3.31)
33
68
  yamler (0.1.0)
34
69
 
35
70
  PLATFORMS
36
71
  ruby
37
72
 
38
73
  DEPENDENCIES
39
- actionpack (~> 2.3.0)
40
- activerecord (~> 2.3.0)
74
+ apn_on_rails!
41
75
  autotest
42
- bundler (~> 1.0.0)
43
- configatron
44
- jeweler (~> 1.5.0)
76
+ bundler
77
+ rake
45
78
  rcov
46
- rspec (>= 2.0.0)
79
+ rspec
47
80
  sqlite3-ruby
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+ require "bundler/gem_tasks"
4
+
3
5
  begin
4
6
  Bundler.setup(:default, :development)
5
7
  rescue Bundler::BundlerError => e
@@ -7,24 +9,8 @@ rescue Bundler::BundlerError => e
7
9
  $stderr.puts "Run `bundle install` to install missing gems"
8
10
  exit e.status_code
9
11
  end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "apn_on_rails"
16
- gem.summary = %Q{Apple Push Notifications on Rails}
17
-
18
- gem.description = %Q{APN on Rails is a Ruby on Rails gem that allows you to
19
- easily add Apple Push Notification (iPhone) support to your Rails application.
20
- }
21
-
22
- gem.email = "tech-team@prx.org"
23
- gem.homepage = "http://github.com/PRX/apn_on_rails"
24
- gem.authors = ["markbates", "Rebecca Nesson"]
25
- end
26
- #Jeweler::RubygemsDotOrgsTasks.new
27
12
 
13
+ require 'rake'
28
14
  require 'rspec/core'
29
15
  require 'rspec/core/rake_task'
30
16
  RSpec::Core::RakeTask.new(:spec) do |spec|
@@ -1,144 +1,32 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "apn_on_rails/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{apn_on_rails}
8
- s.version = "0.4.2"
6
+ s.name = %q{apn_on_rails}
7
+ s.version = ApnOnRails::VERSION
8
+ s.authors = ["markbates", "Rebecca Nesson"]
9
+ s.email = %q{tech-team@prx.org}
10
+ s.homepage = %q{http://github.com/PRX/apn_on_rails}
11
+ s.summary = %q{Apple Push Notifications on Rails}
12
+ s.description = %q{APN on Rails is a Ruby on Rails gem that allows you to
13
+ easily add Apple Push Notification (iPhone) support to your Rails application.
14
+ }
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["markbates", "Rebecca Nesson"]
12
- s.date = %q{2011-01-04}
13
- s.description = %q{APN on Rails is a Ruby on Rails gem that allows you to
14
- easily add Apple Push Notification (iPhone) support to your Rails application.
15
- }
16
- s.email = %q{tech-team@prx.org}
17
- s.extra_rdoc_files = [
18
- "LICENSE",
19
- "README",
20
- "README.textile"
21
- ]
22
- s.files = [
23
- ".rspec",
24
- ".specification",
25
- "Gemfile",
26
- "Gemfile.lock",
27
- "LICENSE",
28
- "README",
29
- "README.textile",
30
- "Rakefile",
31
- "VERSION",
32
- "apn_on_rails.gemspec",
33
- "autotest/discover.rb",
34
- "generators/apn_migrations_generator.rb",
35
- "generators/templates/apn_migrations/001_create_apn_devices.rb",
36
- "generators/templates/apn_migrations/002_create_apn_notifications.rb",
37
- "generators/templates/apn_migrations/003_alter_apn_devices.rb",
38
- "generators/templates/apn_migrations/004_create_apn_apps.rb",
39
- "generators/templates/apn_migrations/005_create_groups.rb",
40
- "generators/templates/apn_migrations/006_alter_apn_groups.rb",
41
- "generators/templates/apn_migrations/007_create_device_groups.rb",
42
- "generators/templates/apn_migrations/008_create_apn_group_notifications.rb",
43
- "generators/templates/apn_migrations/009_create_pull_notifications.rb",
44
- "generators/templates/apn_migrations/010_alter_apn_notifications.rb",
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
- "lib/apn_on_rails.rb",
48
- "lib/apn_on_rails/apn_on_rails.rb",
49
- "lib/apn_on_rails/app/models/apn/app.rb",
50
- "lib/apn_on_rails/app/models/apn/base.rb",
51
- "lib/apn_on_rails/app/models/apn/device.rb",
52
- "lib/apn_on_rails/app/models/apn/device_grouping.rb",
53
- "lib/apn_on_rails/app/models/apn/group.rb",
54
- "lib/apn_on_rails/app/models/apn/group_notification.rb",
55
- "lib/apn_on_rails/app/models/apn/notification.rb",
56
- "lib/apn_on_rails/app/models/apn/pull_notification.rb",
57
- "lib/apn_on_rails/libs/connection.rb",
58
- "lib/apn_on_rails/libs/feedback.rb",
59
- "lib/apn_on_rails/tasks/apn.rake",
60
- "lib/apn_on_rails/tasks/db.rake",
61
- "lib/apn_on_rails_tasks.rb",
62
- "spec/active_record/setup_ar.rb",
63
- "spec/apn_on_rails/app/models/apn/app_spec.rb",
64
- "spec/apn_on_rails/app/models/apn/device_spec.rb",
65
- "spec/apn_on_rails/app/models/apn/group_notification_spec.rb",
66
- "spec/apn_on_rails/app/models/apn/notification_spec.rb",
67
- "spec/apn_on_rails/app/models/apn/pull_notification_spec.rb",
68
- "spec/apn_on_rails/libs/connection_spec.rb",
69
- "spec/apn_on_rails/libs/feedback_spec.rb",
70
- "spec/extensions/string.rb",
71
- "spec/factories/app_factory.rb",
72
- "spec/factories/device_factory.rb",
73
- "spec/factories/device_grouping_factory.rb",
74
- "spec/factories/group_factory.rb",
75
- "spec/factories/group_notification_factory.rb",
76
- "spec/factories/notification_factory.rb",
77
- "spec/factories/pull_notification_factory.rb",
78
- "spec/fixtures/hexa.bin",
79
- "spec/fixtures/message_for_sending.bin",
80
- "spec/rails_root/config/apple_push_notification_development.pem",
81
- "spec/spec_helper.rb"
82
- ]
83
- s.homepage = %q{http://github.com/PRX/apn_on_rails}
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
84
19
  s.require_paths = ["lib"]
85
- s.rubygems_version = %q{1.3.7}
86
- s.summary = %q{Apple Push Notifications on Rails}
87
- s.test_files = [
88
- "spec/active_record/setup_ar.rb",
89
- "spec/apn_on_rails/app/models/apn/app_spec.rb",
90
- "spec/apn_on_rails/app/models/apn/device_spec.rb",
91
- "spec/apn_on_rails/app/models/apn/group_notification_spec.rb",
92
- "spec/apn_on_rails/app/models/apn/notification_spec.rb",
93
- "spec/apn_on_rails/app/models/apn/pull_notification_spec.rb",
94
- "spec/apn_on_rails/libs/connection_spec.rb",
95
- "spec/apn_on_rails/libs/feedback_spec.rb",
96
- "spec/extensions/string.rb",
97
- "spec/factories/app_factory.rb",
98
- "spec/factories/device_factory.rb",
99
- "spec/factories/device_grouping_factory.rb",
100
- "spec/factories/group_factory.rb",
101
- "spec/factories/group_notification_factory.rb",
102
- "spec/factories/notification_factory.rb",
103
- "spec/factories/pull_notification_factory.rb",
104
- "spec/spec_helper.rb"
105
- ]
106
20
 
107
- if s.respond_to? :specification_version then
108
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
109
- s.specification_version = 3
21
+ s.add_runtime_dependency('configatron')
22
+ s.add_runtime_dependency('activerecord')
23
+ s.add_runtime_dependency('actionpack')
110
24
 
111
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
112
- s.add_runtime_dependency(%q<configatron>, [">= 0"])
113
- s.add_development_dependency(%q<autotest>, [">= 0"])
114
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
115
- s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
116
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
117
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.0"])
118
- s.add_development_dependency(%q<rcov>, [">= 0"])
119
- s.add_development_dependency(%q<actionpack>, ["~> 2.3.0"])
120
- s.add_development_dependency(%q<activerecord>, ["~> 2.3.0"])
121
- else
122
- s.add_dependency(%q<configatron>, [">= 0"])
123
- s.add_dependency(%q<autotest>, [">= 0"])
124
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
125
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
126
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
127
- s.add_dependency(%q<jeweler>, ["~> 1.5.0"])
128
- s.add_dependency(%q<rcov>, [">= 0"])
129
- s.add_dependency(%q<actionpack>, ["~> 2.3.0"])
130
- s.add_dependency(%q<activerecord>, ["~> 2.3.0"])
131
- end
132
- else
133
- s.add_dependency(%q<configatron>, [">= 0"])
134
- s.add_dependency(%q<autotest>, [">= 0"])
135
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
136
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
137
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
138
- s.add_dependency(%q<jeweler>, ["~> 1.5.0"])
139
- s.add_dependency(%q<rcov>, [">= 0"])
140
- s.add_dependency(%q<actionpack>, ["~> 2.3.0"])
141
- s.add_dependency(%q<activerecord>, ["~> 2.3.0"])
142
- end
25
+ s.add_development_dependency('rake')
26
+ s.add_development_dependency('autotest')
27
+ s.add_development_dependency('sqlite3-ruby')
28
+ s.add_development_dependency('rspec')
29
+ s.add_development_dependency('bundler')
30
+ s.add_development_dependency('rcov')
143
31
  end
144
32
 
@@ -1,31 +1,33 @@
1
1
  require 'rails_generator'
2
+ require 'rails/generators/migration'
2
3
  # Generates the migrations necessary for APN on Rails.
3
- # This should be run upon install and upgrade of the
4
+ # This should be run upon install and upgrade of the
4
5
  # APN on Rails gem.
5
- #
6
+ #
6
7
  # $ ruby script/generate apn_migrations
7
8
  class ApnMigrationsGenerator < Rails::Generator::Base
8
-
9
+ desc "Generates the migrations necessary for APN on Rails."
10
+
9
11
  def manifest # :nodoc:
10
12
  record do |m|
11
13
  timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
12
14
  db_migrate_path = File.join('db', 'migrate')
13
-
15
+
14
16
  m.directory(db_migrate_path)
15
-
17
+
16
18
  Dir.glob(File.join(File.dirname(__FILE__), 'templates', 'apn_migrations', '*.rb')).sort.each_with_index do |f, i|
17
19
  f = File.basename(f)
18
20
  f.match(/\d+\_(.+)/)
19
21
  timestamp = timestamp.succ
20
22
  if Dir.glob(File.join(db_migrate_path, "*_#{$1}")).empty?
21
- m.file(File.join('apn_migrations', f),
22
- File.join(db_migrate_path, "#{timestamp}_#{$1}"),
23
+ m.file(File.join('apn_migrations', f),
24
+ File.join(db_migrate_path, "#{timestamp}_#{$1}"),
23
25
  {:collision => :skip})
24
26
  end
25
27
  end
26
-
28
+
27
29
  end # record
28
-
30
+
29
31
  end # manifest
30
-
31
- end # ApnMigrationsGenerator
32
+
33
+ end # ApnMigrationsGenerator
@@ -3,13 +3,13 @@ require 'openssl'
3
3
  require 'configatron'
4
4
 
5
5
  rails_root = File.join(FileUtils.pwd, 'rails_root')
6
- if defined?(RAILS_ROOT)
7
- rails_root = RAILS_ROOT
6
+ if defined?(Rails.root)
7
+ rails_root = Rails.root.to_s
8
8
  end
9
9
 
10
10
  rails_env = 'development'
11
- if defined?(RAILS_ENV)
12
- rails_env = RAILS_ENV
11
+ if defined?(Rails.env)
12
+ rails_env = Rails.env
13
13
  end
14
14
 
15
15
  configatron.apn.set_default(:passphrase, '')
@@ -21,38 +21,38 @@ configatron.apn.feedback.set_default(:port, 2196)
21
21
  if rails_env == 'production'
22
22
  configatron.apn.set_default(:host, 'gateway.push.apple.com')
23
23
  configatron.apn.set_default(:cert, File.join(rails_root, 'config', 'apple_push_notification_production.pem'))
24
-
24
+
25
25
  configatron.apn.feedback.set_default(:host, 'feedback.push.apple.com')
26
26
  configatron.apn.feedback.set_default(:cert, configatron.apn.cert)
27
27
  else
28
28
  configatron.apn.set_default(:host, 'gateway.sandbox.push.apple.com')
29
29
  configatron.apn.set_default(:cert, File.join(rails_root, 'config', 'apple_push_notification_development.pem'))
30
-
30
+
31
31
  configatron.apn.feedback.set_default(:host, 'feedback.sandbox.push.apple.com')
32
32
  configatron.apn.feedback.set_default(:cert, configatron.apn.cert)
33
33
  end
34
34
 
35
35
  module APN # :nodoc:
36
-
36
+
37
37
  module Errors # :nodoc:
38
-
38
+
39
39
  # Raised when a notification message to Apple is longer than 256 bytes.
40
40
  class ExceededMessageSizeError < StandardError
41
-
41
+
42
42
  def initialize(message) # :nodoc:
43
43
  super("The maximum size allowed for a notification payload is 256 bytes: '#{message}'")
44
44
  end
45
-
45
+
46
46
  end
47
-
47
+
48
48
  class MissingCertificateError < StandardError
49
49
  def initialize
50
50
  super("This app has no certificate")
51
51
  end
52
52
  end
53
-
53
+
54
54
  end # Errors
55
-
55
+
56
56
  end # APN
57
57
 
58
58
  base = File.join(File.dirname(__FILE__), 'app', 'models', 'apn', 'base.rb')
@@ -62,20 +62,20 @@ Dir.glob(File.join(File.dirname(__FILE__), 'app', 'models', 'apn', '*.rb')).sort
62
62
  require f
63
63
  end
64
64
 
65
- %w{ models controllers helpers }.each do |dir|
65
+ %w{ models controllers helpers }.each do |dir|
66
66
  path = File.join(File.dirname(__FILE__), 'app', dir)
67
- $LOAD_PATH << path
67
+ $LOAD_PATH << path
68
68
  # puts "Adding #{path}"
69
69
  begin
70
70
  if ActiveSupport::Dependencies.respond_to? :autoload_paths
71
71
  ActiveSupport::Dependencies.autoload_paths << path
72
72
  ActiveSupport::Dependencies.autoload_once_paths.delete(path)
73
73
  else
74
- ActiveSupport::Dependencies.load_paths << path
75
- ActiveSupport::Dependencies.load_once_paths.delete(path)
74
+ ActiveSupport::Dependencies.load_paths << path
75
+ ActiveSupport::Dependencies.load_once_paths.delete(path)
76
76
  end
77
77
  rescue NameError
78
- Dependencies.load_paths << path
79
- Dependencies.load_once_paths.delete(path)
78
+ Dependencies.load_paths << path
79
+ Dependencies.load_once_paths.delete(path)
80
80
  end
81
81
  end
@@ -1,23 +1,23 @@
1
1
  class APN::App < APN::Base
2
-
2
+
3
3
  has_many :groups, :class_name => 'APN::Group', :dependent => :destroy
4
4
  has_many :devices, :class_name => 'APN::Device', :dependent => :destroy
5
5
  has_many :notifications, :through => :devices, :dependent => :destroy
6
6
  has_many :unsent_notifications, :through => :devices
7
7
  has_many :group_notifications, :through => :groups
8
8
  has_many :unsent_group_notifications, :through => :groups
9
-
9
+
10
10
  def cert
11
11
  (RAILS_ENV == 'production' ? apn_prod_cert : apn_dev_cert)
12
12
  end
13
-
13
+
14
14
  # Opens a connection to the Apple APN server and attempts to batch deliver
15
15
  # an Array of group notifications.
16
- #
17
- #
16
+ #
17
+ #
18
18
  # As each APN::GroupNotification is sent the <tt>sent_at</tt> column will be timestamped,
19
19
  # so as to not be sent again.
20
- #
20
+ #
21
21
  def send_notifications
22
22
  if self.cert.nil?
23
23
  raise APN::Errors::MissingCertificateError.new
@@ -25,9 +25,9 @@ class APN::App < APN::Base
25
25
  end
26
26
  APN::App.send_notifications_for_cert(self.cert, self.id)
27
27
  end
28
-
28
+
29
29
  def self.send_notifications
30
- apps = APN::App.all
30
+ apps = APN::App.all
31
31
  apps.each do |app|
32
32
  app.send_notifications
33
33
  end
@@ -36,12 +36,12 @@ class APN::App < APN::Base
36
36
  send_notifications_for_cert(global_cert, nil)
37
37
  end
38
38
  end
39
-
39
+
40
40
  def self.send_notifications_for_cert(the_cert, app_id)
41
41
  # unless self.unsent_notifications.nil? || self.unsent_notifications.empty?
42
42
  if (app_id == nil)
43
43
  conditions = "app_id is null"
44
- else
44
+ else
45
45
  conditions = ["app_id = ?", app_id]
46
46
  end
47
47
  begin
@@ -57,15 +57,15 @@ class APN::App < APN::Base
57
57
  rescue Exception => e
58
58
  log_connection_exception(e)
59
59
  end
60
- # end
60
+ # end
61
61
  end
62
-
62
+
63
63
  def send_group_notifications
64
- if self.cert.nil?
64
+ if self.cert.nil?
65
65
  raise APN::Errors::MissingCertificateError.new
66
66
  return
67
67
  end
68
- unless self.unsent_group_notifications.nil? || self.unsent_group_notifications.empty?
68
+ unless self.unsent_group_notifications.nil? || self.unsent_group_notifications.empty?
69
69
  APN::Connection.open_for_delivery({:cert => self.cert}) do |conn, sock|
70
70
  unsent_group_notifications.each do |gnoty|
71
71
  gnoty.devices.find_each do |device|
@@ -77,9 +77,9 @@ class APN::App < APN::Base
77
77
  end
78
78
  end
79
79
  end
80
-
80
+
81
81
  def send_group_notification(gnoty)
82
- if self.cert.nil?
82
+ if self.cert.nil?
83
83
  raise APN::Errors::MissingCertificateError.new
84
84
  return
85
85
  end
@@ -93,14 +93,14 @@ class APN::App < APN::Base
93
93
  end
94
94
  end
95
95
  end
96
-
96
+
97
97
  def self.send_group_notifications
98
98
  apps = APN::App.all
99
99
  apps.each do |app|
100
100
  app.send_group_notifications
101
101
  end
102
- end
103
-
102
+ end
103
+
104
104
  # Retrieves a list of APN::Device instnces from Apple using
105
105
  # the <tt>devices</tt> method. It then checks to see if the
106
106
  # <tt>last_registered_at</tt> date of each APN::Device is
@@ -108,7 +108,7 @@ class APN::App < APN::Base
108
108
  # accepting notifications then the device is deleted. Otherwise
109
109
  # it is assumed that the application has been re-installed
110
110
  # and is available for notifications.
111
- #
111
+ #
112
112
  # This can be run from the following Rake task:
113
113
  # $ rake apn:feedback:process
114
114
  def process_devices
@@ -118,7 +118,7 @@ class APN::App < APN::Base
118
118
  end
119
119
  APN::App.process_devices_for_cert(self.cert)
120
120
  end # process_devices
121
-
121
+
122
122
  def self.process_devices
123
123
  apps = APN::App.all
124
124
  apps.each do |app|
@@ -129,23 +129,24 @@ class APN::App < APN::Base
129
129
  APN::App.process_devices_for_cert(global_cert)
130
130
  end
131
131
  end
132
-
132
+
133
133
  def self.process_devices_for_cert(the_cert)
134
134
  puts "in APN::App.process_devices_for_cert"
135
135
  APN::Feedback.devices(the_cert).each do |device|
136
136
  if device.last_registered_at < device.feedback_at
137
137
  puts "device #{device.id} -> #{device.last_registered_at} < #{device.feedback_at}"
138
138
  device.destroy
139
- else
139
+ else
140
140
  puts "device #{device.id} -> #{device.last_registered_at} not < #{device.feedback_at}"
141
141
  end
142
- end
142
+ end
143
143
  end
144
-
145
-
144
+
145
+
146
146
  protected
147
147
  def log_connection_exception(ex)
148
- puts ex.message
148
+ STDERR.puts ex.message
149
+ raise ex
149
150
  end
150
-
151
- end
151
+
152
+ end
@@ -8,6 +8,10 @@ This task no longer exists. Please generate the migrations like this:
8
8
 
9
9
  $ ruby script/generate apn_migrations
10
10
 
11
+ or
12
+
13
+ $ rails g apn_on_rails:install
14
+
11
15
  Then just run the migrations like you would normally:
12
16
 
13
17
  $ rake db:migrate
@@ -0,0 +1,3 @@
1
+ module ApnOnRails
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates the migrations necessary for APN on Rails
3
+
4
+ Usage:
5
+ rails g apn:apn_migrations
6
+
7
+ Examples:
8
+ rails g apn:apn_migrations
@@ -0,0 +1,38 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ # Generates the migrations necessary for APN on Rails.
5
+ # This should be run upon install and upgrade of the
6
+ # APN on Rails gem.
7
+ #
8
+ # $ rails generate apn:apn_migrations
9
+ module ApnOnRails
10
+ module Generators
11
+
12
+ class InstallGenerator < Rails::Generators::Base
13
+ include Rails::Generators::Migration
14
+ source_root(File.expand_path(File.join(File.dirname(__FILE__), 'templates')))
15
+ desc "add the migrations"
16
+
17
+ def self.next_migration_number(path)
18
+ unless @prev_migration_nr
19
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
20
+ else
21
+ @prev_migration_nr += 1
22
+ end
23
+ @prev_migration_nr.to_s
24
+ end
25
+
26
+ def create_migrations
27
+ Dir.glob(File.join(self.class.source_root, '*.rb')).sort.each_with_index do |f, i|
28
+ source = File.basename(f)
29
+ source.match(/\d+\_(.+)/)
30
+ destination = "db/migrate/#{$1}"
31
+ migration_template source, destination
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ class CreateApnDevices < ActiveRecord::Migration # :nodoc:
2
+ def self.up
3
+ create_table :apn_devices do |t|
4
+ t.text :token, :size => 71, :null => false
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :apn_devices
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ class CreateApnNotifications < ActiveRecord::Migration # :nodoc:
2
+
3
+ def self.up
4
+
5
+ create_table :apn_notifications do |t|
6
+ t.integer :device_id, :null => false
7
+ t.integer :errors_nb, :default => 0 # used for storing errors from apple feedbacks
8
+ t.string :device_language, :size => 5 # if you don't want to send localized strings
9
+ t.string :sound
10
+ t.string :alert, :size => 150
11
+ t.integer :badge
12
+ t.datetime :sent_at
13
+ t.timestamps
14
+ end
15
+
16
+ add_index :apn_notifications, :device_id
17
+ end
18
+
19
+ def self.down
20
+ drop_table :apn_notifications
21
+ end
22
+
23
+ end
@@ -0,0 +1,25 @@
1
+ class AlterApnDevices < ActiveRecord::Migration # :nodoc:
2
+
3
+ module APN # :nodoc:
4
+ class Device < ActiveRecord::Base # :nodoc:
5
+ set_table_name 'apn_devices'
6
+ end
7
+ end
8
+
9
+ def self.up
10
+ add_column :apn_devices, :last_registered_at, :datetime
11
+
12
+ APN::Device.all.each do |device|
13
+ device.last_registered_at = device.created_at
14
+ device.save!
15
+ end
16
+ change_column :apn_devices, :token, :string, :size => 100, :null => false
17
+ add_index :apn_devices, :token, :unique => true
18
+ end
19
+
20
+ def self.down
21
+ change_column :apn_devices, :token, :string
22
+ remove_index :apn_devices, :column => :token
23
+ remove_column :apn_devices, :last_registered_at
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ class CreateApnApps < ActiveRecord::Migration # :nodoc:
2
+ def self.up
3
+ create_table :apn_apps do |t|
4
+ t.text :apn_dev_cert
5
+ t.text :apn_prod_cert
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_column :apn_devices, :app_id, :integer
11
+
12
+ end
13
+
14
+ def self.down
15
+ drop_table :apn_apps
16
+ remove_column :apn_devices, :app_id
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ class CreateGroups < ActiveRecord::Migration # :nodoc:
2
+ def self.up
3
+ create_table :apn_groups do |t|
4
+ t.column :name, :string
5
+
6
+ t.timestamps
7
+ end
8
+
9
+ create_table :apn_devices_apn_groups, :id => false do |t|
10
+ t.column :group_id, :integer
11
+ t.column :device_id, :integer
12
+ end
13
+
14
+ add_index :apn_devices_apn_groups, [:group_id, :device_id]
15
+ add_index :apn_devices_apn_groups, :device_id
16
+ add_index :apn_devices_apn_groups, :group_id
17
+ end
18
+
19
+ def self.down
20
+ drop_table :apn_groups
21
+ drop_table :apn_devices_apn_groups
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ class AlterApnGroups < ActiveRecord::Migration # :nodoc:
2
+
3
+ def self.up
4
+ add_column :apn_groups, :app_id, :integer
5
+ end
6
+
7
+ def self.down
8
+ remove_column :apn_groups, :app_id
9
+ end
10
+
11
+ end
@@ -0,0 +1,27 @@
1
+ class CreateDeviceGroups < ActiveRecord::Migration # :nodoc:
2
+ def self.up
3
+ drop_table :apn_devices_apn_groups
4
+
5
+ create_table :apn_device_groupings do |t|
6
+ t.column :group_id, :integer
7
+ t.column :device_id, :integer
8
+ end
9
+
10
+ add_index :apn_device_groupings, [:group_id, :device_id]
11
+ add_index :apn_device_groupings, :device_id
12
+ add_index :apn_device_groupings, :group_id
13
+ end
14
+
15
+ def self.down
16
+ drop_table :apn_device_groupings
17
+
18
+ create_table :apn_devices_apn_groups, :id => false do |t|
19
+ t.column :group_id, :integer
20
+ t.column :device_id, :integer
21
+ end
22
+
23
+ add_index :apn_devices_apn_groups, [:group_id, :device_id]
24
+ add_index :apn_devices_apn_groups, :device_id
25
+ add_index :apn_devices_apn_groups, :group_id
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ class CreateApnGroupNotifications < ActiveRecord::Migration # :nodoc:
2
+
3
+ def self.up
4
+
5
+ create_table :apn_group_notifications do |t|
6
+ t.integer :group_id, :null => false
7
+ t.string :device_language, :size => 5 # if you don't want to send localized strings
8
+ t.string :sound
9
+ t.string :alert, :size => 150
10
+ t.integer :badge
11
+ t.text :custom_properties
12
+ t.datetime :sent_at
13
+ t.timestamps
14
+ end
15
+
16
+ add_index :apn_group_notifications, :group_id
17
+ end
18
+
19
+ def self.down
20
+ drop_table :apn_group_notifications
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+ class CreatePullNotifications < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :apn_pull_notifications do |t|
4
+ t.integer :app_id
5
+ t.string :title
6
+ t.string :content
7
+ t.string :link
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :apn_pull_notifications
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ class AlterApnNotifications < ActiveRecord::Migration # :nodoc:
2
+
3
+ module APN # :nodoc:
4
+ class Notification < ActiveRecord::Base # :nodoc:
5
+ set_table_name 'apn_notifications'
6
+ end
7
+ end
8
+
9
+ def self.up
10
+ unless APN::Notification.column_names.include?("custom_properties")
11
+ add_column :apn_notifications, :custom_properties, :text
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ if APN::Notification.column_names.include?("custom_properties")
17
+ remove_column :apn_notifications, :custom_properties
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,11 @@
1
+ class MakeDeviceTokenIndexNonunique < ActiveRecord::Migration
2
+ def self.up
3
+ remove_index :apn_devices, :column => :token
4
+ add_index :apn_devices, :token
5
+ end
6
+
7
+ def self.down
8
+ remove_index :apn_devices, :column => :token
9
+ add_index :apn_devices, :token, :unique => true
10
+ end
11
+ end
@@ -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
metadata CHANGED
@@ -2,12 +2,12 @@
2
2
  name: apn_on_rails
3
3
  version: !ruby/object:Gem::Version
4
4
  hash: 11
5
- prerelease: false
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 2
10
- version: 0.4.2
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - markbates
@@ -16,12 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-01-04 00:00:00 -05:00
20
- default_executable:
19
+ date: 2012-01-27 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
- name: configatron
24
22
  prerelease: false
23
+ type: :runtime
25
24
  requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
@@ -31,11 +30,11 @@ dependencies:
31
30
  segments:
32
31
  - 0
33
32
  version: "0"
34
- type: :runtime
33
+ name: configatron
35
34
  version_requirements: *id001
36
35
  - !ruby/object:Gem::Dependency
37
- name: autotest
38
36
  prerelease: false
37
+ type: :runtime
39
38
  requirement: &id002 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
@@ -45,11 +44,11 @@ dependencies:
45
44
  segments:
46
45
  - 0
47
46
  version: "0"
48
- type: :development
47
+ name: activerecord
49
48
  version_requirements: *id002
50
49
  - !ruby/object:Gem::Dependency
51
- name: sqlite3-ruby
52
50
  prerelease: false
51
+ type: :runtime
53
52
  requirement: &id003 !ruby/object:Gem::Requirement
54
53
  none: false
55
54
  requirements:
@@ -59,59 +58,53 @@ dependencies:
59
58
  segments:
60
59
  - 0
61
60
  version: "0"
62
- type: :development
61
+ name: actionpack
63
62
  version_requirements: *id003
64
63
  - !ruby/object:Gem::Dependency
65
- name: rspec
66
64
  prerelease: false
65
+ type: :development
67
66
  requirement: &id004 !ruby/object:Gem::Requirement
68
67
  none: false
69
68
  requirements:
70
69
  - - ">="
71
70
  - !ruby/object:Gem::Version
72
- hash: 15
71
+ hash: 3
73
72
  segments:
74
- - 2
75
73
  - 0
76
- - 0
77
- version: 2.0.0
78
- type: :development
74
+ version: "0"
75
+ name: rake
79
76
  version_requirements: *id004
80
77
  - !ruby/object:Gem::Dependency
81
- name: bundler
82
78
  prerelease: false
79
+ type: :development
83
80
  requirement: &id005 !ruby/object:Gem::Requirement
84
81
  none: false
85
82
  requirements:
86
- - - ~>
83
+ - - ">="
87
84
  - !ruby/object:Gem::Version
88
- hash: 23
85
+ hash: 3
89
86
  segments:
90
- - 1
91
87
  - 0
92
- - 0
93
- version: 1.0.0
94
- type: :development
88
+ version: "0"
89
+ name: autotest
95
90
  version_requirements: *id005
96
91
  - !ruby/object:Gem::Dependency
97
- name: jeweler
98
92
  prerelease: false
93
+ type: :development
99
94
  requirement: &id006 !ruby/object:Gem::Requirement
100
95
  none: false
101
96
  requirements:
102
- - - ~>
97
+ - - ">="
103
98
  - !ruby/object:Gem::Version
104
99
  hash: 3
105
100
  segments:
106
- - 1
107
- - 5
108
101
  - 0
109
- version: 1.5.0
110
- type: :development
102
+ version: "0"
103
+ name: sqlite3-ruby
111
104
  version_requirements: *id006
112
105
  - !ruby/object:Gem::Dependency
113
- name: rcov
114
106
  prerelease: false
107
+ type: :development
115
108
  requirement: &id007 !ruby/object:Gem::Requirement
116
109
  none: false
117
110
  requirements:
@@ -121,54 +114,46 @@ dependencies:
121
114
  segments:
122
115
  - 0
123
116
  version: "0"
124
- type: :development
117
+ name: rspec
125
118
  version_requirements: *id007
126
119
  - !ruby/object:Gem::Dependency
127
- name: actionpack
128
120
  prerelease: false
121
+ type: :development
129
122
  requirement: &id008 !ruby/object:Gem::Requirement
130
123
  none: false
131
124
  requirements:
132
- - - ~>
125
+ - - ">="
133
126
  - !ruby/object:Gem::Version
134
127
  hash: 3
135
128
  segments:
136
- - 2
137
- - 3
138
129
  - 0
139
- version: 2.3.0
140
- type: :development
130
+ version: "0"
131
+ name: bundler
141
132
  version_requirements: *id008
142
133
  - !ruby/object:Gem::Dependency
143
- name: activerecord
144
134
  prerelease: false
135
+ type: :development
145
136
  requirement: &id009 !ruby/object:Gem::Requirement
146
137
  none: false
147
138
  requirements:
148
- - - ~>
139
+ - - ">="
149
140
  - !ruby/object:Gem::Version
150
141
  hash: 3
151
142
  segments:
152
- - 2
153
- - 3
154
143
  - 0
155
- version: 2.3.0
156
- type: :development
144
+ version: "0"
145
+ name: rcov
157
146
  version_requirements: *id009
158
- description: |
159
- APN on Rails is a Ruby on Rails gem that allows you to
160
- easily add Apple Push Notification (iPhone) support to your Rails application.
161
-
147
+ description: "APN on Rails is a Ruby on Rails gem that allows you to\n easily add Apple Push Notification (iPhone) support to your Rails application.\n "
162
148
  email: tech-team@prx.org
163
149
  executables: []
164
150
 
165
151
  extensions: []
166
152
 
167
- extra_rdoc_files:
168
- - LICENSE
169
- - README
170
- - README.textile
153
+ extra_rdoc_files: []
154
+
171
155
  files:
156
+ - .gitignore
172
157
  - .rspec
173
158
  - .specification
174
159
  - Gemfile
@@ -207,7 +192,22 @@ files:
207
192
  - lib/apn_on_rails/libs/feedback.rb
208
193
  - lib/apn_on_rails/tasks/apn.rake
209
194
  - lib/apn_on_rails/tasks/db.rake
195
+ - lib/apn_on_rails/version.rb
210
196
  - lib/apn_on_rails_tasks.rb
197
+ - lib/generators/apn_on_rails/install/USAGE
198
+ - lib/generators/apn_on_rails/install/install_generator.rb
199
+ - lib/generators/apn_on_rails/install/templates/001_create_apn_devices.rb
200
+ - lib/generators/apn_on_rails/install/templates/002_create_apn_notifications.rb
201
+ - lib/generators/apn_on_rails/install/templates/003_alter_apn_devices.rb
202
+ - lib/generators/apn_on_rails/install/templates/004_create_apn_apps.rb
203
+ - lib/generators/apn_on_rails/install/templates/005_create_groups.rb
204
+ - lib/generators/apn_on_rails/install/templates/006_alter_apn_groups.rb
205
+ - lib/generators/apn_on_rails/install/templates/007_create_device_groups.rb
206
+ - lib/generators/apn_on_rails/install/templates/008_create_apn_group_notifications.rb
207
+ - lib/generators/apn_on_rails/install/templates/009_create_pull_notifications.rb
208
+ - lib/generators/apn_on_rails/install/templates/010_alter_apn_notifications.rb
209
+ - lib/generators/apn_on_rails/install/templates/011_make_device_token_index_nonunique.rb
210
+ - lib/generators/apn_on_rails/install/templates/012_add_launch_notification_to_apn_pull_notifications.rb
211
211
  - spec/active_record/setup_ar.rb
212
212
  - spec/apn_on_rails/app/models/apn/app_spec.rb
213
213
  - spec/apn_on_rails/app/models/apn/device_spec.rb
@@ -228,7 +228,6 @@ files:
228
228
  - spec/fixtures/message_for_sending.bin
229
229
  - spec/rails_root/config/apple_push_notification_development.pem
230
230
  - spec/spec_helper.rb
231
- has_rdoc: true
232
231
  homepage: http://github.com/PRX/apn_on_rails
233
232
  licenses: []
234
233
 
@@ -258,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
257
  requirements: []
259
258
 
260
259
  rubyforge_project:
261
- rubygems_version: 1.3.7
260
+ rubygems_version: 1.8.10
262
261
  signing_key:
263
262
  specification_version: 3
264
263
  summary: Apple Push Notifications on Rails
@@ -279,4 +278,7 @@ test_files:
279
278
  - spec/factories/group_notification_factory.rb
280
279
  - spec/factories/notification_factory.rb
281
280
  - spec/factories/pull_notification_factory.rb
281
+ - spec/fixtures/hexa.bin
282
+ - spec/fixtures/message_for_sending.bin
283
+ - spec/rails_root/config/apple_push_notification_development.pem
282
284
  - spec/spec_helper.rb