Skip to content

Instantly share code, notes, and snippets.

@mattdees
Created September 27, 2012 02:10
Show Gist options
  • Save mattdees/3791771 to your computer and use it in GitHub Desktop.
Save mattdees/3791771 to your computer and use it in GitHub Desktop.
sub api_request {
my ($auth, $command, $args ) = @_;
my $authstr;
my $port;
$args ||= {};
my $server = $auth->{'server'};
my $access_hash = $auth->{'hash'};
my $user = $auth->{'user'};
$authstr = "WHM ${user}:${access_hash}";
$port = 2087;
my $http = HTTP::Tiny->new(
'default_headers' => {
'Authorization' => $authstr,
},
);
my $url = "https://${server}:${port}/json-api/${command}";
my $res = $http->post_form($url, $args);
if ( !exists $res->{'content'} ) {
print "Could not read response from $server\n";
return;
}
eval {
$res->{'decoded_content'} = JSON::Syck::Load($res->{'content'});
};
if ( $@ ) {
print "Could not decode content from $server\n";
}
return $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment