Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ and install it with
APNS.pass = ''
# Just in case your pem need a password

Alternatively, If you don't have the certificate stored in a file, you can pass any object that responds to ``read``.

APNS.pem = StringIO.new(pem_string)

### Usage

#### Sending a single notification:
Expand Down
28 changes: 17 additions & 11 deletions lib/pushmeup/apns/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,25 @@ def self.feedback

return apns_feedback
end

protected

def self.pem_data
raise "Your pem file is not set. (APNS.pem = /path/to/cert.pem or object that responds to read)" unless pem
if pem.respond_to? :read
data = pem.read
pem.rewind if pem.respond_to?(:rewind)
else
raise "The path to your pem file does not exist!" unless File.exist?(pem)
data = File.read(pem)
end
data
end

def self.open_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)
context.cert = OpenSSL::X509::Certificate.new(self.pem_data)
context.key = OpenSSL::PKey::RSA.new(self.pem_data, self.pass)

sock = TCPSocket.new(self.host, self.port)
ssl = OpenSSL::SSL::SSLSocket.new(sock,context)
Expand All @@ -65,12 +74,9 @@ def self.open_connection
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)
context.cert = OpenSSL::X509::Certificate.new(self.pem_data)
context.key = OpenSSL::PKey::RSA.new(self.pem_data, self.pass)

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