module Rpush::Client::ActiveModel::Apns::App

Public Class Methods

included(base) click to toggle source
# File lib/rpush/client/active_model/apns/app.rb, line 6
def self.included(base)
  base.instance_eval do
    validates :environment, presence: true, inclusion: { in: %w(development production sandbox) }
    validates :certificate, presence: true
    validate :certificate_has_matching_private_key
  end
end

Public Instance Methods

service_name() click to toggle source
# File lib/rpush/client/active_model/apns/app.rb, line 14
def service_name
  'apns'
end

Private Instance Methods

certificate_has_matching_private_key() click to toggle source
# File lib/rpush/client/active_model/apns/app.rb, line 20
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 && pkey
    rescue OpenSSL::OpenSSLError
      errors.add :certificate, 'value must contain a certificate and a private key.'
    end
  end
  result
end