Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Working on feedback.

  • Loading branch information...
commit cf4ae4f4502f811f6232b3660310afb2dfc1d202 1 parent e6b7afe
@markbates markbates authored
View
35 lib/apn_on_rails/app/models/apn/connection.rb
@@ -34,7 +34,34 @@ def open_for_delivery(options = {}, &block)
# configatron.apn.feedback.cert = File.join(rails_root, 'config', 'apple_push_notification_development.pem')) # Development
# configatron.apn.feedback.cert = File.join(rails_root, 'config', 'apple_push_notification_production.pem')) # Production
def open_for_feedback(options = {}, &block) # :nodoc:
+ options = {:cert => configatron.apn.feedback.cert,
+ :passphrase => configatron.apn.feedback.passphrase,
+ :host => configatron.apn.feedback.host,
+ :port => configatron.apn.feedback.port}.merge(options)
+ open(options, &block)
+ # 'c5280d58a5dda773f5d59578f895c0e16124fab77938ac00b903115a21d4'.unpack('N1n1H140')
+ # time (big endian), token length (big endian), device token (binary)
+ # [1664430648, 12388, "353861356464613737336635643539353738663839356330653136313234666162373739333861633030623930333131356132316434"]
+ # APN::Connection.open_for_feedback do |conn, sock|
+ # # begin
+ # # while data = sock.read(76)
+ # # next if data.size < 76
+ # # timestamp, token_length, device_token = data.unpack('N1n1H140')
+ # # puts timestamp
+ # # puts token_length
+ # # puts device_token
+ # # end
+ # # rescue SocketError => e
+ # # puts 'oops!'
+ # # puts e.message
+ # # end
+ #
+ # while line = sock.gets # Read lines from the socket
+ # puts line.chop.unpack('N1n1H140') # And print with platform line terminator
+ # end
+ #
+ # end
end
private
@@ -48,15 +75,15 @@ def open(options = {}, &block) # :nodoc:
ctx.key = OpenSSL::PKey::RSA.new(cert, options[:passphrase])
ctx.cert = OpenSSL::X509::Certificate.new(cert)
- s = TCPSocket.new(options[:host], options[:port])
- ssl = OpenSSL::SSL::SSLSocket.new(s, ctx)
+ sock = TCPSocket.new(options[:host], options[:port])
+ ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
ssl.sync = true
ssl.connect
- yield ssl if block_given?
+ yield ssl, sock if block_given?
ssl.close
- s.close
+ sock.close
end
end
View
2  lib/apn_on_rails/app/models/apn/notification.rb
@@ -87,7 +87,7 @@ class << self
def send_notifications(notifications = APN::Notification.all(:conditions => {:sent_at => nil}))
unless notifications.nil? || notifications.empty?
- APN::Connection.open_for_delivery do |conn|
+ APN::Connection.open_for_delivery do |conn, sock|
notifications.each do |noty|
conn.write(noty.message_for_sending)
noty.sent_at = Time.now
Please sign in to comment.
Something went wrong with that request. Please try again.