Class: DataDuck::Optimizely::OptimizelyIntegration

Inherits:
OptimizelyTable show all
Defined in:
lib/integrations/optimizely/optimizely_integration.rb

Instance Attribute Summary

Attributes inherited from Table

#data, #errors

Instance Method Summary collapse

Methods inherited from OptimizelyTable

#optimizely_api_token, #should_fully_reload?

Methods inherited from Table

#actions, #batch_size, #building_name, #check_table_valid!, #distribution_key, #extract!, #extract_by_clause, #extract_by_column, #extract_query, #include_with_all?, #indexes, #limit_clause, #load!, #name, output, #output_column_names, #output_schema, #prefix, #recreate!, #should_fully_reload?, #show, source, #staging_name, #transform!, transforms, validates

Instance Method Details

#etl!(destinations, options = {}) ⇒ Object



4
5
6
7
# File 'lib/integrations/optimizely/optimizely_integration.rb', line 4

def etl!(destinations, options = {})
  projects = fetch_data("projects")
  # TODO alternate way to load Optimizely data
end

#fetch_data(api_endpoint) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/integrations/optimizely/optimizely_integration.rb', line 9

def fetch_data(api_endpoint)
  now = DateTime.now

  response = Typhoeus.get("https://www.optimizelyapis.com/experiment/v1/#{ api_endpoint }", headers: {'Token' => self.optimizely_api_token})
  if response.response_code != 200
    raise Exception.new("Optimizely API for #{ api_endpoint } returned error #{ response.response_code} #{ response.body }")
  end

  rows = Oj.load(response.body)
  rows.each do |row|
    row[:dataduck_extracted_at] = now
  end

  rows
end