Class: AppnexusApi::LogLevelDataService

Inherits:
ReadOnlyService show all
Defined in:
lib/appnexusapi/services/log_level_data_service.rb

Direct Known Subclasses

LogLevelDataDownloadService

Constant Summary collapse

DEFAULT_FEED =
'standard_feed'.freeze
DOWNLOAD_URI =
'siphon-download'.freeze
RETRY_DOWNLOAD_PARAMS =
{
  base_interval: 30,
  tries: 20,
  max_elapsed_time: 3600,
  on: [AppnexusApi::Error, ::Faraday::Error::ClientError],
  on_retry: Proc.new do |exception, tries|
    AppnexusApi.config.logger.warn("Retrying after #{exception.class}: #{tries} attempts.")
  end
}.freeze

Constants inherited from Service

Service::DEFAULT_NUMBER_OF_ELEMENTS

Instance Method Summary collapse

Methods inherited from Service

#create, #delete, #get, #get_all, #name, #plural_name, #plural_uri_name, #update, #uri_suffix

Constructor Details

#initialize(connection, options = {}) ⇒ LogLevelDataService

Returns a new instance of LogLevelDataService.



15
16
17
18
19
# File 'lib/appnexusapi/services/log_level_data_service.rb', line 15

def initialize(connection, options = {})
  @downloaded_files_path = options[:downloaded_files_path] || '.'
  @siphon_name = options[:siphon_name] || DEFAULT_FEED
  super(connection)
end

Instance Method Details

#download_new_files_since(time = nil) ⇒ Object



21
22
23
# File 'lib/appnexusapi/services/log_level_data_service.rb', line 21

def download_new_files_since(time = nil)
  since(time).map { |siphon| download_resource(siphon) }
end

#since(time = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/appnexusapi/services/log_level_data_service.rb', line 29

def since(time = nil)
  params = {}
  params[:siphon_name] = @siphon_name if @siphon_name
  params[:updated_since] = time.strftime('%Y_%m_%d_%H') if time
  siphons = get(params) || {}

  # Anything with the same name and hour but with a newer timestamp is a republished replacement for an older file.
  # When this happens appnexus is supposed to set the checksum for the old file to NULL but they do not always
  # actually do this, so we have to manually reject invalid entries.
  siphons.reject do |siphon|
    (siphons - [siphon]).any? { |s| s.name == siphon.name && s.hour == siphon.hour && s.timestamp > siphon.timestamp }
  end
end

#uri_nameObject



25
26
27
# File 'lib/appnexusapi/services/log_level_data_service.rb', line 25

def uri_name
  'siphon'
end