Class: Rapns::Daemon::Apns::FeedbackReceiver

Inherits:
Object
  • Object
show all
Includes:
InterruptibleSleep, Reflectable
Defined in:
lib/rapns/daemon/apns/feedback_receiver.rb

Constant Summary collapse

FEEDBACK_TUPLE_BYTES =
38
HOSTS =
{
  :production  => ['feedback.push.apple.com', 2196],
  :development => ['feedback.sandbox.push.apple.com', 2196], # deprecated
  :sandbox     => ['feedback.sandbox.push.apple.com', 2196]
}

Instance Method Summary collapse

Methods included from InterruptibleSleep

#interrupt_sleep, #interruptible_sleep

Methods included from Reflectable

#reflect

Constructor Details

#initialize(app, poll) ⇒ FeedbackReceiver

Returns a new instance of FeedbackReceiver.



15
16
17
18
19
20
21
# File 'lib/rapns/daemon/apns/feedback_receiver.rb', line 15

def initialize(app, poll)
  @app = app
  @host, @port = HOSTS[@app.environment.to_sym]
  @poll = poll
  @certificate = app.certificate
  @password = app.password
end

Instance Method Details

#check_for_feedbackObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rapns/daemon/apns/feedback_receiver.rb', line 39

def check_for_feedback
  connection = nil
  begin
    connection = Connection.new(@app, @host, @port)
    connection.connect

    while tuple = connection.read(FEEDBACK_TUPLE_BYTES)
      timestamp, device_token = parse_tuple(tuple)
      create_feedback(timestamp, device_token)
    end
  rescue StandardError => e
    Rapns.logger.error(e)
  ensure
    connection.close if connection
  end
end

#startObject



23
24
25
26
27
28
29
30
31
# File 'lib/rapns/daemon/apns/feedback_receiver.rb', line 23

def start
  @thread = Thread.new do
    loop do
      break if @stop
      check_for_feedback
      interruptible_sleep @poll
    end
  end
end

#stopObject



33
34
35
36
37
# File 'lib/rapns/daemon/apns/feedback_receiver.rb', line 33

def stop
  @stop = true
  interrupt_sleep
  @thread.join if @thread
end