lib/desk/configuration.rb in desk-1.0.8 vs lib/desk/configuration.rb in desk-1.0.9

- old
+ new

@@ -1,16 +1,21 @@ require 'faraday' require 'desk/version' +require 'desk/authentication' module Desk # Defines constants and methods related to configuration module Configuration # An array of valid keys in the options hash when configuring a {Twitter::API} VALID_OPTIONS_KEYS = [ :adapter, + :auth_method, + :basic_auth_username, + :basic_auth_password, :consumer_key, :consumer_secret, + :domain, :format, :logger, :max_requests, :oauth_token, :oauth_token_secret, @@ -30,10 +35,22 @@ # The adapter that will be used to connect if none is set # # @note The default faraday adapter is Net::HTTP. DEFAULT_ADAPTER = Faraday.default_adapter + # By default, OAUTH is selected + DEFAULT_AUTH_METHOD = Desk::Authentication::Methods::OAUTH + + # By default, don't set a username + DEFAULT_BASIC_AUTH_USERNAME = nil + + # By default, don't set a password + DEFAULT_BASIC_AUTH_PASSWORD = nil + + # By default, use the desk.com hosted domain + DEFAULT_DOMAIN = "desk.com" + # By default, don't set an application key DEFAULT_CONSUMER_KEY = nil # By default, don't set an application secret DEFAULT_CONSUMER_SECRET = nil @@ -73,10 +90,11 @@ DEFAULT_VERSION = "v2".freeze # By default, don't set a support email address DEFAULT_SUPPORT_EMAIL = nil + attr_reader :DEFAULT_ADAPTER # @private attr_accessor *VALID_OPTIONS_KEYS # When this module is extended, set all configuration options to their default values def self.extended(base) @@ -99,10 +117,18 @@ def adapter=(val) Thread.current[:adapter] = val end + def auth_method + Thread.current[:auth_method] ||= DEFAULT_ADAPTER + end + + def auth_method=(val) + Thread.current[:auth_method] = val + end + def consumer_key Thread.current[:consumer_key] ||= DEFAULT_CONSUMER_KEY end def consumer_key=(val) @@ -115,10 +141,18 @@ def consumer_secret=(val) Thread.current[:consumer_secret] = val end + def domain + Thread.current[:domain] ||= DEFAULT_DOMAIN + end + + def domain=(val) + Thread.current[:domain] = val + end + def format Thread.current[:format] ||= DEFAULT_FORMAT end def format=(val) @@ -206,11 +240,15 @@ end # Reset all configuration options to defaults def reset self.adapter = DEFAULT_ADAPTER + self.auth_method = DEFAULT_AUTH_METHOD + self.basic_auth_username= DEFAULT_BASIC_AUTH_USERNAME + self.basic_auth_password= DEFAULT_BASIC_AUTH_PASSWORD self.consumer_key = DEFAULT_CONSUMER_KEY self.consumer_secret = DEFAULT_CONSUMER_SECRET + self.domain = DEFAULT_DOMAIN self.format = DEFAULT_FORMAT self.logger = DEFAULT_LOGGER self.max_requests = DEFAULT_MAX_REQUESTS self.oauth_token = DEFAULT_OAUTH_TOKEN self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET