class AdopsReportScrapper::UndertoneClient
Public Instance Methods
date_supported?(date = nil)
click to toggle source
# File lib/adops_report_scrapper/undertone_client.rb, line 5 def date_supported?(date = nil) _date = date || @date return true if _date >= Date.today - 3 false end
Private Instance Methods
extract_data_from_po_report()
click to toggle source
# File lib/adops_report_scrapper/undertone_client.rb, line 64 def extract_data_from_po_report @client.within_window @client.driver.browser.window_handles.last do rows = @client.find_all :xpath, '//table/*/tr[not(contains(@class, "text"))]' rows = rows.to_a rows.pop rows.pop keys = rows.shift keys = keys.find_css('td,th').map { |td| td.visible_text } valuess = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } } l_data = valuess.map { |values| Hash[keys.zip(values)] } @data[0] << 'Revenue' l_data.each do |l_datum| @data.each_with_index do |datum, i| next if i == 0 next unless datum[0].downcase.tr(' ','').include? "-#{l_datum['Ad Unit'].downcase.tr(' ','')}-" @data[i] << datum[3].tr(',','').to_i * l_datum['Sales Price'].tr('USD','').to_f / 1000 end end end end
extract_data_from_zone_report()
click to toggle source
# File lib/adops_report_scrapper/undertone_client.rb, line 43 def extract_data_from_zone_report @client.within_window @client.driver.browser.window_handles.last do @data = [] rows = @client.find_all :xpath, '//table/*/tr[not(contains(@class, "text"))]' rows = rows.to_a rows.pop @data = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } } end end
login()
click to toggle source
# File lib/adops_report_scrapper/undertone_client.rb, line 13 def login @client.visit 'https://insights.undertone.com/user/login' @client.fill_in 'user_email', :with => @login @client.fill_in 'user_password', :with => @secret @client.click_button 'Sign In' begin @client.find :xpath, '//*[text()="Reporting"]' rescue Exception => e raise e, 'Undertone login error' end end
request_po_report()
click to toggle source
# File lib/adops_report_scrapper/undertone_client.rb, line 53 def request_po_report date_str = date.strftime('%m/%d/%Y') @client.fill_in 'start', :with => date_str @client.fill_in 'end', :with => date_str sleep 2 @client.select 'Purchase Order Summary', :from => 'report_id' sleep 2 @client.click_button 'html' sleep 10 end
request_zone_report()
click to toggle source
# File lib/adops_report_scrapper/undertone_client.rb, line 32 def request_zone_report date_str = date.strftime('%m/%d/%Y') @client.fill_in 'start', :with => date_str @client.fill_in 'end', :with => date_str sleep 2 @client.select 'Zone Report - Publishers', :from => 'report_id' sleep 2 @client.click_button 'html' sleep 10 end
scrap()
click to toggle source
# File lib/adops_report_scrapper/undertone_client.rb, line 25 def scrap request_zone_report extract_data_from_zone_report request_po_report extract_data_from_po_report end