class AdopsReportScrapper::AdtomationClient

Private Instance Methods

extract_data_from_report() click to toggle source
# File lib/adops_report_scrapper/adtomation_client.rb, line 32
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
login() click to toggle source
# File lib/adops_report_scrapper/adtomation_client.rb, line 7
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
request_report() click to toggle source
# File lib/adops_report_scrapper/adtomation_client.rb, line 25
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
scrap() click to toggle source
# File lib/adops_report_scrapper/adtomation_client.rb, line 20
def scrap
  request_report
  extract_data_from_report
end
wait_for_loading() click to toggle source
# File lib/adops_report_scrapper/adtomation_client.rb, line 39
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