Sha256: 72ca0f98be9f480ba15fe0b6bb77b854969b32270956f05452ff8851dd1000c3

Contents?: true

Size: 1.81 KB

Versions: 75

Compression:

Stored size: 1.81 KB

Contents

require 'date'
require_relative 'base_client'

class AdopsReportScrapper::TripleliftClient < AdopsReportScrapper::BaseClient
  private

  def login
    @client.visit 'https://console.triplelift.com/login'
    @client.fill_in 'Email', :with => @login
    @client.fill_in 'Password', :with => @secret
    @client.click_button 'Sign in'
    begin
      @client.find :xpath, '//*[text()="Reporting"]'
    rescue Exception => e
      raise e, 'Triplelift login error'
    end
  end

  def scrap
    @date_str = @date.strftime('%B %d, %Y')
    @client.find(:xpath, '//*[text()="Reporting"]').click
    wait_for_spin
    @client.find(:xpath, '//button[contains(text(),"Last 7 days") or contains(text(),"Month to date") or contains(text(),"Custom")]').click
    @client.find(:xpath, '//a[contains(text(),"Yesterday")]').click
    sleep 1
    
    @client.find(:xpath, '//tl-checkbox/div/span[text()[normalize-space()="Placement"]]').click
    sleep 1
    @client.find(:xpath, '//tl-checkbox/div/span[text()[normalize-space()="Clicks"]]').click
    sleep 1
    @client.find(:xpath, '//*[text()[normalize-space()="Run query"]]').click
    sleep 10

    extract_data
  end

  def extract_data
    @data = []
    return if @client.find_all(:xpath, '//*[text()="No data available for selected date range"]').count > 0

    rows = @client.find_all :xpath, '//table/*/tr'
    rows = rows.to_a
    rows.pop
    header = rows.shift
    n_data = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
    if @data.count == 0
      n_header = header.find_css('td,th').map { |td| td.visible_text }
      @data << n_header
    end
    @data += n_data
  end

  def wait_for_spin
    30.times do |_i| # wait 5 min
      begin
        @client.find(:css, '.spinner')
      rescue Exception => e
        break
      end
      sleep 5
    end
    sleep 2
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
adops_report_scrapper-0.2.52 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.51 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.50 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.49 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.48 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.46 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.45 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.44 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.43 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.42 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.41 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.40 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.39 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.38 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.37 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.35 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.34 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.33 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.32 lib/adops_report_scrapper/triplelift_client.rb
adops_report_scrapper-0.2.31 lib/adops_report_scrapper/triplelift_client.rb