Class: Passkit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/passkit.rb

Constant Summary collapse

REQUIRED_ATTRIBUTES =
%i[
  web_service_host
  certificate_key
  private_p12_certificate
  apple_intermediate_certificate
  apple_team_identifier
  pass_type_identifier
]
DEFAULT_AUTHENTICATION =
proc do
  authenticate_or_request_with_http_basic("Passkit Dashboard. Login required") do |username, password|
    username == Passkit.configuration.dashboard_username && password == Passkit.configuration.dashboard_password
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/passkit.rb', line 60

def initialize
  # Required
  @certificate_key = ENV["PASSKIT_CERTIFICATE_KEY"]
  @private_p12_certificate = ENV["PASSKIT_PRIVATE_P12_CERTIFICATE"]
  @apple_intermediate_certificate = ENV["PASSKIT_APPLE_INTERMEDIATE_CERTIFICATE"]
  @apple_team_identifier = ENV["PASSKIT_APPLE_TEAM_IDENTIFIER"]
  @pass_type_identifier = ENV["PASSKIT_PASS_TYPE_IDENTIFIER"]

  # Optional
  @skip_verification = false
  @web_service_host = ENV["PASSKIT_WEB_SERVICE_HOST"] || "https://localhost:3000"
  @available_passes = { "Passkit::ExampleStoreCard" => -> {} }
  @format_version = ENV["PASSKIT_FORMAT_VERSION"] || 1
  @dashboard_username = ENV["PASSKIT_DASHBOARD_USERNAME"]
  @dashboard_password = ENV["PASSKIT_DASHBOARD_PASSWORD"]
end

Instance Attribute Details

#apple_intermediate_certificateObject

Returns the value of attribute apple_intermediate_certificate.



29
30
31
# File 'lib/passkit.rb', line 29

def apple_intermediate_certificate
  @apple_intermediate_certificate
end

#apple_team_identifierObject

Returns the value of attribute apple_team_identifier.



29
30
31
# File 'lib/passkit.rb', line 29

def apple_team_identifier
  @apple_team_identifier
end

#available_passesObject

Returns the value of attribute available_passes.



29
30
31
# File 'lib/passkit.rb', line 29

def available_passes
  @available_passes
end

#certificate_keyObject

Returns the value of attribute certificate_key.



29
30
31
# File 'lib/passkit.rb', line 29

def certificate_key
  @certificate_key
end

#dashboard_passwordObject

Returns the value of attribute dashboard_password.



29
30
31
# File 'lib/passkit.rb', line 29

def dashboard_password
  @dashboard_password
end

#dashboard_usernameObject

Returns the value of attribute dashboard_username.



29
30
31
# File 'lib/passkit.rb', line 29

def dashboard_username
  @dashboard_username
end

#format_versionObject

Returns the value of attribute format_version.



29
30
31
# File 'lib/passkit.rb', line 29

def format_version
  @format_version
end

#pass_type_identifierObject

Returns the value of attribute pass_type_identifier.



29
30
31
# File 'lib/passkit.rb', line 29

def pass_type_identifier
  @pass_type_identifier
end

#private_p12_certificateObject

Returns the value of attribute private_p12_certificate.



29
30
31
# File 'lib/passkit.rb', line 29

def private_p12_certificate
  @private_p12_certificate
end

#skip_verificationObject

Returns the value of attribute skip_verification.



29
30
31
# File 'lib/passkit.rb', line 29

def skip_verification
  @skip_verification
end

#web_service_hostObject

Returns the value of attribute web_service_host.



29
30
31
# File 'lib/passkit.rb', line 29

def web_service_host
  @web_service_host
end

Instance Method Details

#authenticate_dashboard_with(&block) ⇒ Object



55
56
57
58
# File 'lib/passkit.rb', line 55

def authenticate_dashboard_with(&block)
  @authenticate = block if block
  @authenticate || DEFAULT_AUTHENTICATION
end

#configured?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/passkit.rb', line 77

def configured?
  REQUIRED_ATTRIBUTES.all? { |attr| send(attr).present? }
end

#verify!Object

Raises:



81
82
83
84
85
86
87
88
89
# File 'lib/passkit.rb', line 81

def verify!
  return if skip_verification

  REQUIRED_ATTRIBUTES.each do |attr|
    raise Error, "Please set #{attr.upcase}" unless send(attr).present?
  end

  raise Error, "PASSKIT_WEB_SERVICE_HOST must start with https://" unless web_service_host.start_with?("https://")
end