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.1.38 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.37 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.36 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.35 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.34 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.33 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.32 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.31 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.30 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.29 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.28 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.27 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.26 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.25 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.24 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.23 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.22 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.21 lib/adops_report_scrapper/adtomation_client.rb
adops_report_scrapper-0.1.20 lib/adops_report_scrapper/adtomation_client.rb