| 1 | package Net::Google::WebmasterTools::Request; | ||
| 2 | { | ||
| 3 | $Net::Google::WebmasterTools::Request::VERSION = '0.03'; | ||
| 4 | } | ||
| 5 | use strict; | ||
| 6 | |||
| 7 | # ABSTRACT: Google Webmaster Tools API request | ||
| 8 | |||
| 9 | use Class::XSAccessor accessors => [ | ||
| 10 | qw( | ||
| 11 | site_url | ||
| 12 | report_name | ||
| 13 | method | ||
| 14 | dimension | ||
| 15 | dimensions | ||
| 16 | dimension_filter_groups | ||
| 17 | operator | ||
| 18 | expression | ||
| 19 | sort | ||
| 20 | filters | ||
| 21 | segment | ||
| 22 | start_index row_limit | ||
| 23 | fields | ||
| 24 | pretty_print | ||
| 25 | user_ip quota_user | ||
| 26 | ) | ||
| 27 | ], | ||
| 28 | constructor => 'new'; | ||
| 29 | |||
| 30 | my @param_map = ( | ||
| 31 | dimensions => 'dimensions', | ||
| 32 | dimension_filter_groups => 'dimensionFilterGroups', | ||
| 33 | filters => 'filters', | ||
| 34 | dimension => 'dimension', | ||
| 35 | operator => 'operator', | ||
| 36 | expression => 'expression', | ||
| 37 | search_type => 'searchType', | ||
| 38 | start_date => 'startDate', | ||
| 39 | end_date => 'endDate', | ||
| 40 | row_limit => 'rowLimit', | ||
| 41 | pretty_print => 'prettyPrint', | ||
| 42 | user_ip => 'userIp', | ||
| 43 | quota_user => 'quotaUser', | ||
| 44 | ); | ||
| 45 | |||
| 46 | sub _params { | ||
| 47 | my $self = shift; | ||
| 48 | |||
| 49 | # for my $name (qw(site_url report_name)) { | ||
| 50 | # my $value = $self->{$name}; | ||
| 51 | # die("parameter $name is empty") | ||
| 52 | # if !defined($value) || $value eq ''; | ||
| 53 | # } | ||
| 54 | |||
| 55 | my %params; | ||
| 56 | |||
| 57 | for ( my $i = 0; $i < @param_map; $i += 2 ) { | ||
| 58 | my $from = $param_map[$i]; | ||
| 59 | my $to = $param_map[ $i + 1 ]; | ||
| 60 | |||
| 61 | my $value = $self->{$from}; | ||
| 62 | $params{$to} = $value if defined($value); | ||
| 63 | } | ||
| 64 | |||
| 65 | return %params; | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; | ||
| 69 | |||
| 70 | =pod | ||
| 71 | |||
| 72 | =head1 NAME | ||
| 73 | |||
| 74 | Net::Google::WebmasterTools::Request - Google Webmaster Tools API request | ||
| 75 | |||
| 76 | =head1 VERSION | ||
| 77 | |||
| 78 | version 0.03 | ||
| 79 | |||
| 80 | =head1 SYNOPSIS | ||
| 81 | |||
| 82 | my $req = $wmt->new_request( | ||
| 83 | site_url => "http://www.example.com", | ||
| 84 | report_name => "searchAnalytics", | ||
| 85 | method => "query", | ||
| 86 | dimensions => "[query,country,device]", | ||
| 87 | search_type => "web", | ||
| 88 | start_date => "2015-08-01", | ||
| 89 | end_date => "2015-08-05", | ||
| 90 | row_limit => 5, | ||
| 91 | ); | ||
| 92 | |||
| 93 | my $res = $wmt->retrieve($req); | ||
| 94 | |||
| 95 | =head1 DESCRIPTION | ||
| 96 | |||
| 97 | Request class for L<Net::Google::WebmasterTools> web service. | ||
| 98 | |||
| 99 | =head1 CONSTRUCTOR | ||
| 100 | |||
| 101 | =head2 new | ||
| 102 | |||
| 103 | my $req = Net::Google::WebmasterTools::Request->new(param => $value, ...); | ||
| 104 | my $req = $wmt->new_request(param => $value, ...); | ||
| 105 | |||
| 106 | Creates a new request object with the given parameters. You can also use the | ||
| 107 | shorthand L<Net::Google::WebmasterTools/new_request>. | ||
| 108 | |||
| 109 | =head1 ACCESSORS | ||
| 110 | |||
| 111 | $req->site_url('http://example.com'); | ||
| 112 | $req->method('query'); | ||
| 113 | |||
| 114 | See the | ||
| 115 | L<API reference|https://developers.google.com/webmaster-tools/v3/parameters> | ||
| 116 | for a description of the request parameters. The provided parameter values must | ||
| 117 | not be URL encoded. | ||
| 118 | |||
| 119 | =head2 site_url | ||
| 120 | |||
| 121 | Required | ||
| 122 | |||
| 123 | =head2 report_name | ||
| 124 | |||
| 125 | Required | ||
| 126 | |||
| 127 | =head2 method | ||
| 128 | |||
| 129 | Required | ||
| 130 | |||
| 131 | =head2 start_date | ||
| 132 | |||
| 133 | Required | ||
| 134 | |||
| 135 | =head2 end_date | ||
| 136 | |||
| 137 | Required | ||
| 138 | |||
| 139 | =head2 dimensions | ||
| 140 | |||
| 141 | =head2 row_limit | ||
| 142 | |||
| 143 | =head2 fields | ||
| 144 | |||
| 145 | =head2 pretty_print | ||
| 146 | |||
| 147 | =head2 user_ip | ||
| 148 | |||
| 149 | =head2 quota_user | ||
| 150 | |||
| 151 | =head1 AUTHOR | ||
| 152 | |||
| 153 | Nick Wellnhofer <wellnhofer@aevum.de> | ||
| 154 | |||
| 155 | =head1 COPYRIGHT AND LICENSE | ||
| 156 | |||
| 157 | This software is copyright (c) 2012 by Nick Wellnhofer. | ||
| 158 | |||
| 159 | This is free software; you can redistribute it and/or modify it under | ||
| 160 | the same terms as the Perl 5 programming language system itself. | ||
| 161 | |||
| 162 | =cut | ||
| 163 | |||
| 164 | __END__ |