Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add $response->num_rows method

  • Loading branch information...
commit 7b6fcc846aa6befd44f8abcd16a39166e9df1485 1 parent 9bd6924
@nwellnhof authored
View
1  Changes
@@ -1,6 +1,7 @@
Revision history for Perl module Net::Google::Analytics
Next release
+ - Add $response->num_rows method
- Allow additional parameters to authorize_url
(Thanks to Masakazu Ohtsuka for the patch)
View
2  lib/Net/Google/Analytics.pm
@@ -223,7 +223,7 @@ the legacy v2 API.
# Print results
print
- "Results: 1 - ", $res->items_per_page,
+ "Results: 1 - ", $res->num_rows,
" of ", $res->total_results, "\n\n";
for my $row (@{ $res->rows }) {
View
12 lib/Net/Google/Analytics/Response.pm
@@ -70,6 +70,12 @@ sub _parse_column_name {
return $res;
}
+sub num_rows {
+ my $self = shift;
+
+ return scalar(@{ $self->rows });
+}
+
sub metrics {
my $self = shift;
@@ -179,7 +185,7 @@ Response class for L<Net::Google::Analytics> web service.
die("GA error: " . $res->error_message) if !$res->is_success;
print
- "Results: 1 - ", $res->items_per_page,
+ "Results: 1 - ", $res->num_rows,
" of ", $res->total_results, "\n\n";
for my $row (@{ $res->rows }) {
@@ -242,6 +248,10 @@ Returns true if the results contain sampled data.
A hashref containing information about the analytics profile.
+=head2 num_rows
+
+The number of rows on this result page.
+
=head2 rows
An arrayref of result rows of type L<Net::Google::Analytics::Row>.
View
4 t/01-test.t
@@ -1,7 +1,7 @@
#!perl -w
use strict;
-use Test::More tests => 42;
+use Test::More tests => 44;
our $expect_url;
our $content;
@@ -149,6 +149,7 @@ $res = $analytics->retrieve($req);
ok($res, 'retrieve data');
ok($res->is_success, 'retrieve success');
+is($res->num_rows, 5, 'num_rows');
is($res->total_results, 6451, 'total_results');
is($res->start_index, 1, 'start_index');
is($res->items_per_page, 5, 'items_per_page');
@@ -192,6 +193,7 @@ my $projection = $res->project([ 'domain_style' ], sub {
ok($projection, 'projection');
ok($projection->is_success, 'is_success of projection');
+is($projection->num_rows, 2, 'num_rows of projection');
is($projection->total_results, 2, 'total_results of projection');
is($projection->start_index, 1, 'start_index of projection');
is($projection->items_per_page, 2, 'items_per_page of projection');
Please sign in to comment.
Something went wrong with that request. Please try again.