class Rpush::Daemon::Dispatcher::ApnsHttp2

Constants

DEFAULT_TIMEOUT
URLS

Public Class Methods

new(app, delivery_class, _options = {}) click to toggle source
# File lib/rpush/daemon/dispatcher/apns_http2.rb, line 14
def initialize(app, delivery_class, _options = {})
  @app = app
  @delivery_class = delivery_class

  url = URLS[app.environment.to_sym]
  @client = NetHttp2::Client.new(url,
    ssl_context:     prepare_ssl_context,
    connect_timeout: DEFAULT_TIMEOUT)
end

Public Instance Methods

cleanup() click to toggle source
# File lib/rpush/daemon/dispatcher/apns_http2.rb, line 28
def cleanup
  @client.close
end
dispatch(payload) click to toggle source
# File lib/rpush/daemon/dispatcher/apns_http2.rb, line 24
def dispatch(payload)
  @delivery_class.new(@app, @client, payload.batch).perform
end

Private Instance Methods

prepare_ssl_context() click to toggle source
# File lib/rpush/daemon/dispatcher/apns_http2.rb, line 34
def prepare_ssl_context
  @ssl_context ||= begin
    ctx = OpenSSL::SSL::SSLContext.new
    begin
      p12      = OpenSSL::PKCS12.new(@app.certificate, @app.password)
      ctx.key  = p12.key
      ctx.cert = p12.certificate
    rescue OpenSSL::PKCS12::PKCS12Error
      ctx.key  = OpenSSL::PKey::RSA.new(@app.certificate, @app.password)
      ctx.cert = OpenSSL::X509::Certificate.new(@app.certificate)
    end
    ctx
  end
end