class AdopsReportScrapper::BrowsiClient
Public Instance Methods
date_supported?(date = nil)
click to toggle source
# File lib/adops_report_scrapper/browsi_client.rb, line 6 def date_supported?(date = nil) _date = date || @date return true if _date >= Date.today - 30 false end
Private Instance Methods
extract_data_from_report()
click to toggle source
# File lib/adops_report_scrapper/browsi_client.rb, line 41 def extract_data_from_report rows = @client.find_all :xpath, '//li[@ng-class="{opened:site.isGraphOpen}"]' @data = [['Site', 'Revenues', 'Page Views']] @data += rows.map do |row| site = row.find_css('.header-full').first.visible_text rev = @client.find_all(:xpath, row.path+'//*[../span[text()="Revenues"]]').first.text pv = @client.find_all(:xpath, row.path+'//*[../span[text()="Page Views"]]').first.text [site, rev, pv] end end
login()
click to toggle source
# File lib/adops_report_scrapper/browsi_client.rb, line 14 def login @client.visit 'https://reports.brow.si' @client.fill_in 'Email', :with => @login @client.fill_in 'Password', :with => @secret @client.find(:xpath, '//*[text()="Login"]').click sleep 10 begin @client.find :css, '.ico-calendar' rescue Exception => e raise e, 'Browsi login error' end end
request_report()
click to toggle source
# File lib/adops_report_scrapper/browsi_client.rb, line 32 def request_report date_range_obj = { startDate: @date.to_time.utc.strftime('%FT%T.000Z'), endDate: (@date.to_time+86400-1).utc.strftime('%FT%T.999Z') } @client.visit "https://reports.brow.si/client/app/index.html#/report/home?dateRange=#{URI::encode(date_range_obj.to_json)}" sleep 30 end
scrap()
click to toggle source
# File lib/adops_report_scrapper/browsi_client.rb, line 27 def scrap request_report extract_data_from_report end