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, :custom_event_prefix
]
DEFAULT_LOGGER =
Logger.new(nil)
DEFAULT_BASE_URL =
"https://api.hubapi.com".freeze

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
37
38
39
40
41
42
# File 'lib/hubspot/config.rb', line 16

def configure(config)
  config.stringify_keys!
  @hapikey = config['hapikey']
  @base_url = config['base_url'] || DEFAULT_BASE_URL
  @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']
  @custom_event_prefix = config['custom_event_prefix']

  unless authentication_uncertain?
    raise Hubspot::ConfigurationError.new("You must provide either an access_token or an hapikey")
  end

  if hapikey.present?
    Hubspot::Deprecator.build.deprecation_warning("hapikey", "please use access_token instead. See https://developers.hubspot.com/docs/api/migrate-an-api-key-integration-to-a-private-app")
  end

  if access_token.present?
    Hubspot::Connection.headers("Authorization" => "Bearer #{access_token}")
  end
  self
end

.ensure!(*params) ⇒ Object



53
54
55
56
57
# File 'lib/hubspot/config.rb', line 53

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

.reset!Object



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

def reset!
  @hapikey = nil
  @base_url = DEFAULT_BASE_URL
  @portal_id = nil
  @logger = DEFAULT_LOGGER
  @access_token = nil
  Hubspot::Connection.headers({})
end