CloudApp-REST

 view release on metacpan or  search on metacpan

lib/CloudApp/REST.pm  view on Meta::CPAN

of a C<CloudApp::REST::Item::*> module object.

=cut

sub delete_item {
    my $self = shift;
    my $item = shift;

    $self->authenticate;
    $self->_get_response({ method => 'DELETE', uri => $item->href->path });

    return 1;
}

=head2 authenticate

Parameters:

=over

=item C<\%params>

=back

Instead of using L</email> and L</password> directly you can
pass along both parameters to L</authenticate> to set the user data.

If one of the following parameters are not given, L</authenticate> tries to find them in
L</email> or L</password>.  If either parameter cannot be found,
L</authenticate> dies.

=over 4

=item I<email =E<gt> $email>
=item I<username =E<gt> $email> (B<Legacy>)
=item I<user =E<gt> $email> (B<Legacy>)

Email to authenticate with.  Use one of them to access L</email>.

=item I<password =E<gt> $password>
=item I<pass =E<gt> $password>

Password to authenticate with.  Use one of them to access L</password>.

=back

B<Note:> the credentails passed through L</authenticate> are B<not> saved within the instance
data of L<CloudApp::REST>. As result only one request is handled with authentication, all
following will be processed without it.  Note that some API calles require authentication
and if this data is not present when calling such a method, that method will die.

=cut

sub authenticate {
    my $self   = shift;
    my $params = shift;

    my $email = $params->{email} || $params->{username} || $params->{user} || $self->email || die "You have to provide an email address";
    my $pass  = $params->{password} || $params->{pass} || $self->password || die "You have to provide a password";

    $self->useragent->credentials($self->auth_netloc, $self->auth_realm, $email, $pass);

    return 1;
}

=head2 account_register

Parameters:

=over

=item C<\%params>

=back

Registers an CloudApp account using the given email and password and returns the data returned by the API call as hash ref.

=over 4

=item I<email =E<gt> $email>

Email address (username) to register.

=item I<password =E<gt> $password>
=item I<pass =E<gt> $password>

Password for the user.

=back

=cut

sub account_register {
    my $self   = shift;
    my $params = shift;

    my $email = $params->{email} || $self->email || die "You have to provide an email address";
    my $pass  = $params->{password} || $params->{pass} || $self->password || die "You have to provide a password";

    return $self->_get_response({ uri => $self->private_base_url . 'register', params => { user => { email => $email, password => $pass } } });
}

=head1 FLAGS, ATTRIBUTES AND SETTINGS

You can control some behaviour by setting different flags or change some attributes
or settings.  Use them as methods.

=over 4

=item debug

Parameters:

=over

=item C<$bool>

=back

Activates the debug mode by passing a true value.  Defaults to C<0>.  Debug messages are
printed with C<warn>.



( run in 1.567 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )