./lib/houston/client.rb in houston-2.2.3 vs ./lib/houston/client.rb in houston-2.2.4

- old
+ new

@@ -1,11 +1,11 @@ module Houston - APPLE_PRODUCTION_GATEWAY_URI = "apn://gateway.push.apple.com:2195" - APPLE_PRODUCTION_FEEDBACK_URI = "apn://feedback.push.apple.com:2196" + APPLE_PRODUCTION_GATEWAY_URI = 'apn://gateway.push.apple.com:2195' + APPLE_PRODUCTION_FEEDBACK_URI = 'apn://feedback.push.apple.com:2196' - APPLE_DEVELOPMENT_GATEWAY_URI = "apn://gateway.sandbox.push.apple.com:2195" - APPLE_DEVELOPMENT_FEEDBACK_URI = "apn://feedback.sandbox.push.apple.com:2196" + APPLE_DEVELOPMENT_GATEWAY_URI = 'apn://gateway.sandbox.push.apple.com:2195' + APPLE_DEVELOPMENT_FEEDBACK_URI = 'apn://feedback.sandbox.push.apple.com:2196' class Client attr_accessor :gateway_uri, :feedback_uri, :certificate, :passphrase, :timeout class << self @@ -25,11 +25,11 @@ end def initialize @gateway_uri = ENV['APN_GATEWAY_URI'] @feedback_uri = ENV['APN_FEEDBACK_URI'] - @certificate = File.read(ENV['APN_CERTIFICATE']) if ENV['APN_CERTIFICATE'] + @certificate = certificate_data @passphrase = ENV['APN_CERTIFICATE_PASSPHRASE'] @timeout = Float(ENV['APN_TIMEOUT'] || 0.5) end def push(*notifications) @@ -51,11 +51,11 @@ notification.mark_as_sent! read_socket, write_socket = IO.select([ssl], [ssl], [ssl], nil) if (read_socket && read_socket[0]) if error = connection.read(6) - command, status, index = error.unpack("ccN") + command, status, index = error.unpack('ccN') notification.apns_error_code = status notification.mark_as_unsent! end end end @@ -68,17 +68,25 @@ Connection.open(@feedback_uri, @certificate, @passphrase) do |connection| while line = connection.read(38) feedback = line.unpack('N1n1H140') timestamp = feedback[0] token = feedback[2].scan(/.{0,8}/).join(' ').strip - devices << {token: token, timestamp: timestamp} if token && timestamp + devices << { token: token, timestamp: timestamp } if token && timestamp end end devices end def devices - unregistered_devices.collect{|device| device[:token]} + unregistered_devices.collect { |device| device[:token] } + end + + def certificate_data + if ENV['APN_CERTIFICATE'] + File.read(ENV['APN_CERTIFICATE']) + elsif ENV['APN_CERTIFICATE_DATA'] + ENV['APN_CERTIFICATE_DATA'] + end end end end