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.2.11 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.10 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.9 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.8 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.7 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.6 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.5 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.4 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.3 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.2 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.2.1 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.69 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.68 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.67 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.66 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.65 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.64 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.63 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.62 lib/adops_report_scrapper/springserve_client.rb
adops_report_scrapper-0.1.61 lib/adops_report_scrapper/springserve_client.rb