Sha256: fd80c394420f92131ac96da2712047506a62b83df544121e53f7506f2a425e7d

Contents?: true

Size: 1.37 KB

Versions: 11

Compression:

Stored size: 1.37 KB

Contents

module Rpush
  module Daemon
    module Dispatcher
      class ApnsHttp2

        URLS = {
          production: 'https://api.push.apple.com:443',
          development: 'https://api.development.push.apple.com:443',
          sandbox: 'https://api.development.push.apple.com:443'
        }

        DEFAULT_TIMEOUT = 60

        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

        def dispatch(payload)
          @delivery_class.new(@app, @client, payload.batch).perform
        end

        def cleanup
          @client.close
        end

        private

        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
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
rpush-3.3.1 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush-3.3.0 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush_extended-3.2.6 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush_extended-3.2.5 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush-3.2.4 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush-3.2.3 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush-3.2.2 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush-3.2.1 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush-3.2.0 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush-3.1.1 lib/rpush/daemon/dispatcher/apns_http2.rb
rpush-3.1.0 lib/rpush/daemon/dispatcher/apns_http2.rb