| 1 | package WWW::GoDaddy::REST; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | #<<< NO perltidy - must be all on one line | ||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use version; our $VERSION = version->new('0.8'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | #>>> | ||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use File::Slurp qw( slurp ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use WWW::GoDaddy::REST::Resource; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use WWW::GoDaddy::REST::Schema; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use WWW::GoDaddy::REST::Util qw(abs_url json_encode json_decode is_json ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 4 | my $JSON_MIME_TYPE = 'application/json'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | has 'url' => ( | |||||||||||||||||||||||||||
| 22 | is => 'rw', | ||||||||||||||||||||||||||||
| 23 | isa => 'Str', | ||||||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||||||
| 25 | documentation => 'Base url of the REST service' | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 4 | has 'basic_username' => ( | |||||||||||||||||||||||||||
| 29 | is => 'rw', | ||||||||||||||||||||||||||||
| 30 | isa => 'Str', | ||||||||||||||||||||||||||||
| 31 | required => 0, | ||||||||||||||||||||||||||||
| 32 | documentation => 'Username portion if using basic auth' | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 4 | has 'basic_password' => ( | |||||||||||||||||||||||||||
| 36 | is => 'rw', | ||||||||||||||||||||||||||||
| 37 | isa => 'Str', | ||||||||||||||||||||||||||||
| 38 | required => 0, | ||||||||||||||||||||||||||||
| 39 | documentation => 'Password portion if using basic auth' | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 4 | has 'user_agent' => ( | |||||||||||||||||||||||||||
| 43 | is => 'rw', | ||||||||||||||||||||||||||||
| 44 | isa => 'Object', | ||||||||||||||||||||||||||||
| 45 | required => 1, | ||||||||||||||||||||||||||||
| 46 | default => \&default_user_agent, | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 4 | has 'schemas_file' => ( | |||||||||||||||||||||||||||
| 50 | is => 'rw', | ||||||||||||||||||||||||||||
| 51 | isa => 'Str', | ||||||||||||||||||||||||||||
| 52 | required => 0, | ||||||||||||||||||||||||||||
| 53 | documentation => 'Optional, cached copy of the schemas JSON to avoid HTTP round trip' | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 4 | has 'schemas' => ( | |||||||||||||||||||||||||||
| 57 | is => 'rw', | ||||||||||||||||||||||||||||
| 58 | isa => 'ArrayRef[WWW::GoDaddy::REST::Schema]', | ||||||||||||||||||||||||||||
| 59 | required => 1, | ||||||||||||||||||||||||||||
| 60 | lazy => 1, | ||||||||||||||||||||||||||||
| 61 | builder => '_build_schemas' | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 4 | has 'raise_http_errors' => ( | |||||||||||||||||||||||||||
| 65 | is => 'rw', | ||||||||||||||||||||||||||||
| 66 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 67 | required => 1, | ||||||||||||||||||||||||||||
| 68 | default => 1 | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub BUILD { | ||||||||||||||||||||||||||||
| 72 | 13 | ▶ | my ( $self, $params ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 13 | ▶ | if ( defined $params->{basic_username} or defined $params->{basic_password} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $params->{"basic_username"} or defined $params->{"basic_password"}
MC/DC100%2/2
defined $params->{"basic_username"} or defined $params->{"basic_password"}
defined $params->{"basic_username"}
defined $params->{"basic_password"}
Truth table100%3/3
A or B
A= defined $params->{"basic_username"}B= defined $params->{"basic_password"}
| |||||||||||||||||||||||||||||
| 75 | 3 | ▶ | if ( !defined $params->{basic_username} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 1 | confess 'Attribute (basic_username) is required if basic_password is provided'; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 2 | ▶ | if ( !defined $params->{basic_password} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 1 | confess 'Attribute (basic_password) is required if basic_username is provided'; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 11 | ▶ | if ( defined $params->{schemas_file} and !-e $params->{schemas_file} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $params->{"schemas_file"} and not -e $params->{"schemas_file"}
MC/DC100%2/2
defined $params->{"schemas_file"} and not -e $params->{"schemas_file"}
defined $params->{"schemas_file"}
not -e $params->{"schemas_file"}
Truth table100%3/3
A and not(B)
A= defined $params->{"schemas_file"}B= not -e $params->{"schemas_file"}
| |||||||||||||||||||||||||||||
| 84 | 1 | confess 'Attribute (schemas_file) must be a file that exists: ' . $params->{schemas_file}; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub query { | ||||||||||||||||||||||||||||
| 90 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
query: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 5 | my $type = shift; | |||||||||||||||||||||||||||
| 92 | 5 | return $self->schema($type)->query(@_); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub query_by_id { | ||||||||||||||||||||||||||||
| 96 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
query_by_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 6 | my $type = shift; | |||||||||||||||||||||||||||
| 98 | 6 | return $self->schema($type)->query_by_id(@_); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub create { | ||||||||||||||||||||||||||||
| 102 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 3 | my $type = shift; | |||||||||||||||||||||||||||
| 104 | 3 | return $self->schema($type)->create(@_); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub schema { | ||||||||||||||||||||||||||||
| 108 | 30 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
schema: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 30 | my $name = shift; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 30 | my @schemas = @{ $self->schemas() }; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 30 | return WWW::GoDaddy::REST::Schema->registry_lookup($name); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub schemas_url { | ||||||||||||||||||||||||||||
| 117 | 88 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
schemas_url: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 88 | ▶ | my $specific_name = shift || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 88 | my $base = $self->url; | |||||||||||||||||||||||||||
| 121 | 88 | my $path = sprintf( 'schemas/%s', $specific_name ); | |||||||||||||||||||||||||||
| 122 | 88 | return abs_url( $base, $path ); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | sub http_request_schemas_json { | ||||||||||||||||||||||||||||
| 126 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
http_request_schemas_json: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 1 | my $request = $self->build_http_request( 'GET', $self->schemas_url ); | |||||||||||||||||||||||||||
| 129 | 1 | my $response = $self->user_agent->request($request); | |||||||||||||||||||||||||||
| 130 | 1 | my $content = $response->content; | |||||||||||||||||||||||||||
| 131 | 1 | ▶ | if ( !$response->is_success && $self->raise_http_errors ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $response->is_success and $self->raise_http_errors
MC/DC0%0/2
not $response->is_success and $self->raise_http_errors
not $response->is_success
$self->raise_http_errors
Truth table33%1/3
not(A) and B
A= not $response->is_successB= $self->raise_http_errors
| |||||||||||||||||||||||||||||
| 132 | 0 | die($content); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 1 | return $content; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | sub http_request_as_resource { | ||||||||||||||||||||||||||||
| 138 | 21 | ▶ | my ( $self, $method, $url, $content ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
http_request_as_resource: called CC=4 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||
| 139 | 21 | my ( $struct_from_json, $http_response ) = $self->http_request( $method, $url, $content ); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 21 | my $resource = WWW::GoDaddy::REST::Resource->new_subclassed( | |||||||||||||||||||||||||||
| 142 | { client => $self, | ||||||||||||||||||||||||||||
| 143 | fields => $struct_from_json, | ||||||||||||||||||||||||||||
| 144 | http_response => $http_response | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 21 | ▶ | if ( !$http_response->is_success && $self->raise_http_errors ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $http_response->is_success and $self->raise_http_errors
MC/DC0%0/2
not $http_response->is_success and $self->raise_http_errors
not $http_response->is_success
$self->raise_http_errors
Truth table33%1/3
not(A) and B
A= not $http_response->is_successB= $self->raise_http_errors
| |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if ($EXCEPTIONS_BEING_CAUGHT) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 0 | die($resource); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | else { | ||||||||||||||||||||||||||||
| 153 | 0 | die( $resource->to_string ); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 21 | return $resource; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | sub http_request { | ||||||||||||||||||||||||||||
| 161 | 21 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
http_request: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 21 | my ( $method, $uri, $perl_data ) = @_; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 21 | $uri = abs_url( $self->url, $uri ); | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 21 | my $headers = undef; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 21 | my $content; | |||||||||||||||||||||||||||
| 169 | 21 | ▶ | if ( defined $perl_data ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 8 | $content = eval { json_encode($perl_data) }; | |||||||||||||||||||||||||||
| 171 | 8 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | confess "$@:\n$perl_data"; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | 8 | $headers = [ 'Content-type' => $JSON_MIME_TYPE ]; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 21 | my $request = $self->build_http_request( $method, $uri, $headers, $content ); | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 21 | my $response = $self->user_agent->request($request); | |||||||||||||||||||||||||||
| 180 | 21 | my $response_text = $response->content; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 21 | my $content_data; | |||||||||||||||||||||||||||
| 183 | 21 | ▶ | if ($response_text) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 20 | $content_data = eval { json_decode($response_text) }; | |||||||||||||||||||||||||||
| 185 | 20 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | confess "$@:\n$response_text"; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | else { | ||||||||||||||||||||||||||||
| 190 | 1 | $content_data = undef; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | 21 | ▶ | return wantarray ? ( $content_data, $response ) : $content_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | sub build_http_request { | ||||||||||||||||||||||||||||
| 196 | 22 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
build_http_request: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | 22 | my @params = @_; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 22 | my $request = HTTP::Request->new(@params); | |||||||||||||||||||||||||||
| 200 | 22 | ▶ | if ( defined $self->basic_username or defined $self->basic_password ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->basic_username or defined $self->basic_password
MC/DC0%0/2
defined $self->basic_username or defined $self->basic_password
defined $self->basic_username
defined $self->basic_password
Truth table33%1/3
A or B
A= defined $self->basic_usernameB= defined $self->basic_password
| |||||||||||||||||||||||||||||
| 201 | 0 | $request->authorization_basic( $self->basic_username, $self->basic_password ); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | 22 | return $request; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | sub default_user_agent { | ||||||||||||||||||||||||||||
| 207 | 11 | ▶ | my $ua = LWP::UserAgent->new( env_proxy => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
default_user_agent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 208 | 11 | $ua->default_headers->push_header( 'Accept' => $JSON_MIME_TYPE ); | |||||||||||||||||||||||||||
| 209 | 11 | return $ua; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | sub _build_schemas { | ||||||||||||||||||||||||||||
| 213 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_schemas: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 4 | my $schema_json; | |||||||||||||||||||||||||||
| 216 | 4 | ▶ | if ( $self->schemas_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 3 | $schema_json = slurp( $self->schemas_file ); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | else { | ||||||||||||||||||||||||||||
| 220 | 1 | $schema_json = $self->http_request_schemas_json; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 4 | my $struct = eval { json_decode($schema_json) }; | |||||||||||||||||||||||||||
| 224 | 4 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | confess "$@:\n$schema_json"; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | 4 | foreach my $schema_struct ( @{ $struct->{data} } ) { | |||||||||||||||||||||||||||
| 228 | 40 | my $schema = WWW::GoDaddy::REST::Resource->new_subclassed( | |||||||||||||||||||||||||||
| 229 | { client => $self, fields => $schema_struct } ); | ||||||||||||||||||||||||||||
| 230 | 40 | my $key = $schema->link('self'); | |||||||||||||||||||||||||||
| 231 | 40 | WWW::GoDaddy::REST::Schema->registry_add( $schema->id => $schema ); | |||||||||||||||||||||||||||
| 232 | 40 | WWW::GoDaddy::REST::Schema->registry_add( $key => $schema ); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 4 | return [ WWW::GoDaddy::REST::Schema->registry_list ]; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 4 | 1; | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =head1 NAME | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | WWW::GoDaddy::REST - Work with services conforming to the GDAPI spec | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | use WWW::GoDaddy::REST; | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | my $client = WWW::GoDaddy::REST->new({ | ||||||||||||||||||||||||||||
| 249 | url => 'https://example.com/v1', | ||||||||||||||||||||||||||||
| 250 | basic_username => 'theuser', | ||||||||||||||||||||||||||||
| 251 | basic_password => 'notsosecret' | ||||||||||||||||||||||||||||
| 252 | }); | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | # see docs for WWW::GoDaddy::REST::Resource for more info | ||||||||||||||||||||||||||||
| 255 | my $auto = $client->query_by_id('autos',$vehicle_id_number); | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | print $auto->f('make'); # get a field | ||||||||||||||||||||||||||||
| 258 | print $auto->f('model','S'); # set a field | ||||||||||||||||||||||||||||
| 259 | $saved_auto = $auto->save(); | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | my $resource = $auto->follow_link('link_name'); | ||||||||||||||||||||||||||||
| 262 | my $resource = $auto->do_action('drive', { lat => ..., lon => ...}); | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | my $new = $client->create('autos', { 'make' => 'Tesla', 'model' => 'S' }); | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | $auto->delete(); | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | my @autos = $client->query('autos',{ 'make' => 'tesla' }); | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | This client makes it easy to code against a REST API that is created using | ||||||||||||||||||||||||||||
| 273 | the Go Daddy (r) API Specification (GDAPI) L<https://github.com/godaddy/gdapi>. | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | You will typically only need three pieces of information: | ||||||||||||||||||||||||||||
| 276 | - base url of the api (this must include the version number) | ||||||||||||||||||||||||||||
| 277 | - username | ||||||||||||||||||||||||||||
| 278 | - password | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | =head1 SEARCHING AND FILTERS | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | There are two methods that deal with searching: C<query> and C<query_by_id>. | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | =head2 SEARCH BY ID | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | Example: | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | $resource = $client->query_by_id('schema_name','id'); | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | =head2 SEARCH WITH FILTER | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | Filters are hash references. The first level key is the field | ||||||||||||||||||||||||||||
| 293 | name that you are searching on. The value of the field is an array | ||||||||||||||||||||||||||||
| 294 | reference that has a list of hash references. | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | Full Syntax Example: | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | @items = $client->query( 'the_schema_name', | ||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||
| 300 | 'your_field_name' => [ | ||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||
| 302 | 'modifier' => 'your modifier like "eq" or "ne"', | ||||||||||||||||||||||||||||
| 303 | 'value' => 'your search value' | ||||||||||||||||||||||||||||
| 304 | }, | ||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||
| 306 | #... | ||||||||||||||||||||||||||||
| 307 | }, | ||||||||||||||||||||||||||||
| 308 | ], | ||||||||||||||||||||||||||||
| 309 | 'another_field' => ... | ||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | ); | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | Now there are shortcuts as well. | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | Single Field Equality Example: | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | @items = $client->query( 'the_schema_name', | ||||||||||||||||||||||||||||
| 318 | { 'your_field_name' => 'your search value' } | ||||||||||||||||||||||||||||
| 319 | ); | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | Assumed Equality Example: | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | @items = $client->query( 'the_schema_name', | ||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||
| 325 | 'your_field_name' => [ | ||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||
| 327 | # notice the missing 'modifier' key | ||||||||||||||||||||||||||||
| 328 | 'value' => 'your search value', | ||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | ], | ||||||||||||||||||||||||||||
| 331 | 'another_field' => 'equality search too' | ||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | ); | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | Attributes can be provided in the C<new> method and have corresponding | ||||||||||||||||||||||||||||
| 338 | methods to get/set the values. | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | =over 4 | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | =item url | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | Base URL for the web service. This must include the version portion of the | ||||||||||||||||||||||||||||
| 345 | URL as well. | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | Trailing slash can be present or left out. | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | Example: | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | $c = WWW::GoDaddy::REST->new( { | ||||||||||||||||||||||||||||
| 352 | url => 'https://example.com/v1' | ||||||||||||||||||||||||||||
| 353 | } ); | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | =item basic_username | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | The username or key you were assigned for the web service. | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | Example: | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | $c = WWW::GoDaddy::REST->new( { | ||||||||||||||||||||||||||||
| 362 | url => '...', | ||||||||||||||||||||||||||||
| 363 | basic_username => 'me', | ||||||||||||||||||||||||||||
| 364 | basic_password => '...' | ||||||||||||||||||||||||||||
| 365 | } ); | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | NOTE: not all web services authenticate using HTTP Basic Auth. In this case, | ||||||||||||||||||||||||||||
| 368 | you will need to provide your own C<user_agent> with default headers to | ||||||||||||||||||||||||||||
| 369 | accomplish authentication on your own. | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | =item basic_password | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | The password or secret you were assigned for the web service. | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | Example: | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | $c = WWW::GoDaddy::REST->new( { | ||||||||||||||||||||||||||||
| 378 | url => '...', | ||||||||||||||||||||||||||||
| 379 | basic_username => '...', | ||||||||||||||||||||||||||||
| 380 | basic_password => 'very_secret' | ||||||||||||||||||||||||||||
| 381 | } ); | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | NOTE: not all web services authenticate using HTTP Basic Auth. In this case, | ||||||||||||||||||||||||||||
| 384 | you will need to provide your own C<user_agent> with default headers to | ||||||||||||||||||||||||||||
| 385 | accomplish authentication on your own. | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | =item user_agent | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | The instance of L<LWP::UserAgent> that is used for all HTTP(S) interraction. | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | This has a sane default if you do not provide an instance yourself. | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | You may override this if you wish in the constructor or later on at runtime. | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | See the C<default_user_agent> in L<"CLASS METHODS">. | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | Example: | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | $ua = LWP::UserAgent->new(); | ||||||||||||||||||||||||||||
| 400 | $ua->default_headers->push_header( | ||||||||||||||||||||||||||||
| 401 | 'Authorization' => 'MyCustom ASDFDAFFASFASFSAFSDFAS==' | ||||||||||||||||||||||||||||
| 402 | ); | ||||||||||||||||||||||||||||
| 403 | $c = WWW::GoDaddy::REST->new({ | ||||||||||||||||||||||||||||
| 404 | url => '...', | ||||||||||||||||||||||||||||
| 405 | user_agent => $ua | ||||||||||||||||||||||||||||
| 406 | }); | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | =item schemas_file | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | Optional path to a file containing the JSON for all of the schemas for this web | ||||||||||||||||||||||||||||
| 411 | service (from the schemas collection). If you would like to avoid a round trip | ||||||||||||||||||||||||||||
| 412 | to the server at runtime, this is the way to do it. | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | Example: | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | $c = WWW::GoDaddy::REST->new({ | ||||||||||||||||||||||||||||
| 417 | url => '...', | ||||||||||||||||||||||||||||
| 418 | schemas_file => '/my/app/schema.json' | ||||||||||||||||||||||||||||
| 419 | }); | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | See the GDAPI Specification for more information about schemas and collections. | ||||||||||||||||||||||||||||
| 422 | L<https://github.com/godaddy/gdapi/blob/master/specification.md> | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | =item raise_http_errors | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | Boolean value that indicates whether a C<die()> will occur in the | ||||||||||||||||||||||||||||
| 427 | event of a non successful HTTP response (4xx 5xx etc). | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | It defaults to True. Set to a false value if you wish to check | ||||||||||||||||||||||||||||
| 430 | the HTTP response code in the resultant resource on your own. | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | =back | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | =head1 METHODS | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | =over 4 | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | =item query | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | Search for a list of resources given a schema name and a filter. | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | In scalar context, this returns a L<WWW::GoDaddy::REST::Collection> | ||||||||||||||||||||||||||||
| 443 | object. | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | In list context, this returns a list of L<WWW::GoDaddy::REST::Resource> | ||||||||||||||||||||||||||||
| 446 | objects (or subclasses). | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | Example: | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | @items = $client->query('schema_name',{ 'field' => 'value' }); | ||||||||||||||||||||||||||||
| 451 | $collection = $client->query('schema_name',{ 'field' => 'value' }); | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | See L<"SEARCHING AND FILTERS"> for more information. | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | =item query_by_id | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | Search for a single instance of a resource by its primary id. | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | This returns a L<WWW::GoDaddy::REST::Resource> (or a subclass). | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | Example: | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | $resource = $client->query_by_id('the_schema','the_id'); | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | =item create | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | Given a schema and a resource (or hashref), a POST will be made | ||||||||||||||||||||||||||||
| 468 | against the collection url of the schema to create the resource. | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | This returns a L<WWW::GoDaddy::REST::Resource> (or a subclass). | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | Example: | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | $car = $client->create('autos', { 'make' => 'Tesla', 'model' => 'S' }); | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | =item schema | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | Given a schema name, return a L<WWW::GoDaddy::REST::Schema> object or | ||||||||||||||||||||||||||||
| 479 | undef if it is not found. | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | Example: | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | $schema_resource = $client->schema('the_schema'); | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | =item schemas_url | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | If no schema name is provided, return the schema collection url where you can | ||||||||||||||||||||||||||||
| 488 | retrieve the collection of all schemas. | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | If a schema name is provided, return the URL where you can retrieve the schema | ||||||||||||||||||||||||||||
| 491 | with the given name. | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | Example: | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | $c = WWW::GoDaddy::REST->new({url => 'http://example.com/v1/'}); | ||||||||||||||||||||||||||||
| 496 | $c->schemas_url(); # http://example.com/v1/schemas/ | ||||||||||||||||||||||||||||
| 497 | $c->schemas_url('error'); # http://example.com/v1/schemas/error | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | =item http_request | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | Perform the HTTP request and return a hashref of the decoded JSON response. | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | If this is called in list context, it returns the decoded JSON response and | ||||||||||||||||||||||||||||
| 504 | the associated L<HTTP::Response> object. | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | This takes the following parameters (similar but not the same as L<HTTP::Request>): | ||||||||||||||||||||||||||||
| 507 | - HTTP method | ||||||||||||||||||||||||||||
| 508 | - URL relative to the web service base C<url> | ||||||||||||||||||||||||||||
| 509 | - Optional hashref of data to send as JSON content | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | The url provided will be rooted to the base url, C<url>. | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | Example: | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | $c = WWW::GoDaddy::REST->new({ | ||||||||||||||||||||||||||||
| 516 | url => 'http://example.com/v1/' | ||||||||||||||||||||||||||||
| 517 | }); | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | # GET http://example.com/v1/servers/Asdf | ||||||||||||||||||||||||||||
| 520 | $data_hashref = $c->http_request('GET','/servers/Asdf') | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | ($hash,$http_response) = $c->http_request('GET','/servers/Asdf'); | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | =item http_request_as_resource | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | Perform the HTTP request and return a L<WWW::GoDaddy::REST::Resource> instance. | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | This takes the following parameters (similar but not the same as L<HTTP::Request>): | ||||||||||||||||||||||||||||
| 529 | - HTTP method | ||||||||||||||||||||||||||||
| 530 | - URL relative to the web service base C<url> | ||||||||||||||||||||||||||||
| 531 | - Optional hashref of data to send as JSON content | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | The url provided will be rooted to the base url, C<url>. | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | The url provided will be rooted to the base url, C<url>. | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | Example: | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | $c = WWW::GoDaddy::REST->new({ | ||||||||||||||||||||||||||||
| 540 | url => 'http://example.com/v1/' | ||||||||||||||||||||||||||||
| 541 | }); | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | # GET http://example.com/v1/servers/Asdf | ||||||||||||||||||||||||||||
| 544 | $resource = $c->http_request_as_resource('GET','/servers/Asdf') | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | =item http_request_schemas_json | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | Retrieve the JSON string for the schemas collection. | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | Example: | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | $c = WWW::GoDaddy::REST->new({ | ||||||||||||||||||||||||||||
| 553 | url => 'http://example.com/v1/' | ||||||||||||||||||||||||||||
| 554 | }); | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | $schemas_json = $c->http_request_schemas_json(); | ||||||||||||||||||||||||||||
| 557 | # write this out to a file for later use | ||||||||||||||||||||||||||||
| 558 | # with the 'schemas_file' parameter for example | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | =item build_http_request | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | Given parameters for a L<HTTP::Request> object, return an instance | ||||||||||||||||||||||||||||
| 564 | of this object with certain defaults filled in. | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | As of this writing the defaults filled in are: | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | - HTTP basic auth headers if auth is provided | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | Unlike other methods such as C<http_request>, the C<url> is not rooted | ||||||||||||||||||||||||||||
| 571 | to the base url. | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | Example: | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | $c = WWW::GoDaddy::REST->new({ | ||||||||||||||||||||||||||||
| 577 | url => 'http://example.com/v1/' | ||||||||||||||||||||||||||||
| 578 | }); | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | $request = $c->build_http_request('GET','http://example.com/v1/test'); | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | =back | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | =over 4 | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | =item default_user_agent | ||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | Generate a default L<LWP::UserAgent>. See C<user_agent>. | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | Example: | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | $ua = WWW::GoDaddy::REST->default_user_agent(); | ||||||||||||||||||||||||||||
| 595 | $ua->default_headers->push('X-Custom' => 'thing'); | ||||||||||||||||||||||||||||
| 596 | $c = WWW::GoDaddy::REST->new({ | ||||||||||||||||||||||||||||
| 597 | user_agent => $ua, | ||||||||||||||||||||||||||||
| 598 | url => '...' | ||||||||||||||||||||||||||||
| 599 | }); | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | =back | ||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | C<gdapi-shell> command line program. | ||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | David Bartle, C<< <davidb@mediatemple.net> >> | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | Copyright (c) 2014 Go Daddy Operating Company, LLC | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | Permission is hereby granted, free of charge, to any person obtaining a | ||||||||||||||||||||||||||||
| 616 | copy of this software and associated documentation files (the "Software"), | ||||||||||||||||||||||||||||
| 617 | to deal in the Software without restriction, including without limitation | ||||||||||||||||||||||||||||
| 618 | the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||||||||||||||||||||||||||
| 619 | and/or sell copies of the Software, and to permit persons to whom the | ||||||||||||||||||||||||||||
| 620 | Software is furnished to do so, subject to the following conditions: | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | The above copyright notice and this permission notice shall be included in | ||||||||||||||||||||||||||||
| 623 | all copies or substantial portions of the Software. | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||||||||||||||||||||||||
| 626 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||||||||||||||||||||||
| 627 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||||||||||||||||||||||||||||
| 628 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||||||||||||||||||||||||
| 629 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||||||||||||||||||||||||||
| 630 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||||||||||||||||||||||||||
| 631 | DEALINGS IN THE SOFTWARE. | ||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | =cut | ||||||||||||||||||||||||||||