Sha256: 83fe507a6baeea52b090ab2cb81958b05dce68d55759420a2544ce9527b8c136

Contents?: true

Size: 1.36 KB

Versions: 16

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true
module OptimizelyServerSide

  class DatafileFetcher
    # Responsible for fetching the optimizely sdk config from
    # the API source. The API can be optimizely cdn itself or
    # any other source.

    attr_reader :content, :success

    def initialize(content: nil, success: false)
      @content = content
      @success = success
    end

    class << self

      # Fetch the Config from the specified source.
      # Incase of any error or exception we goto the fallback data
      def fetch
        begin
          response = call_optimizely_cdn
          return fallback unless response.is_a?(Net::HTTPSuccess)
          new(content: response.body, success: true)
        rescue Exception => e
          fallback
        end
      end
      alias_method :datafile, :fetch

      # Gets data from Optimizely cdn
      def call_optimizely_cdn
        ActiveSupport::Notifications.instrument "oss.call_optimizely_cdn",this: :data  do
          Net::HTTP.get_response(
            URI(OptimizelyServerSide.configuration.config_endpoint)
          )
        end
      end

      def fallback
        new(
          content: '{"experiments": [],"version": "1","audiences": [],"dimensions": [],"groups": [],"projectId": "5960232316","accountId": "5955320306","events": [],"revision": "30"}',
          success: false
        )

      end
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
optimizely_server_side-1.2.0 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-1.0.1 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-1.0.0 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.18 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.17 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.16 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.15 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.14 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.13 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.12 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.11 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.10 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.9 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.8 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.7 lib/optimizely_server_side/datafile_fetcher.rb
optimizely_server_side-0.0.6 lib/optimizely_server_side/datafile_fetcher.rb