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



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

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



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

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



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

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

#download_report_as_file_with_awql(report_query, format, path, cid = nil) ⇒ Object

Downloads a report with AWQL and saves it to a file.

Args:

  • report_query: query for the report as string

  • format: format for the report as string

  • path: path to save report to

  • cid: optional customer ID to run report against

Returns:

  • nil

Raises:

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



112
113
114
115
116
# File 'lib/adwords_api/report_utils.rb', line 112

def download_report_as_file_with_awql(report_query, format, path, cid = nil)
  report_body = download_report_with_awql(report_query, format, cid)
  save_to_file(report_body, path)
  return nil
end

#download_report_with_awql(report_query, format, cid = nil) ⇒ Object

Downloads and returns a report with AWQL.

Args:

  • report_query: query for the report as string

  • format: format for the report as string

  • cid: optional customer ID to run report against

Returns:

  • report body

Raises:

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



94
95
96
# File 'lib/adwords_api/report_utils.rb', line 94

def download_report_with_awql(report_query, format, cid = nil)
  return get_report_response_with_awql(report_query, format, cid).body
end