push-apns 0.0.1.pre3 → 0.0.1.pre4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ module Push
2
+ class ConfigurationApns < Push::Configuration
3
+ store :properties, accessors: [:certificate, :certificate_password, :sandbox, :feedback_poll]
4
+ attr_accessible :app, :enabled, :connections, :certificate, :certificate_password, :sandbox, :feedback_poll
5
+ validates :certificate, :presence => true
6
+ validates :sandbox, :inclusion => { :in => [true, false] }
7
+ validates :feedback_poll, :presence => true
8
+
9
+ def name
10
+ :apns
11
+ end
12
+ end
13
+ end
@@ -1,14 +1,12 @@
1
1
  module Push
2
2
  module Daemon
3
3
  class Apns
4
- attr_accessor :configuration, :certificate
4
+ attr_accessor :configuration
5
5
 
6
6
  def initialize(options)
7
7
  self.configuration = options
8
8
 
9
- self.certificate = ApnsSupport::Certificate.new(configuration[:certificate])
10
- certificate.load
11
-
9
+ @feedback_receiver = ApnsSupport::FeedbackReceiver.new(self)
12
10
  start_feedback
13
11
  end
14
12
 
@@ -26,11 +24,11 @@ module Push
26
24
  end
27
25
 
28
26
  def start_feedback
29
- ApnsSupport::FeedbackReceiver.start(self)
27
+ @feedback_receiver.start
30
28
  end
31
29
 
32
30
  def stop_feedback
33
- ApnsSupport::FeedbackReceiver.stop
31
+ @feedback_receiver.stop
34
32
  end
35
33
 
36
34
  def stop
@@ -10,11 +10,11 @@ module Push
10
10
  @provider = provider
11
11
  if i
12
12
  # Apns push connection
13
- @name = "ConnectionApns #{i}"
13
+ @name = "#{@provider.configuration[:name]}: ConnectionApns #{i}"
14
14
  @host = "gateway.#{provider.configuration[:sandbox] ? 'sandbox.' : ''}push.apple.com"
15
15
  @port = 2195
16
16
  else
17
- @name = "FeedbackReceiver"
17
+ @name = "#{@provider.configuration[:name]}: FeedbackReceiver"
18
18
  @host = "feedback.#{provider.configuration[:sandbox] ? 'sandbox.' : ''}push.apple.com"
19
19
  @port = 2196
20
20
  end
@@ -94,8 +94,8 @@ module Push
94
94
 
95
95
  def setup_ssl_context
96
96
  ssl_context = OpenSSL::SSL::SSLContext.new
97
- ssl_context.key = OpenSSL::PKey::RSA.new(provider.certificate.certificate, provider.configuration[:certificate_password])
98
- ssl_context.cert = OpenSSL::X509::Certificate.new(provider.certificate.certificate)
97
+ ssl_context.key = OpenSSL::PKey::RSA.new(provider.configuration[:certificate], provider.configuration[:certificate_password])
98
+ ssl_context.cert = OpenSSL::X509::Certificate.new(provider.configuration[:certificate])
99
99
  ssl_context
100
100
  end
101
101
 
@@ -2,12 +2,14 @@ module Push
2
2
  module Daemon
3
3
  module ApnsSupport
4
4
  class FeedbackReceiver
5
- extend Push::Daemon::InterruptibleSleep
6
- attr_accessor :provider
5
+ include Push::Daemon::InterruptibleSleep
7
6
  FEEDBACK_TUPLE_BYTES = 38
8
7
 
9
- def self.start(provider)
8
+ def initialize(provider)
10
9
  @provider = provider
10
+ end
11
+
12
+ def start
11
13
  @thread = Thread.new do
12
14
  loop do
13
15
  break if @stop
@@ -17,13 +19,12 @@ module Push
17
19
  end
18
20
  end
19
21
 
20
- def self.stop
22
+ def stop
21
23
  @stop = true
22
24
  interrupt_sleep
23
- @thread.join if @thread
24
25
  end
25
26
 
26
- def self.check_for_feedback
27
+ def check_for_feedback
27
28
  connection = nil
28
29
  begin
29
30
  connection = ApnsSupport::ConnectionApns.new(@provider)
@@ -42,15 +43,15 @@ module Push
42
43
 
43
44
  protected
44
45
 
45
- def self.parse_tuple(tuple)
46
+ def parse_tuple(tuple)
46
47
  failed_at, _, device = tuple.unpack("N1n1H*")
47
48
  [Time.at(failed_at).utc, device]
48
49
  end
49
50
 
50
- def self.create_feedback(failed_at, device)
51
+ def create_feedback(failed_at, device)
51
52
  formatted_failed_at = failed_at.strftime("%Y-%m-%d %H:%M:%S UTC")
52
53
  Push::Daemon.logger.info("[FeedbackReceiver] Delivery failed at #{formatted_failed_at} for #{device}")
53
- Push::FeedbackApns.create!(:failed_at => failed_at, :device => device)
54
+ Push::FeedbackApns.create!(:app => @provider.configuration[:name], :failed_at => failed_at, :device => device, :follow_up => 'delete')
54
55
  end
55
56
  end
56
57
  end
@@ -1,5 +1,7 @@
1
1
  module Push
2
2
  class FeedbackApns < Push::Feedback
3
+ attr_accessible :app, :device, :follow_up, :failed_at
3
4
  validates :device, :format => { :with => /\A[a-z0-9]{64}\z/ }
5
+ validates :follow_up, :inclusion => { :in => %w(delete), :message => "%{value} is not a valid follow-up" }
4
6
  end
5
7
  end
@@ -15,7 +15,7 @@ module Push
15
15
  }
16
16
 
17
17
  store :properties, accessors: [:alert, :badge, :sound, :expiry, :attributes_for_device]
18
- attr_accessible :device, :alert, :badge, :sound, :expiry, :attributes_for_device
18
+ attr_accessible :app, :device, :alert, :badge, :sound, :expiry, :attributes_for_device
19
19
 
20
20
  validates :badge, :numericality => true, :allow_nil => true
21
21
  validates :expiry, :numericality => true, :presence => true
@@ -1,3 +1,3 @@
1
1
  module PushApns
2
- VERSION = "0.0.1.pre3"
2
+ VERSION = "0.0.1.pre4"
3
3
  end
data/lib/push-apns.rb CHANGED
@@ -2,12 +2,13 @@ require 'socket'
2
2
  require 'pathname'
3
3
  require 'push-apns/version'
4
4
  require 'push/apns/binary_notification_validator'
5
+ require 'push/configuration'
6
+ require 'push/configuration_apns'
5
7
  require 'push/message'
6
8
  require 'push/message_apns'
7
9
  require 'push/feedback'
8
10
  require 'push/feedback_apns'
9
11
  require 'push/daemon/apns'
10
12
  require 'push/daemon/interruptible_sleep'
11
- require 'push/daemon/apns_support/certificate'
12
13
  require 'push/daemon/apns_support/connection_apns'
13
14
  require 'push/daemon/apns_support/feedback_receiver'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: push-apns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre3
4
+ version: 0.0.1.pre4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-03 00:00:00.000000000 Z
12
+ date: 2012-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
16
- requirement: &70130311065320 !ruby/object:Gem::Requirement
16
+ requirement: &70225631818240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70130311065320
24
+ version_requirements: *70225631818240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: push-core
27
- requirement: &70130311063400 !ruby/object:Gem::Requirement
27
+ requirement: &70225631817380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
31
31
  - !ruby/object:Gem::Version
32
- version: 0.0.1.pre2
32
+ version: 0.0.1.pre4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70130311063400
35
+ version_requirements: *70225631817380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70130311061660 !ruby/object:Gem::Requirement
38
+ requirement: &70225631816340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,8 +43,8 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70130311061660
47
- description: Plugin with APNS specific push information.
46
+ version_requirements: *70225631816340
47
+ description: APNS support for the modular push daemon.
48
48
  email:
49
49
  - tom@tnux.net
50
50
  executables: []
@@ -54,8 +54,8 @@ files:
54
54
  - lib/push-apns.rb
55
55
  - lib/push-apns/version.rb
56
56
  - lib/push/apns/binary_notification_validator.rb
57
+ - lib/push/configuration_apns.rb
57
58
  - lib/push/daemon/apns.rb
58
- - lib/push/daemon/apns_support/certificate.rb
59
59
  - lib/push/daemon/apns_support/connection_apns.rb
60
60
  - lib/push/daemon/apns_support/feedback_receiver.rb
61
61
  - lib/push/feedback_apns.rb
@@ -85,5 +85,5 @@ rubyforge_project:
85
85
  rubygems_version: 1.8.5
86
86
  signing_key:
87
87
  specification_version: 3
88
- summary: APNS (iOS) part of the modular push daemon.
88
+ summary: APNS (iOS/Apple) part of the modular push daemon.
89
89
  test_files: []
@@ -1,37 +0,0 @@
1
- module Push
2
- class CertificateError < StandardError; end
3
-
4
- module Daemon
5
- module ApnsSupport
6
- class Certificate
7
- attr_accessor :certificate
8
-
9
- def initialize(certificate_path)
10
- @certificate_path = path(certificate_path)
11
- end
12
-
13
- def path(path)
14
- if Pathname.new(path).absolute?
15
- path
16
- else
17
- File.join(Rails.root, "config", "push", path)
18
- end
19
- end
20
-
21
- def load
22
- @certificate = read_certificate
23
- end
24
-
25
- protected
26
-
27
- def read_certificate
28
- if !File.exists?(@certificate_path)
29
- raise CertificateError, "#{@certificate_path} does not exist. The certificate location can be configured in config/push/<<environment>>.rb"
30
- else
31
- File.read(@certificate_path)
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end