class VWO::Services::SettingsFileManager

Constants

HOSTNAME
PROTOCOL

Public Class Methods

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

Public Instance Methods

get_settings_file(is_via_webhook = false) click to toggle source

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

can be retrieved from VWO app

@return: JSON - settings_file,

as received from the server,
nil if no settings_file is found or sdk_key is incorrect
# File lib/vwo/services/settings_file_manager.rb, line 42
      def get_settings_file(is_via_webhook = false)
        is_valid_key = valid_number?(@account_id) || valid_string?(@account_id)

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

        if is_via_webhook
          path = ::VWO::CONSTANTS::ENDPOINTS::WEBHOOK_SETTINGS_URL
        else
          path = ::VWO::CONSTANTS::ENDPOINTS::SETTINGS_URL
        end
        vwo_server_url = "#{PROTOCOL}://#{HOSTNAME}#{path}"

        settings_file_response = ::VWO::Utils::Request.get(vwo_server_url, params)

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

Private Instance Methods

params() click to toggle source
# File lib/vwo/services/settings_file_manager.rb, line 75
def params
  {
    a: @account_id,
    i: @sdk_key,
    r: get_random_number,
    platform: 'server',
    'api-version' => 1
  }
end