class VWO::GetSettings

Constants

HOSTNAME
PATH
PROTOCOL

Public Class Methods

new(account_id, sdk_key) click to toggle source
# File lib/vwo/get_settings.rb, line 16
def initialize(account_id, sdk_key)
  @account_id = account_id
  @sdk_key = sdk_key
end

Public Instance Methods

get() click to toggle source

Get method to retrieve settings_file for customer from dacdn server @param [string]: Account ID of user @param [string]: Unique sdk key for user,

can be retrieved from our website

@return: Json String representation of settings_file,

as received from the website,
nil if no settings_file is found or sdk_key is incorrect
# 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

Private Instance Methods

params() click to toggle source
# File lib/vwo/get_settings.rb, line 55
def params
  {
    a: @account_id,
    i: @sdk_key,
    r: VWO::Common::Utils.get_random_number,
    platform: 'server',
    'api-version' => 2
  }
end