Sha256: c362a658b1288117e424d3d61b0539454fccb9be8898b9bacae46f8845b18c3b

Contents?: true

Size: 1.17 KB

Versions: 99

Compression:

Stored size: 1.17 KB

Contents

require 'date'
require_relative 'base_client'

class AdopsReportScrapper::AdtomationClient < AdopsReportScrapper::BaseClient
  private

  def login
    @client.visit 'http://console.adtomation.com/'
    @client.fill_in 'Username', :with => @login
    @client.fill_in 'Password', :with => @secret
    @client.click_button 'Sign In'

    begin
      @client.find :xpath, '//*[text()="Reporting"]'
    rescue Exception => e
      raise e, 'Adtomation login error'
    end
  end

  def scrap
    request_report
    extract_data_from_report
  end

  def request_report
    @client.click_link 'Your Reports'
    @client.find(:xpath, '//*[../../../../../td[text()="report created by adops report scrapper"] and contains(text(),"Run")]').click
    sleep 5
    wait_for_loading
  end

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

  def wait_for_loading
    30.times do |_i| # wait 5 min
      begin
        @client.find(:xpath, '//*[text()="Loading..."]')
      rescue Exception => e
        break
      end
      sleep 10
    end
    sleep 2
  end
end

Version data entries

99 entries across 99 versions & 1 rubygems

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