Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
appointment_plus / lib / appointment_plus / configuration.rb
Size: Mime:
module AppointmentPlus
  module Configuration

    VALID_OPTIONS_KEYS = [
      :api_key,
      :site_id,
      :adapter,
      :endpoint,
      :logging
    ].freeze

    # By default don't set the api key.
    DEFAULT_API_KEY = nil

    # By default don't set the site_id
    DEFAULT_SITE_ID = nil

    # Use the default Faraday adapter.
    DEFAULT_ADAPTER = Faraday.default_adapter

    # By default use the main api URL.
    DEFAULT_ENDPOINT = 'https://ws.appointment-plus.com'.freeze

    # By default request JSON data to be returned from the API.
    DEFAULT_FORMAT = :json

    DEFAULT_LOGGING = false

    attr_accessor *VALID_OPTIONS_KEYS

    # Convenience method to allow configuration options to be set in a block
    def configure
      yield self
    end

    def options
      VALID_OPTIONS_KEYS.inject({}) do |option, key|
        option.merge!(key => send(key))
      end
    end

    # When this module is extended, reset all settings.
    def self.extended(base)
      base.reset
    end

    # Reset all configuration settings to default values.
    def reset
      self.api_key        = DEFAULT_API_KEY
      self.site_id        = DEFAULT_SITE_ID
      self.endpoint       = DEFAULT_ENDPOINT
      self.adapter        = DEFAULT_ADAPTER
      self.logging        = DEFAULT_LOGGING
    end
  end
end