Class: Crm::Core::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/crm/core/configuration.rb

Overview

Configuration is yielded by Crm.configure. It lets you set the credentials for accessing the API. The tenant, login, and api_key attributes must be provided.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject



7
8
9
# File 'lib/crm/core/configuration.rb', line 7

def api_key
  @api_key
end

#endpointObject



11
12
13
# File 'lib/crm/core/configuration.rb', line 11

def endpoint
  @endpoint
end

#loggerObject



39
40
41
# File 'lib/crm/core/configuration.rb', line 39

def logger
  Crm::Core::LogSubscriber.logger
end

#loginObject



8
9
10
# File 'lib/crm/core/configuration.rb', line 8

def 
  @login
end

#tenantObject



9
10
11
# File 'lib/crm/core/configuration.rb', line 9

def tenant
  @tenant
end

Instance Method Details

#endpoint_uriObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/crm/core/configuration.rb', line 28

def endpoint_uri
  if endpoint.present?
    url = endpoint
    url = "https://#{url}" unless url.match(/^http/)
    url += '/' unless url.end_with?('/')
    URI.parse(url)
  else
    URI.parse("https://#{tenant}.crm.infopark.net/api2/")
  end
end

#validate!Object



57
58
59
60
61
62
63
# File 'lib/crm/core/configuration.rb', line 57

def validate!
  raise "Missing required configuration key: api_key" if api_key.blank?
  raise "Missing required configuration key: login" if .blank?
  if tenant.blank? && endpoint.blank?
    raise "Missing required configuration key: tenant"
  end
end