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

#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



150
151
152
153
154
# File 'lib/adwords_api/report_utils.rb', line 150

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_as_stream(report_definition, cid = nil, &block) ⇒ Object

Streams a report as a string to the given block. This method will not do error checking on returned values.

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



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

def download_report_as_stream(report_definition, cid = nil, &block)
  return get_report_response(report_definition, cid, &block)
end

#download_report_as_stream_with_awql(report_query, format, cid = nil, &block) ⇒ Object

Streams a report with AWQL as a string to the given block. This method will not do error checking on returned values.

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:

  • nil



167
168
169
170
# File 'lib/adwords_api/report_utils.rb', line 167

def download_report_as_stream_with_awql(
    report_query, format, cid = nil, &block)
  return get_report_response_with_awql(report_query, format, cid, &block)
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



132
133
134
# File 'lib/adwords_api/report_utils.rb', line 132

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

#get_stream_helper(report_definition, cid = nil) ⇒ Object

Returns a helper object that can manage breaking the streamed report results into individual lines.

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:

  • ReportStream object initialized to begin streaming.

Raises:

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



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

def get_stream_helper(report_definition, cid = nil)
  return AdwordsApi::ReportStream.set_up(
      self, report_definition, cid)
end

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

Returns a helper object that can manage breaking the streamed report results into individual lines.

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:

  • ReportStream object initialized to begin streaming.



183
184
185
186
# File 'lib/adwords_api/report_utils.rb', line 183

def get_stream_helper_with_awql(report_query, format, cid = nil)
  return AdwordsApi::ReportStream.set_up_with_awql(
      self, report_query, format, cid)
end