class AdopsReportScrapper::ImonomyClient
Public Instance Methods
date_supported?(date = nil)
click to toggle source
# File lib/adops_report_scrapper/imonomy_client.rb, line 5 def date_supported?(date = nil) _date = date || @date return true if _date >= Date.today - 7 false end
Private Instance Methods
extract_data_from_report()
click to toggle source
# File lib/adops_report_scrapper/imonomy_client.rb, line 46 def extract_data_from_report until @client.find(:xpath, '//*[text()=">"]')[:disabled] == "disabled" rows = @client.find_all :xpath, %Q{//table/tbody/tr[./td[text()="#{@date.strftime('%d.%m.%Y')}"]]} rows = rows.to_a if @data.count == 0 header = @client.find :xpath, '//table/thead/tr' n_header = header.find_css('td,th').map { |td| td.visible_text } @data << n_header end @data.concat rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } } @client.find(:xpath, '//*[text()=">"]').click sleep 1 end end
login()
click to toggle source
# File lib/adops_report_scrapper/imonomy_client.rb, line 13 def login @client.visit 'http://dashboard.imonomy.com/' @client.fill_in 'Username', :with => @login @client.fill_in 'Password', :with => @secret @client.click_button 'Sign In' begin @client.find :xpath, '//*[text()="My Statistics"]' rescue Exception => e raise e, 'Imonomy login error' end end
request_report()
click to toggle source
# File lib/adops_report_scrapper/imonomy_client.rb, line 32 def request_report @client.find(:xpath, '//*[text()="My Statistics"]').click @client.find(:xpath, '//option[text()="Last 7 Days"]').select_option @client.check 'Website' @client.check 'Country' @client.check 'Device' @client.click_link 'Submit' sleep 10 @client.find(:xpath, '//option[text()="100"]').select_option end
scrap()
click to toggle source
# File lib/adops_report_scrapper/imonomy_client.rb, line 25 def scrap @data = [] return if @date == Date.today - 1 # imonomy never update revenues for in 1 day request_report extract_data_from_report end