Class: Hubspot::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/hubspot/config.rb

Constant Summary collapse

CONFIG_KEYS =
[
  :hapikey, :base_url, :portal_id, :logger, :access_token, :client_id,
  :client_secret, :redirect_uri, :read_timeout, :open_timeout
]
DEFAULT_LOGGER =
Logger.new(nil)

Class Method Summary collapse

Class Method Details

.configure(config) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hubspot/config.rb', line 16

def configure(config)
  config.stringify_keys!
  @hapikey = config["hapikey"]
  @base_url = config["base_url"] || "https://api.hubapi.com"
  @portal_id = config["portal_id"]
  @logger = config["logger"] || DEFAULT_LOGGER
  @access_token = config["access_token"]
  @client_id = config["client_id"] if config["client_id"].present?
  @client_secret = config["client_secret"] if config["client_secret"].present?
  @redirect_uri = config["redirect_uri"] if config["redirect_uri"].present?
  @read_timeout = config['read_timeout'] || config['timeout']
  @open_timeout = config['open_timeout'] || config['timeout']

  unless access_token.present? ^ hapikey.present?
    Hubspot::ConfigurationError.new("You must provide either an access_token or an hapikey")
  end
  if access_token.present?
    Hubspot::Connection.headers("Authorization" => "Bearer #{access_token}")
  end
  self
end

.ensure!(*params) ⇒ Object



47
48
49
50
51
# File 'lib/hubspot/config.rb', line 47

def ensure!(*params)
  params.each do |p|
    raise Hubspot::ConfigurationError.new("'#{p}' not configured") unless instance_variable_get "@#{p}"
  end
end

.reset!Object



38
39
40
41
42
43
44
45
# File 'lib/hubspot/config.rb', line 38

def reset!
  @hapikey = nil
  @base_url = "https://api.hubapi.com"
  @portal_id = nil
  @logger = DEFAULT_LOGGER
  @access_token = nil
  Hubspot::Connection.headers({})
end