CDS
view release on metacpan or search on metacpan
$o->{url} }
sub get {
my $o = shift;
my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
my $response = $o->request('GET', $o->{url}.'/objects/'.$hash->hex, HTTP::Headers->new);
return if $response->code == 404;
return undef, 'get ==> HTTP '.$response->status_line if ! $response->is_success;
return CDS::Object->fromBytes($response->decoded_content(charset => 'none'));
}
sub put {
my $o = shift;
my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
my $headers = HTTP::Headers->new;
$headers->header('Content-Type' => 'application/condensation-object');
my $boxLabel = shift;
my $timeout = shift;
my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
my $boxUrl = $o->{url}.'/accounts/'.$accountHash->hex.'/'.$boxLabel;
my $headers = HTTP::Headers->new;
$headers->header('Condensation-Watch' => $timeout.' ms') if $timeout > 0;
my $needsSignature = $boxLabel ne 'public';
my $response = $o->request('GET', $boxUrl, $headers, $keyPair, undef, $needsSignature);
return undef, 'list ==> HTTP '.$response->status_line if ! $response->is_success;
my $bytes = $response->decoded_content(charset => 'none');
if (length($bytes) % 32 != 0) {
print STDERR 'old procotol', "\n";
my $hashes = [];
for my $line (split /\n/, $bytes) {
push @$hashes, CDS::Hash->fromHex($line) // next;
}
return $hashes;
}
( run in 0.360 second using v1.01-cache-2.11-cpan-26ccb49234f )