Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
Simplifying Houston::Client#push
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Aug 13, 2014
1 parent e6bba76 commit e71b87d
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions lib/houston/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def push(*notifications)
return if notifications.empty?

notifications.flatten!
error = nil

Connection.open(@gateway_uri, @certificate, @passphrase) do |connection|
ssl = connection.ssl
Expand All @@ -51,32 +50,16 @@ def push(*notifications)
connection.write(notification.message)
notification.mark_as_sent!

break if notifications.count == 1 || notification == notifications.last

read_socket, write_socket = IO.select([ssl], [ssl], [ssl], nil)
if (read_socket && read_socket[0])
error = connection.read(6)
break
end
end

return if notifications.count == 1

unless error
read_socket, write_socket = IO.select([ssl], nil, [ssl], timeout)
if (read_socket && read_socket[0])
error = connection.read(6)
if error = connection.read(6)
command, status, index = error.unpack("ccN")
notification.apns_error_code = status
notification.mark_as_unsent!
end
end
end
end

if error
command, status, index = error.unpack("ccN")
notifications[index].apns_error_code = status
notifications.slice!(0..index)
notifications.each(&:mark_as_unsent!)
push(*notifications)
end
end

def unregistered_devices
Expand Down

0 comments on commit e71b87d

Please sign in to comment.