Class: GaTrackable::BaseFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ga_trackable/base_fetcher.rb

Direct Known Subclasses

PageViewsFetcher, VideoPlaysFetcher

Constant Summary collapse

GA_DATE_FORMAT =
'%Y-%m-%d'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: GaTrackable.client, analytics: GaTrackable.analytics, config: GaTrackable.config) ⇒ BaseFetcher

Returns a new instance of BaseFetcher.



10
11
12
13
14
15
16
17
18
19
# File 'lib/ga_trackable/base_fetcher.rb', line 10

def initialize(
      client: GaTrackable.client,
      analytics: GaTrackable.analytics,
      config: GaTrackable.config
    )
  @client = client
  @analytics = analytics
  @config = config
  @sometime_processed_counters = []
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



7
8
9
# File 'lib/ga_trackable/base_fetcher.rb', line 7

def end_date
  @end_date
end

#sometime_processed_countersObject

Returns the value of attribute sometime_processed_counters.



8
9
10
# File 'lib/ga_trackable/base_fetcher.rb', line 8

def sometime_processed_counters
  @sometime_processed_counters
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



6
7
8
# File 'lib/ga_trackable/base_fetcher.rb', line 6

def start_date
  @start_date
end

Instance Method Details

#fetch_for_current_day!Object

Вытащить просмотры за текущий день. Метод может вызываться много раз, количество просмотров за текущий день будет обновляться.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ga_trackable/base_fetcher.rb', line 23

def fetch_for_current_day!
  @start_date = DateTime.current.beginning_of_day
  @end_date = DateTime.current

  self.sometime_processed_counters = []

  start_index = 1
  max_results = 1000

  begin
    rows = get_data(start_date, end_date, start_index, max_results).rows
    rows.each do |row|
      begin
        process_row(row, create_in_past: true)
      rescue => ex
        handle_exception(ex)
      end
    end
    start_index += max_results
  end while rows.size == max_results

  self.sometime_processed_counters = []
  true
end