Sha256: 4142956e888d5ce4a00c73e1117616ad8af9e4cc6a50abd3e52f2a4e7a932d90

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module ExtendWarranties
  class Configuration
    attr_reader :sandbox, :base_url, :env, :access_token, :store_id, :headers

    REST_URLS = {
      sandbox:    'https://api-demo.helloextend.com',
      production: 'https://api.helloextend.com'
    }

    SANDBOX = :sandbox
    PRODUCTION = :production

    def initialize(args = {})
      validate_args(args)

      @env = args[:env].to_sym
      @sandbox = @env == SANDBOX
      @base_url = REST_URLS[env]
      @access_token = args[:access_token]
      @headers = args[:headers] || { 'Content-Type' => 'application/json', 'X-Extend-Access-Token' => @access_token }
      @store_id = args[:store_id]
    end

    private

    def validate_args(args)
      raise ArgumentError, 'access token is required' if args[:access_token].blank?
      raise ArgumentError, 'store id is required' if args[:store_id].blank?
      raise ArgumentError, 'env is required' if args[:env].blank?

      return if [SANDBOX, PRODUCTION].include?(args[:env].to_sym)
      raise ArgumentError, 'env must be of :sandbox or :production'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
extend_warranties-0.1.0 lib/extend_warranties/configuration.rb