Sha256: b7faa63d22ea8a2168b87ef78ea9332bfcba58aeff3516675c48e6d0c7f23fed

Contents?: true

Size: 1.44 KB

Versions: 48

Compression:

Stored size: 1.44 KB

Contents

require 'date'
require_relative 'base_client'

class AdopsReportScrapper::SpringserveClient < AdopsReportScrapper::BaseClient
  private

  def login
    @client.visit 'http://video.springserve.com/'
    @client.fill_in 'Email', :with => @login
    @client.fill_in 'Password', :with => @secret
    @client.click_button 'Log in'
    begin
      @client.find :xpath, '//*[contains(text(),"Reporting")]'
    rescue Exception => e
      raise e, 'Springserve login error'
    end
  end

  def scrap
    request_report
    extract_data_from_report
  end

  def request_report
    @client.find(:xpath, '//*[contains(text(),"Reporting")]').click
    @client.find(:xpath, '//*[contains(text(),"Create Reports")]').click

    # select date
    @client.find(:css, '#date_range_chosen').click
    @client.find(:xpath, '//*[text()="Yesterday"]').click

    @client.find(:css, '#dimensions_chosen').click
    @client.find(:xpath, '//*[text()="Country"]').click

    @client.find(:xpath, '//*[@value="Run Report"]').click

    30.times do |_i| # wait 5 min
      begin
        @client.find(:css, '#spinner_image')
      rescue Exception => e
        break
      end
      sleep 10
    end
    sleep 10
  end

  def extract_data_from_report
    rows = @client.find_all :xpath, '//table[1]/*/tr'
    @data = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }.reject { |row| row[0] == 'Total' }
    @data = [] if @data.flatten.include? 'No data available in table'
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
adops_report_scrapper-0.1.60 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.59 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.58 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.57 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.56 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.55 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.54 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.53 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.52 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.51 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.50 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.49 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.48 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.47 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.46 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.45 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.44 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.43 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.42 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.41 lib/adops_report_scrapper/springserve_client.rb