Class: OptimizelyServerSide::DatafileFetcher
- Inherits:
-
Object
- Object
- OptimizelyServerSide::DatafileFetcher
- Defined in:
- lib/optimizely_server_side/datafile_fetcher.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Responsible for fetching the optimizely sdk config from the API source.
-
#success ⇒ Object
readonly
Responsible for fetching the optimizely sdk config from the API source.
Class Method Summary collapse
-
.call_optimizely_cdn ⇒ Object
Gets data from Optimizely cdn.
- .fallback ⇒ Object
-
.fetch ⇒ Object
(also: datafile)
Fetch the Config from the specified source.
Instance Method Summary collapse
-
#initialize(content:, success:) ⇒ DatafileFetcher
constructor
A new instance of DatafileFetcher.
Constructor Details
#initialize(content:, success:) ⇒ DatafileFetcher
Returns a new instance of DatafileFetcher.
11 12 13 14 |
# File 'lib/optimizely_server_side/datafile_fetcher.rb', line 11 def initialize(content:, success:) @content = content @success = success end |
Instance Attribute Details
#content ⇒ Object (readonly)
Responsible for fetching the optimizely sdk config from the API source. The API can be optimizely cdn itself or any other source.
9 10 11 |
# File 'lib/optimizely_server_side/datafile_fetcher.rb', line 9 def content @content end |
#success ⇒ Object (readonly)
Responsible for fetching the optimizely sdk config from the API source. The API can be optimizely cdn itself or any other source.
9 10 11 |
# File 'lib/optimizely_server_side/datafile_fetcher.rb', line 9 def success @success end |
Class Method Details
.call_optimizely_cdn ⇒ Object
Gets data from Optimizely cdn
34 35 36 37 38 |
# File 'lib/optimizely_server_side/datafile_fetcher.rb', line 34 def call_optimizely_cdn Net::HTTP.get_response( URI(OptimizelyServerSide.configuration.config_endpoint) ) end |
.fallback ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/optimizely_server_side/datafile_fetcher.rb', line 40 def fallback new( content: '{"experiments": [],"version": "1","audiences": [],"dimensions": [],"groups": [],"projectId": "5960232316","accountId": "5955320306","events": [],"revision": "30"}', success: false ) end |
.fetch ⇒ Object Also known as: datafile
Fetch the Config from the specified source.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/optimizely_server_side/datafile_fetcher.rb', line 19 def fetch begin response = call_optimizely_cdn if response.is_a?(Net::HTTPSuccess) new(content: response.body, success: true) else fallback end rescue Exception => e fallback end end |