Class: AdopsReportScrapper::BaseClient
- Inherits:
-
Object
- Object
- AdopsReportScrapper::BaseClient
- Defined in:
- lib/adops_report_scrapper/base_client.rb
Direct Known Subclasses
AdaptvClient, AdforgeClient, AdiplyClient, AdsenseClient, AdsparcClient, AdsupplyClient, AdsupplybuyerClient, AdtechusClient, AdtomationClient, AdxClient, AnyclipClient, AppnexusClient, BrightcomClient, BrightrollClient, BrowsiClient, ContentadClient, ConversantClient, CriteoClient, EmailClient, FacebookaudienceClient, GcsClient, GumgumClient, ImonomyClient, IndexexchangeClient, LittlethingsClient, LiveintentClient, LkqdClient, MarfeelClient, NativoClient, NetseerClient, OpenxClient, PopadsbuyerClient, PositivemobileClient, RevcontentClient, RhythmoneClient, RubiconClient, SonobiClient, SovrnClient, SpotxchangeClient, SpringserveClient, TremorClient, TripleliftClient, UndertoneClient, ZedoClient
Instance Method Summary collapse
- #before_quit_with_error ⇒ Object
-
#date_supported?(date = nil) ⇒ Boolean
by default only support yesterday.
-
#get_data(date = nil, options = nil) ⇒ Object
date: (optional) return data in array of array, first array is the headers, no total included.
- #init_client ⇒ Object
-
#initialize(login, secret, options = nil) ⇒ BaseClient
constructor
login: username, id, email, or api token secret: password or api secret options: { :date => (optional) default: yesterday }.
- #login ⇒ Object
-
#logout ⇒ Object
logout can be optional.
- #scrap ⇒ Object
Constructor Details
#initialize(login, secret, options = nil) ⇒ BaseClient
login: username, id, email, or api token secret: password or api secret options:
:date => (optional) default: yesterday
12 13 14 15 16 17 |
# File 'lib/adops_report_scrapper/base_client.rb', line 12 def initialize(login, secret, = nil) @login = login @secret = secret @options = || {} @date = @options[:date] || Date.today.prev_day end |
Instance Method Details
#before_quit_with_error ⇒ Object
66 67 68 |
# File 'lib/adops_report_scrapper/base_client.rb', line 66 def before_quit_with_error @client.save_screenshot end |
#date_supported?(date = nil) ⇒ Boolean
by default only support yesterday
71 72 73 74 75 |
# 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) ⇒ Object
date: (optional) return data in array of array, first array is the headers, no total included
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/adops_report_scrapper/base_client.rb', line 21 def get_data(date = nil, = nil) @date = date if date @options = @options.merge( || {}) 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 ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# 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 ⇒ Object
53 54 55 |
# File 'lib/adops_report_scrapper/base_client.rb', line 53 def login # do nothing by default end |
#logout ⇒ Object
logout can be optional
62 63 64 |
# File 'lib/adops_report_scrapper/base_client.rb', line 62 def logout # do nothing by default end |
#scrap ⇒ Object
57 58 59 |
# File 'lib/adops_report_scrapper/base_client.rb', line 57 def scrap # do nothing by default end |