apn_sender 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,7 +4,7 @@ Need to send background notifications to an iPhone application over a <em>persis
4
4
 
5
5
  == The Story
6
6
 
7
- So you're building the server component of an iPhone application in Ruby. And you want to send background notifications through the Apple Push Notification servers, which doesn't seem too bad at first. But then you read in the {Apple Documentation}[https://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/WhatAreRemoteNotif/WhatAreRemoteNotif.html#//apple_ref/doc/uid/TP40008194-CH102-SW7] that Apple's servers may treat non-persistent connections as a Denial of Service attack, and you realize that Rails has no easy way to maintain a persistent connection internally, and things started looking more complicated.
7
+ So you're building the server component of an iPhone application in Ruby. And you want to send background notifications through the Apple Push Notification servers, which doesn't seem too bad at first. But then you read in the {Apple Documentation}[https://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/WhatAreRemoteNotif/WhatAreRemoteNotif.html#//apple_ref/doc/uid/TP40008194-CH102-SW7] that Apple's servers may treat non-persistent connections as a Denial of Service attack, and you realize that Rails has no easy way to maintain a persistent connection internally, and things start looking more complicated.
8
8
 
9
9
  The apn_sender gem includes a background daemon which processes background messages from your application and sends them along to Apple <em>over a single, persistent socket</em>. It also includes the ability to query the Feedback service, helper methods for enqueueing your jobs, and a sample monit config to make sure the background worker is around when you need it.
10
10
 
@@ -15,7 +15,7 @@ Yup. There's some great code out there already, but we didn't like the idea of
15
15
  == Current Status
16
16
 
17
17
  This gem has been in production use since early May, 2010. There are no guarantees of complete functionality, of course, but it's working for us. :)
18
-
18
+ ** UPDATE: our site is now defunct (for completely-unrelated reasons), but the many forks and watchers make me think something's going right. **
19
19
 
20
20
  == Usage
21
21
 
@@ -85,7 +85,7 @@ Forcing a reconnect is as easy as calling either method with the single paramete
85
85
 
86
86
  ==== Warning: No really, check Apple's Feedback Service occasionally
87
87
 
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)).
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 monitor 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
90
  Just for the record, this is essentially what you want to have whenever run periodically for you:
91
91
 
@@ -115,12 +115,16 @@ There's also an included sample <code>apn_sender.monitrc</code> file in the <cod
115
115
 
116
116
  APN is built on top of {Resque}[http://github.com/defunkt/resque] (an awesome {Redis}[http://code.google.com/p/redis/]-based background runner similar to {delayed_job}[http://github.com/collectiveidea/delayed_job]). Read through the {Resque README}[http://github.com/defunkt/resque#readme] to get a feel for what's going on, follow the installation instructions there, and then run:
117
117
 
118
- $ sudo gem install apn_sender
118
+ $ gem install apn_sender
119
119
 
120
- In your Rails app, add
120
+ In your Rails app, add (2.3.x):
121
121
 
122
122
  config.gem 'apn_sender', :lib => 'apn'
123
123
 
124
+ or (3.x) to your Gemfile:
125
+
126
+ gem 'apn_sender', :require => 'apn'
127
+
124
128
  To add a few useful rake tasks for running workers, add the following line to your Rakefile:
125
129
 
126
130
  require 'apn/tasks'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
data/apn_sender.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{apn_sender}
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
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{2011-04-22}
12
+ s.date = %q{2011-05-15}
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 = [
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  ]
45
45
  s.homepage = %q{http://github.com/kdonovan/apple_push_notification}
46
46
  s.require_paths = ["lib"]
47
- s.rubygems_version = %q{1.6.2}
47
+ s.rubygems_version = %q{1.5.2}
48
48
  s.summary = %q{Resque-based background worker to send Apple Push Notifications over a persistent TCP socket.}
49
49
  s.test_files = [
50
50
  "test/helper.rb",
@@ -29,17 +29,17 @@ module APN
29
29
 
30
30
  # Default to Rails or Merg logger, if available
31
31
  def setup_logger
32
- @logger = if defined?(Merb::Logger)
33
- Merb.logger
34
- elsif defined?(RAILS_DEFAULT_LOGGER)
35
- RAILS_DEFAULT_LOGGER
32
+ @logger = if defined?(::Merb::Logger)
33
+ ::Merb.logger
34
+ elsif defined?(::Rails.logger)
35
+ ::Rails.logger
36
36
  end
37
37
  end
38
38
 
39
39
  # Log message to any logger provided by the user (e.g. the Rails logger).
40
40
  # Accepts +log_level+, +message+, since that seems to make the most sense,
41
41
  # and just +message+, to be compatible with Resque's log method and to enable
42
- # sending verbose and very_verbose worker messages to e.g. the rails logger.#
42
+ # sending verbose and very_verbose worker messages to e.g. the rails logger.
43
43
  #
44
44
  # Perhaps a method definition of +message, +level+ would make more sense, but
45
45
  # that's also the complete opposite of what anyone comming from rails would expect.
@@ -52,7 +52,8 @@ module APN
52
52
  self.logger.send(level, "#{Time.now}: #{message}")
53
53
  end
54
54
 
55
- # Log the message first, to ensure it reports what went wrong if in daemon mode. Then die, because something went horribly wrong.
55
+ # Log the message first, to ensure it reports what went wrong if in daemon mode.
56
+ # Then die, because something went horribly wrong.
56
57
  def log_and_die(msg)
57
58
  log(:fatal, msg)
58
59
  raise msg
@@ -64,9 +65,10 @@ module APN
64
65
 
65
66
  # Get a fix on the .pem certificate we'll be using for SSL
66
67
  def setup_paths
67
- # Set option defaults
68
- @opts[:cert_path] ||= File.join(File.expand_path(RAILS_ROOT), "config", "certs") if defined?(RAILS_ROOT)
69
- @opts[:environment] ||= RAILS_ENV if defined?(RAILS_ENV)
68
+ # Set option defaults. RAILS_ROOT is still here not from Rails, but to handle passing in root from sender_daemon
69
+ @opts[:root_path] ||= defined?(::Rails.root) ? ::Rails.root.to_s : (defined?(RAILS_ROOT) ? RAILS_ROOT : '/')
70
+ @opts[:cert_path] ||= File.join(File.expand_path(@opts[:root_path]), "config", "certs")
71
+ @opts[:environment] ||= ::Rails.env if defined?(::Rails.env)
70
72
 
71
73
  log_and_die("Missing certificate path. Please specify :cert_path when initializing class.") unless @opts[:cert_path]
72
74
 
@@ -114,4 +116,4 @@ module APN
114
116
 
115
117
  end
116
118
  end
117
- end
119
+ end
data/lib/apn/sender.rb CHANGED
@@ -7,11 +7,13 @@ module APN
7
7
  # which they apparently view as a DOS attack.
8
8
  #
9
9
  # Accepts <code>:environment</code> (production vs anything else) and <code>:cert_path</code> options on initialization. If called in a
10
- # Rails context, will default to RAILS_ENV and RAILS_ROOT/config/certs. :environment will default to development.
10
+ # Rails context, <code>:cert_path</code> will default to "#{Rails.root}/config/certs" and <code>:environment</code>'s default will be set
11
+ # from Rails.env (production if Rails.env is production, development for any other Rails.env value).
12
+ #
11
13
  # APN::Sender expects two files to exist in the specified <code>:cert_path</code> directory:
12
14
  # <code>apn_production.pem</code> and <code>apn_development.pem</code>.
13
15
  #
14
- # If a socket error is encountered, will teardown the connection and retry again twice before admitting defeat.
16
+ # If a socket error is encountered, it will teardown the connection and retry again twice before admitting defeat.
15
17
  class Sender < ::Resque::Worker
16
18
  include APN::Connection::Base
17
19
  TIMES_TO_RETRY_SOCKET_ERROR = 2
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apn_sender
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kali Donovan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-22 00:00:00 -06:00
18
+ date: 2011-05-15 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  requirements: []
111
111
 
112
112
  rubyforge_project:
113
- rubygems_version: 1.6.2
113
+ rubygems_version: 1.5.2
114
114
  signing_key:
115
115
  specification_version: 3
116
116
  summary: Resque-based background worker to send Apple Push Notifications over a persistent TCP socket.