class AdopsReportScrapper::BaseClient
Public Class Methods
new(login, secret, options = nil)
click to toggle source
login: username, id, email, or api token secret: password or api secret options: {
:date => (optional) default: yesterday
}
# File lib/adops_report_scrapper/base_client.rb, line 12 def initialize(login, secret, options = nil) @login = login @secret = secret @options = options || {} @date = @options[:date] || Date.today.prev_day end
Public Instance Methods
before_quit_with_error()
click to toggle source
# File lib/adops_report_scrapper/base_client.rb, line 66 def before_quit_with_error @client.save_screenshot end
date_supported?(date = nil)
click to toggle source
by default only support yesterday
# File lib/adops_report_scrapper/base_client.rb, line 71 def date_supported?(date = nil) _date = date || @date return true if _date == Date.today.prev_day false end
get_data(date = nil, options = nil)
click to toggle source
date: (optional) return data in array of array, first array is the headers, no total included
# File lib/adops_report_scrapper/base_client.rb, line 21 def get_data(date = nil, options = nil) @date = date if date @options = @options.merge(options || {}) fail "specified date is not supported by this scrapper #{self.class.name}" unless date_supported? init_client login begin scrap rescue Exception => e begin before_quit_with_error logout rescue Exception => _e # do nothing end raise e end logout return @data end
init_client()
click to toggle source
# File lib/adops_report_scrapper/base_client.rb, line 42 def init_client Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path, :timeout => 60) end Capybara.default_max_wait_time = 10 @client = Capybara::Session.new(:poltergeist) @client.driver.browser.js_errors = false @client.driver.resize(1920, 985) @client.driver.execute_script('if (localStorage && localStorage.clear) localStorage.clear()') end
login()
click to toggle source
# File lib/adops_report_scrapper/base_client.rb, line 53 def login # do nothing by default end
logout()
click to toggle source
logout can be optional
# File lib/adops_report_scrapper/base_client.rb, line 62 def logout # do nothing by default end
scrap()
click to toggle source
# File lib/adops_report_scrapper/base_client.rb, line 57 def scrap # do nothing by default end