Azure-Storage-Blob-Client

 view release on metacpan or  search on metacpan

lib/Azure/Storage/Blob/Client/Call.pm  view on Meta::CPAN

package Azure::Storage::Blob::Client::Call;
use Moose::Role;

requires 'endpoint';
requires 'method';
requires 'operation';

sub serialize_uri_parameters {
  my $self = shift;
  return {
    map { $_ => $self->$_ }
    grep { $self->meta->get_attribute($_)->does('URIParameter') }
    $self->meta->get_attribute_list()
  };

lib/Azure/Storage/Blob/Client/Call/DeleteBlob.pm  view on Meta::CPAN

package Azure::Storage::Blob::Client::Call::DeleteBlob;
use Moose;
use Azure::Storage::Blob::Client::Exception;
use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::HeaderParameter;

has operation => (is => 'ro', init_arg => undef, default => 'DeleteBlob');
has endpoint => (is => 'ro', init_arg => undef, lazy => 1, default => sub {
  my $self = shift;
  return sprintf(
    'https://%s.blob.core.windows.net/%s/%s',
    $self->account_name,
    $self->container,
    $self->blob_name,
  );
});
has method => (is => 'ro', init_arg => undef, default => 'DELETE');

lib/Azure/Storage/Blob/Client/Call/GetBlobProperties.pm  view on Meta::CPAN

package Azure::Storage::Blob::Client::Call::GetBlobProperties;
use Moose;
use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::HeaderParameter;

has operation => (is => 'ro', init_arg => undef, default => 'GetBlobProperties');
has endpoint => (is => 'ro', init_arg => undef, lazy => 1, default => sub {
  my $self = shift;
  return sprintf(
    'https://%s.blob.core.windows.net/%s/%s',
    $self->account_name,
    $self->container,
    $self->blob_name,
  );
});
has method => (is => 'ro', init_arg => undef, default => 'HEAD');

lib/Azure/Storage/Blob/Client/Call/ListBlobs.pm  view on Meta::CPAN

package Azure::Storage::Blob::Client::Call::ListBlobs;
use Moose;
use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::URIParameter;
use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::HeaderParameter;
use XML::LibXML;

has operation => (is => 'ro', init_arg => undef, default => 'ListBlobs');
has endpoint => (is => 'ro', init_arg => undef, lazy => 1, default => sub {
  my $self = shift;
  return sprintf(
    'https://%s.blob.core.windows.net/%s?restype=container&comp=list',
    $self->account_name,
    $self->container,
  );
});
has method => (is => 'ro', init_arg => undef, default => 'GET');

with 'Azure::Storage::Blob::Client::Call';

lib/Azure/Storage/Blob/Client/Call/PutBlob.pm  view on Meta::CPAN

package Azure::Storage::Blob::Client::Call::PutBlob;
use Moose;
use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::BodyParameter;
use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::HeaderParameter;

has operation => (is => 'ro', init_arg => undef, default => 'PutBlob');
has endpoint => (is => 'ro', init_arg => undef, lazy => 1, default => sub {
  my $self = shift;
  return sprintf(
    'https://%s.blob.core.windows.net/%s/%s',
    $self->account_name,
    $self->container,
    $self->blob_name,
  );
});
has method => (is => 'ro', init_arg => undef, default => 'PUT');

lib/Azure/Storage/Blob/Client/Caller.pm  view on Meta::CPAN

    $call_object->operation ne 'ListBlobs' and
    $call_object->operation ne 'PutBlob'
  ) {
    die 'Unimplemented.';
  }

  my $url_encoded_parameters = HTTP::Tiny->new->www_form_urlencode(
    $call_object->serialize_uri_parameters(),
  );
  my $url = $url_encoded_parameters
    ? sprintf("%s&%s", $call_object->endpoint, $url_encoded_parameters)
    : $call_object->endpoint;

  my $body = $self->_build_body_content($call_object);
  my $headers = $self->_build_headers($call_object, $body);
  my $request = HTTP::Request->new($call_object->method, $url, $headers, $body);
  $self->_sign_request($request, $account_name, $account_key, $call_object);

  return $request;
}

sub _handle_storage_account_api_exceptions {

t/Azure/Storage/Blob/Client/Call.t  view on Meta::CPAN

  use Moose;
  with 'Azure::Storage::Blob::Client::Call';

  has att1 => (is => 'ro', isa => 'Any', required => 1);
  has att2 => (is => 'ro', isa => 'Any', required => 1);
  has att3 => (is => 'ro', isa => 'Any', required => 1);

  # required by Call role
  sub operation {}
  sub method {}
  sub endpoint {}
};

package Azure::Storage::Blob::Client::Test::CallClassWithURIParameters {
  use Moose;
  use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::URIParameter;
  with 'Azure::Storage::Blob::Client::Call';

  has att1 => (is => 'ro', isa => 'Any', required => 1);
  has att2 => (is => 'ro', isa => 'Any', traits => ['URIParameter'], required => 1);
  has att3 => (is => 'ro', isa => 'Any', traits => ['URIParameter'], required => 1);

  # required by Call role
  sub operation {}
  sub method {}
  sub endpoint {}
};

package Azure::Storage::Blob::Client::Test::CallClassWithHeaderParameters {
  use Moose;
  use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::HeaderParameter;
  with 'Azure::Storage::Blob::Client::Call';

  has att1 => (is => 'ro', isa => 'Any', required => 1);
  has att2 => (is => 'ro', isa => 'Any', traits => ['HeaderParameter'], header_name => 'h2', required => 1);
  has att3 => (is => 'ro', isa => 'Any', traits => ['HeaderParameter'], header_name => 'h3', required => 1);

  # required by Call role
  sub operation {}
  sub method {}
  sub endpoint {}
};

package Azure::Storage::Blob::Client::Test::CallClassWithBodyParameters {
  use Moose;
  use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::BodyParameter;
  with 'Azure::Storage::Blob::Client::Call';

  has att1 => (is => 'ro', isa => 'Any', required => 1);
  has att2 => (is => 'ro', isa => 'Any', traits => ['BodyParameter'], required => 1);
  has att3 => (is => 'ro', isa => 'Any', traits => ['BodyParameter'], required => 1);

  # required by Call role
  sub operation {}
  sub method {}
  sub endpoint {}
};

package Azure::Storage::Blob::Client::Test::CallClassWithAllParameters {
  use Moose;
  use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::URIParameter;
  use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::HeaderParameter;
  use Azure::Storage::Blob::Client::Meta::Attribute::Custom::Trait::BodyParameter;
  with 'Azure::Storage::Blob::Client::Call';

  has att1 => (is => 'ro', traits => ['URIParameter'], required => 1);
  has att2 => (is => 'ro', traits => ['HeaderParameter'], header_name => 'h2', required => 1);
  has att3 => (is => 'ro', traits => ['BodyParameter'], required => 1);
  has att4 => (is => 'ro', traits => ['URIParameter', 'HeaderParameter', 'BodyParameter'], header_name => 'h4', required => 1);
  has att5 => (is => 'ro', required => 1);

  # required by Call role
  sub operation {}
  sub method {}
  sub endpoint {}
};

runtests unless caller;



( run in 1.232 second using v1.01-cache-2.11-cpan-49f99fa48dc )