Class: Camp3::Configuration

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/camp3/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.

"Camp3 Ruby Gem #{Camp3::VERSION}"

Instance Attribute Summary

Attributes included from Logging

#logger

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



25
26
27
28
29
30
# File 'lib/camp3/configuration.rb', line 25

def initialize(options = {})
  options[:user_agent] ||= DEFAULT_USER_AGENT
  VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key]) if options[key]
  end
end

Class Method Details

.base_api_endpointObject



69
70
71
# File 'lib/camp3/configuration.rb', line 69

def self.base_api_endpoint
  "https://3.basecampapi.com"
end

Instance Method Details

#api_endpointObject



59
60
61
62
63
# File 'lib/camp3/configuration.rb', line 59

def api_endpoint
  raise Camp3::Error::InvalidConfiguration, "missing basecamp account" unless self.
  
  "#{self.base_api_endpoint}/#{self.}"
end

#authz_endpointObject



51
52
53
# File 'lib/camp3/configuration.rb', line 51

def authz_endpoint
  'https://launchpad.37signals.com/authorization/new'
end

#base_api_endpointObject



65
66
67
# File 'lib/camp3/configuration.rb', line 65

def base_api_endpoint
  self.class.base_api_endpoint
end

#optionsObject

Creates a hash of options and their values.



33
34
35
36
37
# File 'lib/camp3/configuration.rb', line 33

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Resets all configuration options to the defaults.



40
41
42
43
44
45
46
47
48
49
# File 'lib/camp3/configuration.rb', line 40

def reset
  logger.debug "Resetting 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. = 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

#token_endpointObject



55
56
57
# File 'lib/camp3/configuration.rb', line 55

def token_endpoint
  'https://launchpad.37signals.com/authorization/token'
end