apn_sender 1.0.2 → 1.0.3

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.rdoc CHANGED
@@ -87,6 +87,21 @@ Forcing a reconnect is as easy as calling either method with the single paramete
87
87
 
88
88
  If you're sending notifications, you should definitely call one of the <code>receive</code> methods periodically, as Apple's policies require it and they apparently monitors providers for compliance. I'd definitely recommend throwing together a quick rake task to take care of this for you (the {whenever library}[http://github.com/javan/whenever] provides a nice wrapper around scheduling tasks to run at certain times (for systems with cron enabled)).
89
89
 
90
+ Just for the record, this is essentially what you want to have whenever run periodically for you:
91
+
92
+ def self.clear_uninstalled_applications
93
+ feedback_data = APN::Feedback.new(:environment => :production).data
94
+
95
+ feedback_data.each do |item|
96
+ user = User.find_by_iphone_token( item.token )
97
+
98
+ if user.iphone_token_updated_at && user.iphone_token_updated_at > item.timestamp
99
+ return true # App has been reregistered since Apple determined it'd been uninstalled
100
+ else
101
+ user.update_attributes(:iphone_token => nil, :iphone_token_updated_at => Time.now)
102
+ end
103
+ end
104
+ end
90
105
 
91
106
 
92
107
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
data/apn_sender.gemspec CHANGED
@@ -1,63 +1,60 @@
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_sender}
8
- s.version = "1.0.2"
8
+ s.version = "1.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kali Donovan"]
12
- s.date = %q{2010-05-16}
12
+ s.date = %q{2011-04-22}
13
13
  s.description = %q{Resque-based background worker to send Apple Push Notifications over a persistent TCP socket. Includes Resque tweaks to allow persistent sockets between jobs, helper methods for enqueueing APN notifications, and a background daemon to send them.}
14
14
  s.email = %q{kali.donovan@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "apn_sender.gemspec",
27
- "contrib/apn_sender.monitrc",
28
- "generators/apn_sender_generator.rb",
29
- "generators/templates/script",
30
- "init.rb",
31
- "lib/apn.rb",
32
- "lib/apn/connection/base.rb",
33
- "lib/apn/feedback.rb",
34
- "lib/apn/notification.rb",
35
- "lib/apn/notification_job.rb",
36
- "lib/apn/queue_manager.rb",
37
- "lib/apn/queue_name.rb",
38
- "lib/apn/sender.rb",
39
- "lib/apn/sender_daemon.rb",
40
- "lib/apn/tasks.rb",
41
- "lib/resque/hooks/before_unregister_worker.rb",
42
- "rails/init.rb",
43
- "test/helper.rb",
44
- "test/test_apple_push_notification.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "apn_sender.gemspec",
26
+ "contrib/apn_sender.monitrc",
27
+ "generators/apn_sender_generator.rb",
28
+ "generators/templates/script",
29
+ "init.rb",
30
+ "lib/apn.rb",
31
+ "lib/apn/connection/base.rb",
32
+ "lib/apn/feedback.rb",
33
+ "lib/apn/notification.rb",
34
+ "lib/apn/notification_job.rb",
35
+ "lib/apn/queue_manager.rb",
36
+ "lib/apn/queue_name.rb",
37
+ "lib/apn/sender.rb",
38
+ "lib/apn/sender_daemon.rb",
39
+ "lib/apn/tasks.rb",
40
+ "lib/resque/hooks/before_unregister_worker.rb",
41
+ "rails/init.rb",
42
+ "test/helper.rb",
43
+ "test/test_apple_push_notification.rb"
45
44
  ]
46
45
  s.homepage = %q{http://github.com/kdonovan/apple_push_notification}
47
- s.rdoc_options = ["--charset=UTF-8"]
48
46
  s.require_paths = ["lib"]
49
- s.rubygems_version = %q{1.3.6}
47
+ s.rubygems_version = %q{1.6.2}
50
48
  s.summary = %q{Resque-based background worker to send Apple Push Notifications over a persistent TCP socket.}
51
49
  s.test_files = [
52
50
  "test/helper.rb",
53
- "test/test_apple_push_notification.rb"
51
+ "test/test_apple_push_notification.rb"
54
52
  ]
55
53
 
56
54
  if s.respond_to? :specification_version then
57
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
55
  s.specification_version = 3
59
56
 
60
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
58
  s.add_runtime_dependency(%q<resque>, [">= 0"])
62
59
  s.add_runtime_dependency(%q<resque-access_worker_from_job>, [">= 0"])
63
60
  else
@@ -18,4 +18,5 @@ check process apn_sender
18
18
  group apn_sender
19
19
  start program = "/var/www/#{app_name}/current/script/apn_sender --environment=production --verbose start"
20
20
  stop program = "/var/www/{#app_name}/current/script/apn_sender --environment=production --verbose stop"
21
+ if 2 restarts within 3 cycles then timeout
21
22
  depends_on redis
data/lib/apn.rb CHANGED
@@ -2,6 +2,7 @@ require 'resque'
2
2
  require 'resque/plugins/access_worker_from_job'
3
3
  require 'resque/hooks/before_unregister_worker'
4
4
  require 'json'
5
+ require 'active_support'
5
6
 
6
7
  require 'apn/queue_name'
7
8
  require 'apn/queue_manager'
@@ -67,7 +67,7 @@ module APN
67
67
  hsh['aps']['sound'] = sound.is_a?(TrueClass) ? 'default' : sound.to_s
68
68
  end
69
69
  hsh.merge!(opts)
70
- hsh.to_json
70
+ ActiveSupport::JSON::encode(hsh)
71
71
  end
72
72
 
73
73
  # Symbolize keys, using ActiveSupport if available
@@ -5,6 +5,7 @@
5
5
  module APN
6
6
  # Enqueues a notification to be sent in the background via the persistent TCP socket, assuming apn_sender is running (or will be soon)
7
7
  def self.notify(token, opts = {})
8
+ token = token.to_s.gsub(/\W/, '')
8
9
  APN::QueueManager.enqueue(APN::NotificationJob, token, opts)
9
10
  end
10
11
 
data/lib/apn/sender.rb CHANGED
@@ -45,33 +45,3 @@ module APN
45
45
  end
46
46
 
47
47
  end
48
-
49
-
50
- __END__
51
-
52
- # irb -r 'lib/apple_push_notification'
53
-
54
- ## To enqueue test job
55
- k = 'ceecdc18 ef17b2d0 745475e0 0a6cd5bf 54534184 ac2649eb 40873c81 ae76dbe8'
56
- c = '0f58e3e2 77237b8f f8213851 c835dee0 376b7a31 9e0484f7 06fe3035 7c5dda2f'
57
- APN.notify k, 'Resque Test'
58
-
59
- # If you need to really force quit some screwed up workers
60
- Resque.workers.map{|w| Resque.redis.srem(:workers, w)}
61
-
62
- # To run worker from rake task
63
- CERT_PATH=/Users/kali/Code/insurrection/certs/ ENVIRONMENT=production rake apn:work
64
-
65
- # To run worker from IRB
66
- Resque.workers.map(&:unregister_worker)
67
- require 'ruby-debug'
68
- worker = APN::Sender.new(:cert_path => '/Users/kali/Code/insurrection/certs/', :environment => :production)
69
- worker.very_verbose = true
70
- worker.work(5)
71
-
72
- # To run worker as daemon
73
- args = ['--environment=production', '--cert-path=/Users/kali/Code/insurrection/certs/']
74
- APN::SenderDaemon.new(args).daemonize
75
-
76
- # To run daemonized version in Rails app
77
- ./script/apn_sender --environment=production start
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apn_sender
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 17
5
+ prerelease:
5
6
  segments:
6
7
  - 1
7
8
  - 0
8
- - 2
9
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Kali Donovan
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-16 00:00:00 -07:00
18
+ date: 2011-04-22 00:00:00 -06:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: resque
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -33,9 +36,11 @@ dependencies:
33
36
  name: resque-access_worker_from_job
34
37
  prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
36
40
  requirements:
37
41
  - - ">="
38
42
  - !ruby/object:Gem::Version
43
+ hash: 3
39
44
  segments:
40
45
  - 0
41
46
  version: "0"
@@ -52,7 +57,6 @@ extra_rdoc_files:
52
57
  - README.rdoc
53
58
  files:
54
59
  - .document
55
- - .gitignore
56
60
  - LICENSE
57
61
  - README.rdoc
58
62
  - Rakefile
@@ -81,28 +85,32 @@ homepage: http://github.com/kdonovan/apple_push_notification
81
85
  licenses: []
82
86
 
83
87
  post_install_message:
84
- rdoc_options:
85
- - --charset=UTF-8
88
+ rdoc_options: []
89
+
86
90
  require_paths:
87
91
  - lib
88
92
  required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
89
94
  requirements:
90
95
  - - ">="
91
96
  - !ruby/object:Gem::Version
97
+ hash: 3
92
98
  segments:
93
99
  - 0
94
100
  version: "0"
95
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
96
103
  requirements:
97
104
  - - ">="
98
105
  - !ruby/object:Gem::Version
106
+ hash: 3
99
107
  segments:
100
108
  - 0
101
109
  version: "0"
102
110
  requirements: []
103
111
 
104
112
  rubyforge_project:
105
- rubygems_version: 1.3.6
113
+ rubygems_version: 1.6.2
106
114
  signing_key:
107
115
  specification_version: 3
108
116
  summary: Resque-based background worker to send Apple Push Notifications over a persistent TCP socket.
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC