Sha256: 07cb812cf5669c98a5c6b3f10223a7bdc263e92b674d96fcefdfd8f9073b77cb

Contents?: true

Size: 1.86 KB

Versions: 30

Compression:

Stored size: 1.86 KB

Contents

require 'date'
require_relative 'base_client'

class AdopsReportScrapper::TremorClient < AdopsReportScrapper::BaseClient
  private

  def login
    @client.visit 'https://console.tremorhub.com/ssp'
    @client.fill_in 'username', :with => @login
    @client.fill_in 'password', :with => @secret
    @client.click_button 'Sign In'
    begin
      @client.find :xpath, '//*[text()="REPORTS"]'
    rescue Exception => e
      raise e, 'Tremor login error'
    end
  end

  def scrap
    request_report
    extract_data_from_report
  end

  def request_report
    @client.find(:xpath, '//*[text()="REPORTS"]').click
    @client.find(:xpath, '//*[text()="Custom"]').click
    sleep 1
    @client.find(:xpath, '//*[text()="New"]').click
    sleep 1
    # select group by
    @client.find(:css, '#availableFieldsListSearch').click
    @client.find(:xpath, '//*[text()="Supply Domain"]').click
    @client.find(:xpath, '//*[text()="Country"]').click
    @client.find(:xpath, '//*[text()="Ad Unit"]').click
    @client.find(:xpath, '//*[text()="Requests"]').click
    @client.find(:xpath, '//*[text()="Fills"]').click
    @client.find(:xpath, '//*[text()="Impressions"]').click
    @client.find(:xpath, '//*[text()="Completions"]').click
    @client.find(:xpath, '//*[text()="Total Net Revenue"]').click
    @client.find(:css, '.custom-report-dropdown-glyph.glyphicon-remove').click
    # select date
    @client.find(:css, '#customReportsDateRanges').click
    @client.find(:xpath, '//*[text()="Yesterday"]').click
    @client.click_button 'Run'
    sleep 10
    30.times do |_i| # wait 5 min
      begin
        @client.find(:xpath, '//*[text()="Please Hold"]')
      rescue Exception => e
        break
      end
      sleep 10
    end
  end

  def extract_data_from_report
    rows = @client.find_all :xpath, '//table/*/tr'
    @data = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
adops_report_scrapper-0.1.43 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.42 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.41 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.40 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.38 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.37 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.36 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.35 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.34 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.33 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.32 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.31 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.30 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.29 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.28 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.27 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.26 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.25 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.24 lib/adops_report_scrapper/tremor_client.rb
adops_report_scrapper-0.1.23 lib/adops_report_scrapper/tremor_client.rb