Sha256: 25bdfbd9cc547094cb552ae3196e75b8bf9092fbcd6e8ad168d6a45b9bf3e85a

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

WCC::Auth::Config = Struct.new(:environment,
                               :app_name,
                               :app_url,
                               :app_url_protocol,
                               :app_id,
                               :app_secret,
                               :app_domain_suffix,
                               :authorize_site,
                               :authorize_path,
                               :authorize_params) do

  def authorize_site
    self[:authorize_site] || ENV['WCC_AUTHORIZE_SITE'] || default_authorize_site
  end

  def authorize_path
    self[:authorize_path] || ENV['WCC_AUTHORIZE_PATH'] || "/oauth/authorize"
  end

  def authorize_params
    self[:authorize_params] || {}
  end

  def app_url
    self[:app_url] || ENV['APP_URL'] || default_app_url
  end

  def app_url_protocol
    self[:app_domain_suffix] || default_app_url_protocol
  end

  def app_domain_suffix
    self[:app_domain_suffix] || default_app_domain_suffix
  end

  def nucleus_url
    return ENV['NUCLEUS_URL'] if ENV['NUCLEUS_URL']

    case environment.to_sym
    when :production
      "https://login.watermark.org"
    when :staging
      "http://login.staging.watermark.org"
    when :development
      "http://login.dev"
    end
  end

  private

  def default_app_url
    "#{app_url_protocol}://#{app_name}#{app_domain_suffix}"
  end

  def default_app_url_protocol
    case environment.to_sym
    when :production
      "https"
    else
      "http"
    end
  end

  def default_app_domain_suffix
    case environment.to_sym
    when :production
      ".watermark.org"
    when :staging
      ".staging.watermark.org"
    when :development
      ".dev"
    end
  end

  def default_authorize_site
    nucleus_url
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wcc-auth-0.3.3 lib/wcc/auth/config.rb
wcc-auth-0.3.2 lib/wcc/auth/config.rb