GOOGLE-ADWORDS-PERL-CLIENT
view release on metacpan or search on metacpan
lib/Google/Ads/Common/ReportUtils.pm view on Meta::CPAN
my $report_result = shift;
if ($report_result =~ m/^!!![^|]*\|\|\|([^|]*)\|\|\|([^?]*)\?\?\?/) {
warn("Report download failed with error " . $2);
return $2;
}
return undef;
}
sub __extract_xml_error {
my $ref = XML::Simple->new()->XMLin(shift, ForceContent => 1);
return Google::Ads::Common::ReportDownloadError->new({
type => $ref->{ApiError}->{type}->{content},
field_path => $ref->{ApiError}->{fieldPath}->{content} ?
$ref->{ApiError}->{fieldPath}->{content} : "",
trigger => $ref->{ApiError}->{trigger}->{content} ?
$ref->{ApiError}->{trigger}->{content} : ""
});
}
return 1;
=pod
=head1 NAME
Google::Ads::Common::ReportUtils
=head1 SYNOPSIS
use Google::Ads::Common::ReportUtils;
Google::Ads::Common::ReportUtils::download_report($report_definition,
$client, $path);
=head1 DESCRIPTION
Google::Ads::Common::ReportUtils a collection of utility methods for working
with reports.
=head1 SUBROUTINES
=head2 download_report
Downloads a new instance of an existing report definition. If the file_path
parameter is specified it will be downloaded to the file at that path, otherwise
it will be downloaded to memory and be returned as a string.
=head3 Parameters
=over
=item *
The report_definition parameter is either:
- the id of a pre-defined report to download
- a C<ReportDefinition> object to be defined and download on the fly
- a hash with an AWQL query and format. i.e. { query => 'query',
format => 'format' }
In the case of a plain id then the regular download endpoint will be used to
download a pre-stored definition, otherwise the versioned download url endpoint
(based on the version of the given C<Client> object) will be used.
=item *
The client parameter is an instance of a valid L<Google::AdWords::Client>.
=item *
The file_path is an optional parameter that if given the subroutine will write
out the report to the given file path.
=item *
The server is an optional parameter that can be set to alter the URL from where
the report will be requested.
=item *
The return_money_in_micros is an optional parameter that can be set to alter
the output of money kind of fields in the report.
=item *
The timeout is an optional parameter that can be set to alter the default
time that the http client waits to get a response from the server. If not set,
the default timeout used is
L<Google::Ads::Common::ReportUtils::LWP_DEFAULT_TIMEOUT>.
=back
=head3 Returns
If a file_path is given, the report gets saved to file and the file size is
returned, if not the report data itself is returned.
=head3 Exceptions
Starting with v201209 of the API a L<Google::Ads::Common::ReportDownloadError>
object will be returned in case of a download error. If not passing a
C<file_path> to dump the report then you must check if the return
isa("Google::Ads::Common::ReportDownloadError").
Prior to v201209 a warn() will be issued if a report download error occurs.
=head1 LICENSE AND COPYRIGHT
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
( run in 3.430 seconds using v1.01-cache-2.11-cpan-d8267643d1d )