Sha256: 3285ae3153399524b84c39b9974b7d7f30fbc6cf22aac2d8958cd59a5b65cb22

Contents?: true

Size: 1014 Bytes

Versions: 2

Compression:

Stored size: 1014 Bytes

Contents

require 'mercury_web_parser/version'

module MercuryWebParser
  module Configuration
    VALID_CONNECTION_KEYS = [:api_endpoint, :user_agent].freeze
    VALID_OPTIONS_KEYS    = [:api_token].freeze
    VALID_CONFIG_KEYS     = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS

    DEFAULT_API_ENDPOINT  = 'https://mercury.postlight.com/parser'.freeze
    DEFAULT_USER_AGENT    = "MercuryWebParser Ruby Gem #{MercuryWebParser::VERSION}".freeze # rubocop:disable Metrics/LineLength
    DEFAULT_API_TOKEN     = nil

    attr_accessor(*VALID_CONFIG_KEYS)

    def self.extended(base)
      base.reset!
    end

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

    def options
      Hash[* VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten]
    end

    def reset!
      self.api_endpoint = DEFAULT_API_ENDPOINT
      self.user_agent   = DEFAULT_USER_AGENT

      self.api_token    = DEFAULT_API_TOKEN

      true
    end
  end # Configuration
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mercury_web_parser-0.1.2 lib/mercury_web_parser/configuration.rb
mercury_web_parser-0.1.0 lib/mercury_web_parser/configuration.rb