apn_sender 2.0.1 → 2.0.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.
@@ -1,4 +1,11 @@
1
1
  # Version 2.0
2
+ ## 2.0.2
3
+ - Add default file so we dont need to require 'apn' anymore
4
+ - Change backend switch:
5
+ Use simple backend per default, also allow changes.
6
+ Now you can change the backend using:
7
+ APN.backend = :sidekiq
8
+
2
9
  ## 2.0.1
3
10
  - Use bytesize to truncate alert when necessary
4
11
  - Better calculation on payload size. (botvinik)
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Code Climate](https://codeclimate.com/github/arthurnn/apn_sender.png)](https://codeclimate.com/github/arthurnn/apn_sender)
2
- [![Build Status](https://travis-ci.org/arthurnn/apn_sender.png)](https://travis-ci.org/arthurnn/apn_sender)
1
+ [![Code Climate](http://img.shields.io/codeclimate/github/arthurnn/apn_sender.svg)](https://codeclimate.com/github/arthurnn/apn_sender)
2
+ [![Build Status](https://travis-ci.org/arthurnn/apn_sender.svg?branch=master)](https://travis-ci.org/arthurnn/apn_sender)
3
3
 
4
4
  ## Synopsis
5
5
 
@@ -56,9 +56,11 @@ APN.host = 'apple host (on development sandbox url is used by default)'
56
56
  APN.password = 'certificate_password'
57
57
  APN.pool_size = 1 # number of connections on the pool
58
58
  APN.pool_timeout = 5 # timeout in seconds for connection pool
59
+ APN.logger = Logger.new(File.join(Rails.root, 'log', 'apn_sender.log'))
59
60
  ```
60
61
 
61
62
  Check ```logs/apn_sender.log``` for debugging output. In addition to logging any major errors there, apn_sender hooks into the Resque::Worker logging to display any verbose or very_verbose worker output in apn_sender.log file as well.
63
+ On latest versions apn_sender will use Rails.logger as the default logger.
62
64
 
63
65
 
64
66
  ### 4. Checking Apple's Feedback Service
@@ -147,5 +149,3 @@ To add a few useful rake tasks for running workers, add the following line to yo
147
149
  APN Sender is released under the [MIT License](http://www.opensource.org/licenses/MIT).
148
150
 
149
151
 
150
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/arthurnn/apn_sender/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
151
-
data/lib/apn.rb CHANGED
@@ -22,26 +22,26 @@ module APN
22
22
  msg = APN::Notification.new(token, opts)
23
23
  raise "Invalid notification options (did you provide :alert, :badge, or :sound?): #{opts.inspect}" unless msg.valid?
24
24
 
25
+ APN.log(:debug, "Sending to token '#{token}' message '#{opts.to_s}'")
25
26
  APN.with_connection do |client|
26
27
  client.push(msg)
27
28
  end
28
29
  end
29
30
 
30
31
  def backend=(backend)
31
- @backend = backend
32
+ @backend =
33
+ case backend
34
+ when Symbol
35
+ APN::Backend.const_get(backend.to_s.camelize).new
36
+ when nil
37
+ APN::Backend::Simple.new
38
+ else
39
+ backend
40
+ end
32
41
  end
33
42
 
34
43
  def backend
35
- @backend ||=
36
- if defined?(Sidekiq)
37
- require 'apn/jobs/sidekiq_notification_job'
38
- APN::Backend::Sidekiq.new
39
- elsif defined?(Resque)
40
- require 'apn/jobs/resque_notification_job'
41
- APN::Backend::Resque.new
42
- else
43
- APN::Backend::Simple.new
44
- end
44
+ @backend ||= APN::Backend::Simple.new
45
45
  end
46
46
 
47
47
  def logger=(logger)
@@ -1,22 +1,9 @@
1
1
  module APN
2
2
  module Backend
3
-
4
- class Sidekiq
5
-
6
- def notify(token, opts)
7
- ::Sidekiq::Client.enqueue(APN::Jobs::SidekiqNotificationJob, token, opts)
8
- end
9
- end
10
-
11
- class Resque
12
-
13
- def notify(token, opts)
14
- ::Resque.enqueue(APN::Jobs::ResqueNotificationJob, token, opts)
15
- end
16
- end
3
+ autoload :Sidekiq, 'apn/backend/sidekiq'
4
+ autoload :Resque, 'apn/backend/resque'
17
5
 
18
6
  class Simple
19
-
20
7
  def notify(token, opts)
21
8
  Thread.new do
22
9
  APN.notify_sync(token, opts)
@@ -25,7 +12,6 @@ module APN
25
12
  end
26
13
 
27
14
  class Null
28
-
29
15
  def notify(token, opts)
30
16
  APN.log("Null Backend sending message to #{token}")
31
17
  end
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'resque'
3
+ require 'apn/jobs/resque_notification_job'
4
+ rescue LoadError => e
5
+ $stderr.puts "You don't have resque installed in your application. Please add it to your Gemfile and run bundle install"
6
+ raise e
7
+ end
8
+
9
+ module APN
10
+ module Backend
11
+ class Resque
12
+ def notify(token, opts)
13
+ ::Resque.enqueue(APN::Jobs::ResqueNotificationJob, token, opts)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'sidekiq'
3
+ require 'apn/jobs/sidekiq_notification_job'
4
+ rescue LoadError => e
5
+ $stderr.puts "You don't have sidekiq installed in your application. Please add it to your Gemfile and run bundle install"
6
+ raise e
7
+ end
8
+
9
+ module APN
10
+ module Backend
11
+ class Sidekiq
12
+ def notify(token, opts)
13
+ ::Sidekiq::Client.enqueue(APN::Jobs::SidekiqNotificationJob, token, opts)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -22,7 +22,7 @@ module APN
22
22
 
23
23
  APN.log(:debug, "Message sent.")
24
24
  true
25
- rescue OpenSSL::SSL::SSLError, Errno::EPIPE => e
25
+ rescue OpenSSL::SSL::SSLError, Errno::EPIPE, Errno::ETIMEDOUT => e
26
26
  APN.log(:error, "[##{self.object_id}] Exception occurred: #{e.inspect}, socket state: #{socket.inspect}")
27
27
  reset_socket
28
28
  APN.log(:debug, "[##{self.object_id}] Socket reestablished, socket state: #{socket.inspect}")
@@ -46,7 +46,7 @@ module APN
46
46
 
47
47
  # Prettify to return meaningful status information when printed. Can't add these directly to connection/base, because Resque depends on decoding to_s
48
48
  def to_s
49
- "#{@socket ? 'Connected' : 'Connection not currently established'} to #{host} on #{port}"
49
+ "#{@client ? 'Connected' : 'Connection not currently established'} to #{host} on #{port}"
50
50
  end
51
51
 
52
52
  protected
@@ -73,6 +73,9 @@ module APN
73
73
  if sound = opts.delete(:sound)
74
74
  hsh['aps']['sound'] = sound.is_a?(TrueClass) ? 'default' : sound.to_s
75
75
  end
76
+ if content_available = opts.delete(:content_available)
77
+ hsh['aps']['content-available'] = 1 if [1,true].include? content_available
78
+ end
76
79
  hsh.merge!(opts)
77
80
  payload(hsh)
78
81
  end
@@ -7,10 +7,7 @@ module APN
7
7
  APN.certificate_name = "apn_development.pem"
8
8
  APN.host = "gateway.sandbox.push.apple.com"
9
9
  end
10
-
11
- logger = Logger.new(File.join(Rails.root, 'log', 'apn_sender.log'))
12
- APN.logger = logger
13
-
10
+ APN.logger = Rails.logger
14
11
  end
15
12
  end
16
13
  end
@@ -13,6 +13,7 @@ namespace :apn do
13
13
  return
14
14
  end
15
15
 
16
+ APN.backend = :resque
16
17
  APN.password = ENV['CERT_PASS']
17
18
  APN.full_certificate_path = ENV['FULL_CERT_PATH']
18
19
  APN.logger = Rails.logger
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module APN
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.2"
4
4
  end
@@ -0,0 +1 @@
1
+ require 'apn'
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apn_sender
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Kali Donovan
@@ -13,46 +14,40 @@ date: 2011-05-15 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: connection_pool
16
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &1 !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ">="
19
21
  - !ruby/object:Gem::Version
20
22
  version: '0'
21
23
  type: :runtime
22
24
  prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
25
+ version_requirements: *1
28
26
  - !ruby/object:Gem::Dependency
29
27
  name: activesupport
30
- requirement: !ruby/object:Gem::Requirement
28
+ requirement: &2 !ruby/object:Gem::Requirement
29
+ none: false
31
30
  requirements:
32
31
  - - ">="
33
32
  - !ruby/object:Gem::Version
34
33
  version: '3.1'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 4.1.0
35
37
  type: :runtime
36
38
  prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '3.1'
39
+ version_requirements: *2
42
40
  - !ruby/object:Gem::Dependency
43
41
  name: daemons
44
- requirement: !ruby/object:Gem::Requirement
42
+ requirement: &3 !ruby/object:Gem::Requirement
43
+ none: false
45
44
  requirements:
46
45
  - - ">="
47
46
  - !ruby/object:Gem::Version
48
47
  version: '0'
49
48
  type: :runtime
50
49
  prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
50
+ version_requirements: *3
56
51
  description: Background worker to send Apple Push Notifications over a persistent
57
52
  TCP socket. Includes Resque tweaks to allow persistent sockets between jobs, helper
58
53
  methods for enqueueing APN notifications, and a background daemon to send them.
@@ -61,11 +56,8 @@ executables: []
61
56
  extensions: []
62
57
  extra_rdoc_files: []
63
58
  files:
64
- - CHANGELOG.md
65
- - LICENSE
66
- - README.md
67
- - Rakefile
68
- - lib/apn.rb
59
+ - lib/apn/backend/resque.rb
60
+ - lib/apn/backend/sidekiq.rb
69
61
  - lib/apn/backend.rb
70
62
  - lib/apn/client.rb
71
63
  - lib/apn/connection.rb
@@ -77,29 +69,36 @@ files:
77
69
  - lib/apn/sender_daemon.rb
78
70
  - lib/apn/tasks.rb
79
71
  - lib/apn/version.rb
72
+ - lib/apn.rb
73
+ - lib/apn_sender.rb
74
+ - CHANGELOG.md
75
+ - LICENSE
76
+ - README.md
77
+ - Rakefile
80
78
  homepage: http://github.com/arthurnn/apn_sender
81
79
  licenses:
82
80
  - MIT
83
- metadata: {}
84
81
  post_install_message:
85
82
  rdoc_options: []
86
83
  require_paths:
87
84
  - lib
88
85
  required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
89
87
  requirements:
90
88
  - - ">="
91
89
  - !ruby/object:Gem::Version
92
90
  version: '1.9'
93
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
94
93
  requirements:
95
94
  - - ">="
96
95
  - !ruby/object:Gem::Version
97
96
  version: 1.3.6
98
97
  requirements: []
99
98
  rubyforge_project:
100
- rubygems_version: 2.2.0
99
+ rubygems_version: 1.8.11
101
100
  signing_key:
102
- specification_version: 4
101
+ specification_version: 3
103
102
  summary: Background worker to send Apple Push Notifications over a persistent TCP
104
103
  socket.
105
104
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: e9297870e306966d00d3d0acf01a3022dbbb1636
4
- data.tar.gz: 25b8a81befe782fba5a0b7f0376ce9491f674a86
5
- SHA512:
6
- metadata.gz: 5048150d58ffba87b276ebe50d24bd1ab744f6eefa58ac94662cf22b5b773fde19fa66b840c1c982303693460d0d53283606aa9a0af7f99f04a6e4eb6802e634
7
- data.tar.gz: ef4fc9e0ce014ac4bef75d1da4f858ae6317a86bed03aa09e8ca1f248e9b9cffef8f9a5ec2939024fb7db4ee89cfe87e91dcc0bb2c302a581cfcb8a38466f126