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.2.40 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.39 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.38 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.37 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.35 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.34 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.33 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.32 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.31 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.30 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.29 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.28 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.27 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.26 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.25 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.24 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.23 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.22 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.21 lib/adops_report_scrapper/revcontent_client.rb
adops_report_scrapper-0.2.20 lib/adops_report_scrapper/revcontent_client.rb