require 'missionhub/version' module MissionHub # Defines constants and methods related to configuration module Config # The API Key if none is set DEFAULT_CLIENT_SECRET = nil # The endpoint that will be used to connect if none is set DEFAULT_SITE = 'https://www.missionhub.com/apis/v3' # An array of valid keys in the options hash when configuring a {Twitter::Client} VALID_OPTIONS_KEYS = [ :client_secret, :site, :organization_id ] # When this module is extended, set all configuration options to their default values def self.extended(base) base.reset end VALID_OPTIONS_KEYS.each do |attr| define_method(attr) do Thread.current["mission_hub.#{attr}"] end define_method("#{attr}=") do |val| Thread.current["mission_hub.#{attr}"] = val end end # Convenience method to allow configuration options to be set in a block def config yield self Base.site = Thread.current["mission_hub.site"] self end # Create a hash of options and their values def options options = {} VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)} options end # Reset all configuration options to defaults def reset self.client_secret = DEFAULT_CLIENT_SECRET self.site = DEFAULT_SITE self end end end