mattt/houston — pull request #12 by soffes (2013-04-15 21:13:30+00:00)
Title: Optionally manage your own connections

You can test this with the following script in the Houston directory (I'd love to write actual tests at some point)

``` ruby

require 'bundler'
Bundler.setup

token = 'asdf...'
cert = '/somewhere/apple_push_notification.pem'
message = 'Whatever'

client = Houston::Client.development
client.certificate = File.read(cert)

# Initialize your own connection.
# Note that it uses the `client.connection_options_for_endpoint` method. Not a fan of this.
client.gateway_connection = Houston::Connection.new(client.connection_options_for_endpoint(:gateway))

# You have to explicitly open the connection since you are managing it.
client.gateway_connection.open

notification = Houston::Notification.new(device: token)
notification.alert = message

client.push(notification)

puts "Still open: #{client.gateway_connection.open?.inspect}"
```

Basically it checks for the instance variable or will make a new connection. If the connection is open when it's called, it won't close it since it assumes you are managing it.

I think the API for creating a connection with the client needs to be cleaned up. Would love some feedback.