Sha256: d3444d092150f416ed892552064825627f8a898c9175b757c6c58c92019c1d1d

Contents?: true

Size: 1.38 KB

Versions: 108

Compression:

Stored size: 1.38 KB

Contents

require 'date'
require_relative 'base_client'

class AdopsReportScrapper::RevcontentClient < AdopsReportScrapper::BaseClient
  private

  def login
    @client.visit 'https://www.revcontent.com/login'
    @client.fill_in 'name', :with => @login
    @client.fill_in 'password', :with => @secret
    @client.click_button 'Sign In'
    begin
      @client.find :xpath, '//*[contains(text(),"Widgets")]'
    rescue Exception => e
      raise e, 'Revcontent login error'
    end
  end

  def scrap
    @client.find(:xpath, '//*[contains(text(),"Widgets")]').click
    @client.find(:css, '.fa.fa-calendar').click
    @client.find(:xpath, '//*[text()="Yesterday"]').click
    @data = []
    %w(desktoplg desktop tablet phone unknown).each do |device|
      request_report(device)
      extract_data_from_report(device)
    end
  end

  def request_report(device)
    @client.find(:css, '.fa.fa-desktop').click
    @client.find(:xpath, '//*[text()="All Devices"]').click
    @client.find(:css, '.fa.fa-desktop').click
    @client.check device
  end

  def extract_data_from_report(device)
    rows = @client.find_all :xpath, '//table/*/tr'
    rows = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
    header = rows.shift
    rows.shift
    if @data.count == 0
      header.unshift 'Device'
      @data << header
    end
    rows.each do |row|
      row.unshift device
    end
    @data += rows
  end
end

Version data entries

108 entries across 108 versions & 1 rubygems

Version Path
adops_report_scrapper-0.1.68 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.67 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.66 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.65 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.64 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.63 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.62 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.61 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.60 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.59 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.58 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.57 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.56 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.55 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.54 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.53 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.52 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.51 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.50 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.1.49 lib/adops_report_scrapper/revcontent_client.rb