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    
service_m8 / lib / service_m8 / configuration.rb
Size: Mime:
module ServiceM8
  module Configuration
    VALID_OPTIONS_KEYS = [
        :email,
        :password,
        :access_token,
        :api_version,
        :adapter,
        :endpoint
    ].freeze

    # By default don't set the email.
    DEFAULT_EMAIL = nil

    # By default don't set the password.
    DEFAULT_PASSWORD = nil

    # By default don't set the access token.
    DEFAULT_ACCESS_TOKEN = nil

    # By default use V1 of the API.
    DEFAULT_API_VERSION = "/api_1.0".freeze

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

    # By default use the main api URL.
    DEFAULT_ENDPOINT = 'api.servicem8.com'.freeze

    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.email = DEFAULT_EMAIL
      self.password = DEFAULT_PASSWORD
      self.password = DEFAULT_ACCESS_TOKEN
      self.api_version = DEFAULT_API_VERSION
      self.endpoint = DEFAULT_ENDPOINT
      self.adapter = DEFAULT_ADAPTER
    end
  end
end