Skip to content

Commit

Permalink
adding in feedback service
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoz committed Apr 12, 2010
1 parent dc664d1 commit d759ba0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Convert your certificate

In Keychain access export your certificate as a p12. Then run the following command to convert it to a .pem


<pre>
<code>
openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts
Expand Down
35 changes: 35 additions & 0 deletions lib/apns/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ def self.send_notifications(notifications)
sock.close
end

def self.feedback
sock, ssl = self.feedback_connection

apns_feedback = []

while line = sock.gets # Read lines from the socket
line.strip!
f = line.unpack('N1n1H140')
apns_feedback << [Time.at(f[0]), f[2]]
end

ssl.close
sock.close

return apns_feedback
end

protected

def self.packaged_notification(device_token, message)
Expand Down Expand Up @@ -76,4 +93,22 @@ def self.open_connection
return sock, ssl
end

def self.feedback_connection
raise "The path to your pem file is not set. (APNS.pem = /path/to/cert.pem)" unless self.pem
raise "The path to your pem file does not exist!" unless File.exist?(self.pem)

context = OpenSSL::SSL::SSLContext.new
context.cert = OpenSSL::X509::Certificate.new(File.read(self.pem))
context.key = OpenSSL::PKey::RSA.new(File.read(self.pem), self.pass)

fhost = self.host.gsub!('gateway','feedback')
puts fhost

sock = TCPSocket.new(fhost, 2196)
ssl = OpenSSL::SSL::SSLSocket.new(sock,context)
ssl.connect

return sock, ssl
end

end

0 comments on commit d759ba0

Please sign in to comment.