Class: VWO::GetSettings

Inherits:
Object
  • Object
show all
Includes:
Common::Validations
Defined in:
lib/vwo/get_settings.rb

Constant Summary collapse

PROTOCOL =
'https'
HOSTNAME =
VWO::Common::CONSTANTS::ENDPOINTS::BASE_URL
PATH =
VWO::Common::CONSTANTS::ENDPOINTS::ACCOUNT_SETTINGS

Constants included from Common::Validations

Common::Validations::UTILITIES

Instance Method Summary collapse

Methods included from Common::Validations

#valid_hash?, #valid_number?, #valid_settings_file?, #valid_string?, #valid_utility?, #valid_value?

Constructor Details

#initialize(account_id, sdk_key) ⇒ GetSettings

Returns a new instance of GetSettings.



16
17
18
19
# File 'lib/vwo/get_settings.rb', line 16

def initialize(, sdk_key)
  @account_id = 
  @sdk_key = sdk_key
end

Instance Method Details

#getObject

Get method to retrieve settings_file for customer from dacdn server @return: Json String representation of settings_file,

as received from the website,
nil if no settings_file is found or sdk_key is incorrect

Parameters:

  • : (string)

    Account ID of user

  • : (string)

    Unique sdk key for user, can be retrieved from our website



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vwo/get_settings.rb', line 29

def get
  is_valid_key = valid_number?(@account_id) || valid_string?(@account_id)

  unless is_valid_key && valid_string?(@sdk_key)
    STDERR.puts 'account_id and sdk_key are required for fetching account settings. Aborting!'
    return '{}'
  end

  dacdn_url = "#{PROTOCOL}://#{HOSTNAME}#{PATH}"

  settings_file_response = VWO::Common::Requests.get(dacdn_url, params)

  if settings_file_response.code != '200'
    STDERR.puts <<-DOC
      Request failed for fetching account settings.
      Got Status Code: #{settings_file_response.code}
      and message: #{settings_file_response.body}.
    DOC
  end
  settings_file_response.body
rescue StandardError => e
  STDERR.puts "Error fetching Settings File #{e}"
end