API-ParallelsWPB
view release on metacpan or search on metacpan
lib/API/ParallelsWPB.pm view on Meta::CPAN
$data->{req_type} ||= 'GET';
$data->{req_type} = uc $data->{req_type};
#compile URL
my $url = 'https://' . $self->{server} . '/api/' . $self->{api_version} . '/';
$url .= join( '/', @{ $url_array }) . '/';
my $post_data;
if ( $data->{req_type} eq 'POST' || $data->{req_type} eq 'PUT' ) {
$data->{post_data} ||= {};
unless ( ref $data->{post_data} eq 'HASH' || ref $data->{post_data} eq 'ARRAY' ) {
confess "parameter post_data must be hashref or arrayref!"
}
$post_data = $self->_json->encode($data->{post_data});
}
$post_data ||= '{}';
my $response = $self->_send_request($data, $url, $post_data);
return $response;
}
sub _send_request {
my ( $self, $data, $url, $post_data ) = @_;
my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new( $data->{req_type} => $url );
if ( $data->{req_type} eq 'POST' || $data->{req_type} eq 'PUT' ) {
$req->header( 'content-type' => 'application/json' );
$req->content( $post_data );
}
$req->authorization_basic( $self->{username}, $self->{password} );
$ua->ssl_opts( verify_hostname => 0 );
$ua->timeout( $self->{timeout} );
warn $req->as_string if ( $self->{debug} );
t/04_requests.t view on Meta::CPAN
my $p = $client->get_request_params;
like(
$p->{url},
qr{/api/5.3/sites/[\d\w\-]+/},
'URL for change_site_properties is ok'
);
like( $p->{post_data}, qr{"state":"trial"}, 'post_data for change_site_properties is ok' );
is( $p->{data}->{req_type}, 'PUT', 'Reqtype for change_site_properties is ok' );
};
# /api/5.3/sites/{siteUuid}/publish
subtest 'publish' => sub {
$client->publish(
uuid => '6d3f6f9f-55b2-899f-5fb4-ae04b325e360',
);
my $p = $client->get_request_params;
t/04_requests.t view on Meta::CPAN
uuid => '6d3f6f9f-55b2-899f-5fb4-ae04b325e360',
);
my $p = $client->get_request_params;
like(
$p->{url},
qr{/api/5.3/sites/[\d\w\-]+/custom-properties},
'URL for set_site_custom_variable is ok'
);
is( $p->{data}->{req_type}, 'PUT', 'Reqtype for set_site_custom_variable is ok' );
};
# /api/5.3/sites/{site_uuid}/custom-properties
subtest 'get_sites_custom_variables' => sub {
$client->get_sites_custom_variables;
my $p = $client->get_request_params;
like(
$p->{url},
qr{/api/5.3/system/custom-properties},
t/04_requests.t view on Meta::CPAN
subtest 'set_sites_custom_variables' => sub {
$client->set_sites_custom_variables;
my $p = $client->get_request_params;
like(
$p->{url},
qr{/api/5.3/system/custom-properties},
'URL for set_sites_custom_variables is ok'
);
is( $p->{data}->{req_type}, 'PUT', 'Reqtype for set_sites_custom_variables is ok' );
};
# /api/5.3/sites/{site_uuid}/custom-properties
subtest 'set_custom_trial_messages' => sub {
$client->set_custom_trial_messages;
my $p = $client->get_request_params;
like(
$p->{url},
qr{/api/5.3/system/trial-mode/messages},
'URL for set_custom_trial_messages is ok'
);
is( $p->{data}->{req_type}, 'PUT', 'Reqtype for set_custom_trial_messages is ok' );
};
# /api/5.3/sites/{site_uuid}/custom-properties
subtest 'get_custom_trial_messages' => sub {
$client->get_custom_trial_messages;
my $p = $client->get_request_params;
like(
$p->{url},
qr{/api/5.3/system/trial-mode/messages},
t/04_requests.t view on Meta::CPAN
my $p = $client->get_request_params;
like(
$p->{url},
qr{/api/5.3/system/promo-footer},
'URL for change_promo_footer is ok'
);
is( $p->{post_data}, q/["test"]/, 'Post data for change_promo_footer is ok');
is( $p->{data}->{req_type}, 'PUT', 'Reqtype for change_promo_footer is ok' );
};
done_testing;
( run in 0.283 second using v1.01-cache-2.11-cpan-4e96b696675 )