Module: K2Config

Defined in:
lib/k2-connect-ruby/k2_utilities/config/k2_config.rb

Overview

TODO: try to see if you can implement Environment variables

Class Method Summary collapse

Class Method Details

.network_operatorsObject



40
41
42
# File 'lib/k2-connect-ruby/k2_utilities/config/k2_config.rb', line 40

def network_operators
  @config[:network_operators]
end

.path_endpoint(key) ⇒ Object



24
25
26
27
28
29
# File 'lib/k2-connect-ruby/k2_utilities/config/k2_config.rb', line 24

def path_endpoint(key)
  unless key.include?('token')
    return "api/#{version}/#{@config[:endpoints][:"#{key}"]}"
  end
  @config[:endpoints][:"#{key}"]
end

.path_endpointsObject



31
32
33
# File 'lib/k2-connect-ruby/k2_utilities/config/k2_config.rb', line 31

def path_endpoints
  @config[:endpoints]
end

.path_url(key) ⇒ Object



35
36
37
38
# File 'lib/k2-connect-ruby/k2_utilities/config/k2_config.rb', line 35

def path_url(key)
  # TODO: Custom error/exception message
  base_url + path_endpoint(key)
end

.set_base_url(base_url) ⇒ Object

Set the Host Url

Raises:

  • (ArgumentError)


7
8
9
10
11
# File 'lib/k2-connect-ruby/k2_utilities/config/k2_config.rb', line 7

def set_base_url(base_url)
  raise ArgumentError, 'Invalid URL Format.' unless base_url =~ /\A#{URI.regexp(%w[http https])}\z/
  @config[:base_url] = base_url
  File.open("lib/k2-connect-ruby/k2_utilities/config/k2_config.yml", 'w') { |f| YAML.dump(@config, f) }
end

.set_version(version_number) ⇒ Object

TODO: Versioning

Raises:

  • (ArgumentError)


14
15
16
17
18
# File 'lib/k2-connect-ruby/k2_utilities/config/k2_config.rb', line 14

def set_version(version_number)
  raise ArgumentError, 'Invalid Format: Version Number input should be Numeric' unless version_number.is_a?(Numeric)
  @config[:version] = "v#{version_number}"
  File.open("lib/k2-connect-ruby/k2_utilities/config/k2_config.yml", 'w') { |f| YAML.dump(@config, f) }
end

.versionObject



20
21
22
# File 'lib/k2-connect-ruby/k2_utilities/config/k2_config.rb', line 20

def version
  @config[:version]
end