Class: APN::Client
- Inherits:
-
Object
- Object
- APN::Client
- Defined in:
- lib/apn/client.rb
Constant Summary collapse
- DEFAULTS =
{port: 2195, host: "gateway.push.apple.com"}
Instance Method Summary collapse
- #feedback ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #push(message) ⇒ Object
- #socket ⇒ Object
Constructor Details
Instance Method Details
#feedback ⇒ Object
32 33 34 35 36 37 |
# File 'lib/apn/client.rb', line 32 def feedback if bunch = socket.read(38) f = bunch.strip.unpack('N1n1H140') APN::FeedbackItem.new(Time.at(f[0]), f[2]) end end |
#push(message) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/apn/client.rb', line 13 def push() socket.write(.to_s) socket.flush if IO.select([socket], nil, nil, 1) && error = socket.read(6) error = error.unpack("ccN") APN.log(:error, "Error on message: #{error}") return false end APN.log(:debug, "Message sent.") true rescue OpenSSL::SSL::SSLError, Errno::EPIPE, Errno::ETIMEDOUT => e APN.log(:error, "[##{self.object_id}] Exception occurred: #{e.inspect}, socket state: #{socket.inspect}") reset_socket APN.log(:debug, "[##{self.object_id}] Socket reestablished, socket state: #{socket.inspect}") retry end |
#socket ⇒ Object
39 40 41 |
# File 'lib/apn/client.rb', line 39 def socket @socket ||= setup_socket end |