Class: AdwordsApi::ReportUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/adwords_api/report_utils.rb

Instance Method Summary collapse

Constructor Details

#initialize(api, version) ⇒ ReportUtils

Default constructor.

Args:

  • api: AdwordsApi object

  • version: API version to use



37
38
39
# File 'lib/adwords_api/report_utils.rb', line 37

def initialize(api, version)
  @api, @version = api, version
end

Instance Method Details

#download_report(report_definition, cid = nil) ⇒ Object

Downloads and returns a report.

Args:

  • report_definition: definition of the report in XML text or hash

  • cid: optional customer ID to run against

Returns:

  • report body

Raises:

  • AdwordsApi::Errors::InvalidReportDefinitionError if the report definition is invalid

  • AdwordsApi::Errors::ReportError if server-side error occurred



55
56
57
# File 'lib/adwords_api/report_utils.rb', line 55

def download_report(report_definition, cid = nil)
  return get_report_response(report_definition, cid).body
end

#download_report_as_file(report_definition, path, cid = nil) ⇒ Object

Downloads a report and saves it to a file.

Args:

  • report_definition: definition of the report in XML text or hash

  • path: path to save report to

  • cid: optional customer ID to run against

Returns:

  • nil

Raises:

  • AdwordsApi::Errors::InvalidReportDefinitionError if the report definition is invalid

  • AdwordsApi::Errors::ReportError if server-side error occurred



74
75
76
77
78
# File 'lib/adwords_api/report_utils.rb', line 74

def download_report_as_file(report_definition, path, cid = nil)
  report_body = download_report(report_definition, cid)
  save_to_file(report_body, path)
  return nil
end