Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/Net/Google/Analytics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use Net::Google::Analytics::Row;
use URI;

sub new {

my $package = shift;

my $self = bless({}, $package);
Expand Down Expand Up @@ -63,9 +64,12 @@ sub new_request {
}

sub _uri {
my ($self, $req, $start_index, $max_results) = @_;
my ($self, $req, $start_index, $max_results, $service) = @_;

$service = 'ga';
$service = 'realtime' if $req->service && $req->service eq 'realtime';
$service = 'mcf' if $req->service && $req->service eq 'mcf';

my $service = $req->realtime ? 'realtime' : 'ga';
my $uri = URI->new(
"https://www.googleapis.com/analytics/v3/data/$service"
);
Expand Down Expand Up @@ -376,4 +380,3 @@ Sets the L<LWP::UserAgent> object to use for HTTP(S) requests. You only
have to call this method if you want to provide your own user agent.

=cut

13 changes: 9 additions & 4 deletions lib/Net/Google/Analytics/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use warnings;

use Class::XSAccessor
accessors => [ qw(
service
realtime
ids
start_date end_date
Expand Down Expand Up @@ -43,7 +44,9 @@ sub _params {

my @required = qw(ids metrics);

if (!$self->{realtime}) {
if ($self->{realtime}) {
$self->{service} = 'realtime';
} else {
push(@required, qw(start_date end_date));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens too late (_param is called after _uri) and causes a test failure.

}

Expand Down Expand Up @@ -109,9 +112,12 @@ L<API reference|http://code.google.com/apis/analytics/docs/gdata/v3/reference.ht
for a description of the request parameters. The provided parameter values must
not be URL encoded.

=head2 realtime
=head2 service

Set this parameter to use the Real Time Reporting API.
Set this parameter to specify Core, Real Time or Multi-Channel Funnels Reporting API. Defaults to Core.

my $req = $analytics->new_request( service => 'realtime', ...);
my $req = $analytics->new_request( service => 'mcf', ...);

=head2 ids

Expand Down Expand Up @@ -152,4 +158,3 @@ Required
=head2 quota_user

=cut

3 changes: 1 addition & 2 deletions lib/Net/Google/Analytics/Response.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sub _parse_json {
sub _parse_column_name {
my $name = shift;

my ($res) = $name =~ /^(?:ga|rt):(\w{1,64})\z/
my ($res) = $name =~ /^(?:ga|mcf|rt):(\w{1,64})\z/
or die("invalid column name: $name");

# convert camel case
Expand Down Expand Up @@ -313,4 +313,3 @@ categories.
});

=cut