Class: DataDuck::SEMRush::OrganicResults

Inherits:
IntegrationTable show all
Defined in:
lib/integrations/semrush/organic_results.rb

Instance Attribute Summary

Attributes inherited from Table

#data, #errors

Instance Method Summary collapse

Methods inherited from Table

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

Instance Method Details

#display_limitObject



6
7
8
# File 'lib/integrations/semrush/organic_results.rb', line 6

def display_limit
  25
end

#extract!(destination, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/integrations/semrush/organic_results.rb', line 26

def extract!(destination, options = {})
  dates = options[:dates]
  if dates.nil? || dates.length == 0
    raise Exception("Must pass at least one date.")
  end

  self.data = []

  self.phrases.each do |phrase|
    self.dates.each do |date|
      self.extract_results_for_keyword_and_date!(phrase, date)
    end
  end
end

#extract_results_for_keyword_and_date!(phrase, date) ⇒ Object



41
42
43
44
# File 'lib/integrations/semrush/organic_results.rb', line 41

def extract_results_for_keyword_and_date!(phrase, date)
  response = Typhoeus.get("http://api.semrush.com/?type=phrase_organic&key=#{ self.key }&display_limit=#{ self.display_limit }&export_columns=Dn,Ur&phrase=#{ phrase }&database=#{ self.search_database }")
  # TODO
end

#indexesObject



46
47
48
# File 'lib/integrations/semrush/organic_results.rb', line 46

def indexes
  ["date", "phrase", "domain"]
end

#keyObject



10
11
12
# File 'lib/integrations/semrush/organic_results.rb', line 10

def key
  ENV['semrush_api_key']
end

#phrasesObject



14
15
16
# File 'lib/integrations/semrush/organic_results.rb', line 14

def phrases
  raise Exception("Must implement phrases method to be an array of the phrases you want.")
end

#prefixObject



18
19
20
# File 'lib/integrations/semrush/organic_results.rb', line 18

def prefix
  "semrush_"
end

#search_databaseObject



22
23
24
# File 'lib/integrations/semrush/organic_results.rb', line 22

def search_database
  'us'
end