Backblaze-B2

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

METHODS

 ->new %options

        my $b2 = Backblaze::B2::v1->new(
            api => 'Backblaze::B2::v1::Synchronous', # the default
        );

    Creates a new instance. Depending on whether you pass in
    <Backblaze::B2::v1::Synchronous> or <Backblaze::B2::v1::AnyEvent>, you
    will get a synchronous or asynchronous API.

    The synchronous API is what is documented here, as this is the most
    likely use case.

        my @buckets = $b2->buckets();
        for( @buckets ) {
            ...
        }

    The asynchronous API is identical to the synchronous API in spirit, but
    will return Promises . These condvars usually return two or more
    parameters upon completion:

        my $results = $b2->buckets();
        $results->then( sub{ 
            my( @buckets ) = @_;
            for( @buckets ) {
                ...
            }
        }

    The asynchronous API puts the burden of error handling into your code.

 ->buckets

        my @buckets = $b2->buckets();

    Returns a list of Backblaze::B2::Bucket objects associated with the B2
    account.

 ->bucket_from_id

README.mkdn  view on Meta::CPAN

# METHODS

## `->new %options`

    my $b2 = Backblaze::B2::v1->new(
        api => 'Backblaze::B2::v1::Synchronous', # the default
    );

Creates a new instance. Depending on whether you pass in
`<Backblaze::B2::v1::Synchronous`> or `<Backblaze::B2::v1::AnyEvent`>,
you will get a synchronous or asynchronous API.

The synchronous API is what is documented here, as this is the
most likely use case.

    my @buckets = $b2->buckets();
    for( @buckets ) {
        ...
    }

The asynchronous API is identical to the synchronous API in spirit, but
will return [Promises](https://metacpan.org/pod/Promises) . These condvars usually return
two or more parameters upon completion:

    my $results = $b2->buckets();
    $results->then( sub{ 
        my( @buckets ) = @_;
        for( @buckets ) {
            ...
        }
    }

The asynchronous API puts the burden of error handling into your code.

## `->buckets`

    my @buckets = $b2->buckets();

Returns a list of [Backblaze::B2::Bucket](https://metacpan.org/pod/Backblaze::B2::Bucket) objects associated with
the B2 account.

## `->bucket_from_id`

lib/Backblaze/B2.pm  view on Meta::CPAN

=head1 METHODS

=head2 C<< ->new %options >>

    my $b2 = Backblaze::B2::v1->new(
        api => 'Backblaze::B2::v1::Synchronous', # the default
    );

Creates a new instance. Depending on whether you pass in
C<<Backblaze::B2::v1::Synchronous>> or C<<Backblaze::B2::v1::AnyEvent>>,
you will get a synchronous or asynchronous API.

The synchronous API is what is documented here, as this is the
most likely use case.

    my @buckets = $b2->buckets();
    for( @buckets ) {
        ...
    }

The asynchronous API is identical to the synchronous API in spirit, but
will return L<Promises> . These condvars usually return
two or more parameters upon completion:

    my $results = $b2->buckets();
    $results->then( sub{ 
        my( @buckets ) = @_;
        for( @buckets ) {
            ...
        }
    }

The asynchronous API puts the burden of error handling into your code.

=cut

use vars '$API_BASE';
$API_BASE = 'https://api.backblazeb2.com/b2api/v1/';

sub new {
    my( $class, %options ) = @_;
    
    # Hrr. We need to get at an asynchronous API here and potentially
    # wrap the results to synchronous results in case the user wants them.
    # Turtles all the way down, this means we can't reuse calls into ourselves...

    $options{ api } ||= 'Backblaze::B2::v1::Synchronous';
    if( ! ref $options{ api }) {
        eval "require $options{ api }";
        my $class = delete $options{ api };
        $options{ api } = $class->new(%options);
    };
    
    if( $options{ api }->isAsync ) {

lib/Backblaze/B2.pm  view on Meta::CPAN


package Backblaze::B2::v1::Bucket;
use strict;
use Scalar::Util 'weaken';

sub new {
    my( $class, %options ) = @_;
    weaken $options{ parent };
    
    # Whoa! We assume that the async version has the same class name
    # as the synchronous version and just strip it off.
    $options{ file_class } =~ s!::Synchronized$!!;
    
    bless \%options => $class,
}

sub name { $_[0]->{bucketName} }
#sub api { $_[0]->{api} }
sub downloadUrl { join "/", $_[0]->api->downloadUrl, $_[0]->name }
sub id { $_[0]->{bucketId} }
sub type { $_[0]->{bucketType} }

lib/Backblaze/B2/v1/AnyEvent.pm  view on Meta::CPAN



=head2 C<< ->request >>

Returns a promise that will resolve to the response data and the headers from
the request.

=cut

# You might want to override this if you want to use HIJK or
# some other way. If your HTTP requestor is synchronous, just
# return a
# AnyEvent->condvar
# which performs the real task.
# Actually, this now returns just a Promise

sub request {
    my( $self, %options) = @_;
    
    $options{ method } ||= 'GET';
    #my $completed = delete $options{ cb };

lib/Backblaze/B2/v1/Synchronous.pm  view on Meta::CPAN

$VERSION = '0.02';

sub isAsync { 0 }
sub api { $_[0]->{api} }
sub asyncApi { $_[0]->api }

=head1 METHODS

=head2 C<< ->new >>

Creates a new synchronous instance.

=cut

sub new {
    my( $class, %options ) = @_;
    
    require Backblaze::B2;

    $options{ api_base } //= $Backblaze::B2::v1::API_BASE
                           = $Backblaze::B2::v1::API_BASE;



( run in 0.582 second using v1.01-cache-2.11-cpan-0d8aa00de5b )