Class: Mpql::Configuration

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

Constant Summary collapse

REGIONS =
{
  "us" => "https://mixpanel.com",
  "eu" => "https://eu.mixpanel.com",
  "in" => "https://in.mixpanel.com"
}.freeze
DATA_REGIONS =
{
  "us" => "https://data.mixpanel.com",
  "eu" => "https://data-eu.mixpanel.com",
  "in" => "https://data-in.mixpanel.com"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



21
22
23
24
25
26
27
28
29
# File 'lib/mpql/configuration.rb', line 21

def initialize
  @username = nil
  @secret = nil
  @project_id = nil
  @region = "us"

  load_config_file
  load_env
end

Instance Attribute Details

#project_idObject

Returns the value of attribute project_id.



19
20
21
# File 'lib/mpql/configuration.rb', line 19

def project_id
  @project_id
end

#regionObject

Returns the value of attribute region.



19
20
21
# File 'lib/mpql/configuration.rb', line 19

def region
  @region
end

#secretObject

Returns the value of attribute secret.



19
20
21
# File 'lib/mpql/configuration.rb', line 19

def secret
  @secret
end

#usernameObject

Returns the value of attribute username.



19
20
21
# File 'lib/mpql/configuration.rb', line 19

def username
  @username
end

Instance Method Details

#base_urlObject



31
32
33
# File 'lib/mpql/configuration.rb', line 31

def base_url
  REGIONS.fetch(@region, REGIONS["us"])
end

#data_base_urlObject



35
36
37
# File 'lib/mpql/configuration.rb', line 35

def data_base_url
  DATA_REGIONS.fetch(@region, DATA_REGIONS["us"])
end

#validate!Object

Raises:



39
40
41
42
43
44
45
46
# File 'lib/mpql/configuration.rb', line 39

def validate!
  errors = []
  errors << "MIXPANEL_USERNAME is not set" unless @username
  errors << "MIXPANEL_SECRET is not set" unless @secret
  errors << "project_id is not set" unless @project_id

  raise ConfigurationError, errors.join(", ") unless errors.empty?
end