Class: ApnsProviderApi::Connection
- Inherits:
-
Object
- Object
- ApnsProviderApi::Connection
- Extended by:
- Forwardable
- Defined in:
- lib/apns_provider_api/connection.rb
Instance Attribute Summary collapse
-
#certificate ⇒ Object
readonly
def_delegators :@stream, :headers, :data.
-
#http2client ⇒ Object
readonly
def_delegators :@stream, :headers, :data.
-
#passphrase ⇒ Object
readonly
def_delegators :@stream, :headers, :data.
-
#socket ⇒ Object
readonly
def_delegators :@stream, :headers, :data.
-
#ssl ⇒ Object
readonly
def_delegators :@stream, :headers, :data.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #events ⇒ Object
-
#initialize(uri, certificate, passphrase) ⇒ Connection
constructor
A new instance of Connection.
- #new_stream ⇒ Object
- #open ⇒ Object
- #open? ⇒ Boolean
Constructor Details
#initialize(uri, certificate, passphrase) ⇒ Connection
Returns a new instance of Connection.
26 27 28 29 30 31 32 33 |
# File 'lib/apns_provider_api/connection.rb', line 26 def initialize(uri, certificate, passphrase) @uri = URI(uri) @certificate = certificate @passphrase = passphrase @http2client = HTTP2::Client.new events @http2client end |
Instance Attribute Details
#certificate ⇒ Object (readonly)
def_delegators :@stream, :headers, :data
11 12 13 |
# File 'lib/apns_provider_api/connection.rb', line 11 def certificate @certificate end |
#http2client ⇒ Object (readonly)
def_delegators :@stream, :headers, :data
11 12 13 |
# File 'lib/apns_provider_api/connection.rb', line 11 def http2client @http2client end |
#passphrase ⇒ Object (readonly)
def_delegators :@stream, :headers, :data
11 12 13 |
# File 'lib/apns_provider_api/connection.rb', line 11 def passphrase @passphrase end |
#socket ⇒ Object (readonly)
def_delegators :@stream, :headers, :data
11 12 13 |
# File 'lib/apns_provider_api/connection.rb', line 11 def socket @socket end |
#ssl ⇒ Object (readonly)
def_delegators :@stream, :headers, :data
11 12 13 |
# File 'lib/apns_provider_api/connection.rb', line 11 def ssl @ssl end |
Class Method Details
.open(uri, certificate, passphrase) {|connection| ... } ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/apns_provider_api/connection.rb', line 14 def open(uri, certificate, passphrase) return unless block_given? connection = new(uri, certificate, passphrase) connection.open yield connection connection.close end |
Instance Method Details
#close ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/apns_provider_api/connection.rb', line 53 def close return false if closed? @socket.close @socket = nil @ssl.close @ssl = nil end |
#closed? ⇒ Boolean
63 64 65 |
# File 'lib/apns_provider_api/connection.rb', line 63 def closed? not open? end |
#events ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/apns_provider_api/connection.rb', line 71 def events @http2client.on(:frame) do |bytes| # puts "Sending bytes: #{bytes.unpack("H*").first}" ssl.print bytes ssl.flush end end |
#new_stream ⇒ Object
67 68 69 |
# File 'lib/apns_provider_api/connection.rb', line 67 def new_stream @http2client.new_stream end |
#open ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/apns_provider_api/connection.rb', line 35 def open return false if open? @socket = TCPSocket.new(@uri.host, @uri.port) context = OpenSSL::SSL::SSLContext.new context.key = OpenSSL::PKey::RSA.new(@certificate, @passphrase) context.cert = OpenSSL::X509::Certificate.new(certificate) @ssl = OpenSSL::SSL::SSLSocket.new(@socket, context) @ssl.sync_close = true @ssl.hostname = @uri.hostname @ssl.connect end |
#open? ⇒ Boolean
49 50 51 |
# File 'lib/apns_provider_api/connection.rb', line 49 def open? not (@ssl and @socket).nil? end |