Sha256: 8df199f184ffb6ee33f5473e9df1fdf9a899be6619af2f045d457e727fddf0bd

Contents?: true

Size: 832 Bytes

Versions: 2

Compression:

Stored size: 832 Bytes

Contents

module Rpush
  module Apns
    class App < Rpush::App
      validates :environment, :presence => true, :inclusion => { :in => %w(development production sandbox) }
      validates :certificate, :presence => true
      validate :certificate_has_matching_private_key

      def service_name
        'apns'
      end

      private

      def certificate_has_matching_private_key
        result = false
        if certificate.present?
          begin
            x509 = OpenSSL::X509::Certificate.new(certificate)
            pkey = OpenSSL::PKey::RSA.new(certificate, password)
            result = !x509.nil? && !pkey.nil?
          rescue OpenSSL::OpenSSLError
            errors.add :certificate, 'Certificate value must contain a certificate and a private key.'
          end
        end
        result
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rpush-1.0.0-java lib/rpush/apns/app.rb
rpush-1.0.0 lib/rpush/apns/app.rb