Class: Camper::Configuration
- Includes:
- Logging
- Defined in:
- lib/camper/configuration.rb
Overview
Defines constants and methods related to configuration.
Constant Summary collapse
- VALID_OPTIONS_KEYS =
An array of valid keys in the options hash when configuring a Basecamp::API.
%i[ client_id client_secret redirect_uri account_number refresh_token access_token user_agent ].freeze
- DEFAULT_USER_AGENT =
The user agent that will be sent to the API endpoint if none is set.
"Camper Ruby Gem #{Camper::VERSION}"
Instance Attribute Summary
Attributes included from Logging
Class Method Summary collapse
Instance Method Summary collapse
- #api_endpoint ⇒ Object
- #authz_endpoint ⇒ Object
- #base_api_endpoint ⇒ Object
-
#default_from_environment ⇒ Object
Resets all configuration options to the defaults.
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
-
#options ⇒ Object
Creates a hash of options and their values.
- #token_endpoint ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
25 26 27 28 29 30 |
# File 'lib/camper/configuration.rb', line 25 def initialize( = {}) default_from_environment VALID_OPTIONS_KEYS.each do |key| send("#{key}=", [key]) if [key] end end |
Class Method Details
.base_api_endpoint ⇒ Object
69 70 71 |
# File 'lib/camper/configuration.rb', line 69 def self.base_api_endpoint "https://3.basecampapi.com" end |
Instance Method Details
#api_endpoint ⇒ Object
59 60 61 62 63 |
# File 'lib/camper/configuration.rb', line 59 def api_endpoint raise Camper::Error::InvalidConfiguration, "missing basecamp account" unless self.account_number "#{self.base_api_endpoint}/#{self.account_number}" end |
#authz_endpoint ⇒ Object
51 52 53 |
# File 'lib/camper/configuration.rb', line 51 def authz_endpoint 'https://launchpad.37signals.com/authorization/new' end |
#base_api_endpoint ⇒ Object
65 66 67 |
# File 'lib/camper/configuration.rb', line 65 def base_api_endpoint self.class.base_api_endpoint end |
#default_from_environment ⇒ Object
Resets all configuration options to the defaults.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/camper/configuration.rb', line 40 def default_from_environment logger.debug 'Setting attributes to default environment values' self.client_id = ENV['BASECAMP3_CLIENT_ID'] self.client_secret = ENV['BASECAMP3_CLIENT_SECRET'] self.redirect_uri = ENV['BASECAMP3_REDIRECT_URI'] self.account_number = ENV['BASECAMP3_ACCOUNT_NUMBER'] self.refresh_token = ENV['BASECAMP3_REFRESH_TOKEN'] self.access_token = ENV['BASECAMP3_ACCESS_TOKEN'] self.user_agent = ENV['BASECAMP3_USER_AGENT'] || DEFAULT_USER_AGENT end |
#options ⇒ Object
Creates a hash of options and their values.
33 34 35 36 37 |
# File 'lib/camper/configuration.rb', line 33 def VALID_OPTIONS_KEYS.inject({}) do |option, key| option.merge!(key => send(key)) end end |
#token_endpoint ⇒ Object
55 56 57 |
# File 'lib/camper/configuration.rb', line 55 def token_endpoint 'https://launchpad.37signals.com/authorization/token' end |