Sha256: 227e080490a9f574600dc86555ad6342b4e8bc792fbed23933bc3392d20f4aa2

Contents?: true

Size: 1.85 KB

Versions: 66

Compression:

Stored size: 1.85 KB

Contents

require 'date'
require_relative 'base_client'

class AdopsReportScrapper::BrightcomClient < AdopsReportScrapper::BaseClient
  private

  def login
    @client.visit 'https://compass.brightcom.com/'
    @client.fill_in 'Username', :with => @login
    @client.fill_in 'Password', :with => @secret
    @client.click_button 'Login'
    sleep 15
    begin
      @client.find :xpath, '//*[text()="Reports "]'
    rescue Exception => e
      raise e, 'Brightcom login error'
    end
  end

  def scrap
    request_report
    extract_data_from_report
  end

  def request_report
    @client.visit 'https://compass.brightcom.com/onetag/reportsext/display'
    sleep 5

    group_by_dest_elem = @client.find(:css, '#group_by_dest')
    @client.find(:xpath, '//div[text()="Tags" and @data-order="1"]').drag_to(group_by_dest_elem)
    @client.find(:xpath, '//div[text()="Country" and @data-order="2"]').drag_to(group_by_dest_elem)

    metrics_source_elem = @client.find(:css, '#metrics_source')
    metrics_dest_elem = @client.find(:css, '#metrics_dest')
    @client.find(:xpath, '//div[text()="Received IMPS" and @data-order="0"]').drag_to(metrics_dest_elem)
    @client.find(:xpath, '//div[text()="Clicks" and @data-order="3"]').drag_to(metrics_dest_elem)
    @client.find(:xpath, '//div[text()="Conversion Rate" and @data-order="6"]').drag_to(metrics_source_elem)
    @client.find(:xpath, '//div[text()="Revenue eCPM" and @data-order="8"]').drag_to(metrics_source_elem)

    @client.click_button 'Run Report'
    sleep 15
  end

  def extract_data_from_report
    rows = @client.find_all(:xpath, '//table[@role="grid"]/tbody/tr')
    rows = rows.to_a
    header = @client.find :xpath, '//table[@role="grid"]/thead/tr'
    n_header = header.find_css('td,th').map { |td| td.visible_text }
    @data = [n_header]
    @data += rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
adops_report_scrapper-0.2.52 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.51 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.50 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.49 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.48 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.46 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.45 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.44 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.43 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.42 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.41 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.40 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.39 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.38 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.37 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.35 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.34 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.33 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.32 lib/adops_report_scrapper/brightcom_client.rb
adops_report_scrapper-0.2.31 lib/adops_report_scrapper/brightcom_client.rb