@s_moles ,
I wrote a PERL module this morning that would call the API. It works with limited testing (the dump) and it's not complete (I like to add methods for all of the API calls rather than making the end-user specify the URL themselves), but here's what I found so far:
You need to the Digest::SHA module and in particular, the hmac_sha256_base64 procedure.
use Digest::SHA qw{hmac_sha256_base64};
Assuming that you can generate the message as shown in the examples, then the line to generate the HMAC code is this:
my $hmac = hmac_sha256_base64( $message, $secret );
But then there's one additional gotcha. The PERL implementations don't automatically pad the code to the proper length. The length needs to be a multiple of 4 and you add equal signs to the end if it's not.
This can be fixed as such:
while ( length($hmac) % 4 ) {
$hmac .= '=';
}
Depending on how you want to dump your data, there is an issue of a lack of true and false values in PER, instead we use 1 and 0 respectively. The JSON decoders, and this seems pretty common, is to create objects for true and false and then make them act like 1 and 0. So you should be able to say something like if ($item->{'finished'}) { } to see if an dump has been finished.
The following code snippets are other places you might want some help. They probably won't run alone, but incorporated into the bigger picture, it all works.
You can also use HTTP::Date to get the proper date format.
use HTTP::Date;
my $timestamp = time2str();
After reading the documentation, it appears that decode_json() is preferred to from_json.
use LWP::UserAgent;
use JSON qw{decode_json};
my $json;
my $ua = LWP::UserAgent->new;
my $headers = HTTP::Headers->new(
'Authorization' => 'HMACAuth ' . $api_key . ':' . $hmac,
'Date' => $timestamp,
);
my $request = HTTP::Request->new( $method, $uri, $headers );
my $response = $ua->request($request);
if ( $response->is_success ) {
$json = decode_json( $response->decoded_content );
}
else {
print( STDERR $response->status_line() );
}
I apologize for the mix of procedural and object-orientated programming. I am trying to switch most of my coding over to OO, but sometimes, when you just need one function from another module like Digest::SHA, it's quicker to use the procedural approach.
Hopefully you'll get something useful out of this. I'll try to get the code posted somewhere once it's done, but you may not want to wait that long.
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.