Sha256: 7a02cb2e90827eab45aa1ec6ac7e7165398107b8fd6eb2fa3218b0ad2c7fe9da

Contents?: true

Size: 1.12 KB

Versions: 13

Compression:

Stored size: 1.12 KB

Contents

module Rpush
  module Daemon
    module Dispatcher
      class Apnsp8Http2
        include Loggable
        include Reflectable

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

        DEFAULT_TIMEOUT = 60

        def initialize(app, delivery_class, _options = {})
          @app = app
          @delivery_class = delivery_class

          @client = create_http2_client(app)
          @token_provider = Rpush::Daemon::Apnsp8::Token.new(@app)
        end

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

        def cleanup
          @client.close
        end

        private

        def create_http2_client(app)
          url = URLS[app.environment.to_sym]
          client = NetHttp2::Client.new(url, connect_timeout: DEFAULT_TIMEOUT)
          client.on(:error) do |error|
            log_error(error)
            reflect(:error, error)
          end
          client
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rpush-9.1.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-9.0.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-8.0.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-7.0.1 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-7.0.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-6.0.1 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-6.0.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-5.4.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-5.3.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-5.2.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-5.1.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-5.0.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb
rpush-4.2.0 lib/rpush/daemon/dispatcher/apnsp8_http2.rb