Class: Swrve::Configuration

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

Constant Summary collapse

DEFAULT_API_ENDPOINT =
'api.swrve.com'
DEFAULT_ABTEST_ENDPOINT =
'abtest.swrve.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



10
11
12
13
14
15
# File 'lib/swrve/configuration.rb', line 10

def initialize
  @app_version      = '0.0'
  @http_adapter     = Faraday.default_adapter
  @api_version      = 1
  @resource_timeout = 4
end

Instance Attribute Details

#ab_test_urlObject

Returns the value of attribute ab_test_url.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def ab_test_url
  @ab_test_url
end

#api_keyObject

Returns the value of attribute api_key.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def api_key
  @api_key
end

#api_urlObject

Returns the value of attribute api_url.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def api_url
  @api_url
end

#api_versionObject

Returns the value of attribute api_version.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def api_version
  @api_version
end

#app_versionObject

Returns the value of attribute app_version.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def app_version
  @app_version
end

#debugObject

Returns the value of attribute debug.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def debug
  @debug
end

#game_idObject

Returns the value of attribute game_id.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def game_id
  @game_id
end

#http_adapterObject

Returns the value of attribute http_adapter.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def http_adapter
  @http_adapter
end

#load_local_resourcesObject

Returns the value of attribute load_local_resources.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def load_local_resources
  @load_local_resources
end

#local_resource_pathObject

Returns the value of attribute local_resource_path.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def local_resource_path
  @local_resource_path
end

#resource_timeoutObject

Returns the value of attribute resource_timeout.



5
6
7
# File 'lib/swrve/configuration.rb', line 5

def resource_timeout
  @resource_timeout
end

Instance Method Details

#build_endpointsObject



17
18
19
20
21
# File 'lib/swrve/configuration.rb', line 17

def build_endpoints
  return if @api_url && @ab_test_url
  @api_url, @ab_test_url = [ "https://#{game_id}.#{DEFAULT_API_ENDPOINT}", 
                             "https://#{game_id}.#{DEFAULT_ABTEST_ENDPOINT}" ]
end

#validate!Object



23
24
25
26
27
28
# File 'lib/swrve/configuration.rb', line 23

def validate!
  [:game_id, :api_key].each do |check_valid|
    raise ConfigurationError, "#{check_valid} is a required configuration setting" if self.send(check_valid).nil?
  end
  warn 'app_version is a highly recommended configuration setting, defaulting to 0.0' if app_version == '0.0'
end