Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check socket and ssl connection exist before closing. #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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: 2 additions & 2 deletions lib/pushmeup/apns/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def self.with_connection
rescue StandardError, Errno::EPIPE
raise unless attempts < @retries

@ssl.close
@sock.close
@ssl.close unless @ssl.nil?
@sock.close unless @sock.nil?

attempts += 1
retry
Expand Down
6 changes: 4 additions & 2 deletions lib/pushmeup/apns/notification.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module APNS
class Notification
attr_accessor :device_token, :alert, :badge, :sound, :other
attr_accessor :device_token, :alert, :badge, :sound, :category, :other

def initialize(device_token, message)
self.device_token = device_token
if message.is_a?(Hash)
self.alert = message[:alert]
self.badge = message[:badge]
self.sound = message[:sound]
self.category = message[:category]
self.other = message[:other]
elsif message.is_a?(String)
self.alert = message
Expand All @@ -31,6 +32,7 @@ def packaged_message
aps['aps']['alert'] = self.alert if self.alert
aps['aps']['badge'] = self.badge if self.badge
aps['aps']['sound'] = self.sound if self.sound
aps['aps']['category'] = self.category if self.category
aps.merge!(self.other) if self.other
aps.to_json.gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack("H*").unpack("n*").pack("U*")}
end
Expand All @@ -40,8 +42,8 @@ def ==(that)
alert == that.alert &&
badge == that.badge &&
sound == that.sound &&
category == that.category &&
other == that.other
end

end
end