API-ParallelsWPB

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension API::ParallelsWPB

0.03    Tue Jul 1 08:40:44 2014 +0000

    - fixed utf8 flag in request
    - JSON replaced with JSON::XS
    - If error is not in JSON, it is returned "as is"


0.01    Tue Nov 26 12:22:16 2013
        - first release;

LICENSE  view on Meta::CPAN

                            Preamble

  The license agreements of most software companies try to keep users
at the mercy of those companies.  By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

LICENSE  view on Meta::CPAN

Program or a portion of it, either verbatim or with modifications.  Each
licensee is addressed as "you".

  1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program.  You may charge a fee for the physical act of
transferring a copy.

  2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:

    a) cause the modified files to carry prominent notices stating that
    you changed the files and the date of any change; and

    b) cause the whole of any work that you distribute or publish, that
    in whole or in part contains the Program or any part thereof, either

LICENSE  view on Meta::CPAN


    c) If the modified program normally reads commands interactively when
    run, you must cause it, when started running for such interactive use
    in the simplest and most usual way, to print or display an
    announcement including an appropriate copyright notice and a notice
    that there is no warranty (or else, saying that you provide a
    warranty) and that users may redistribute the program under these
    conditions, and telling the user how to view a copy of this General
    Public License.

    d) You may charge a fee for the physical act of transferring a
    copy, and you may at your option offer warranty protection in
    exchange for a fee.

Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.

  3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:

LICENSE  view on Meta::CPAN

    years, to give any third party free (except for a nominal charge
    for the cost of distribution) a complete machine-readable copy of the
    corresponding source code, to be distributed under the terms of
    Paragraphs 1 and 2 above; or,

    c) accompany it with the information you received as to where the
    corresponding source code may be obtained.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form alone.)

Source code for a work means the preferred form of the work for making
modifications to it.  For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.

  4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer

README  view on Meta::CPAN


SYNOPSIS
        my $client = API::ParallelsWPB->new( username => 'admin', password => 'passw0rd', server => 'builder.server.mysite.ru' );
        my $response = $client->get_sites_info;
        if ( $response->success ) {
            for my $site ( @{ $response->response } ) {
                say "UUID: ". $site->{uuid};
            }
        }
        else {
            warn "Error occured: " . $response->error . ", Status: " . $response->status;
        }

METHODS
  new($class, %param)
    Creates new client instance. Parameters for "new" are:

    username
        Username for connection to Parallels WebPresence Builder instance.
        Required parameter.

README  view on Meta::CPAN

        Required parameter.

    server
        Servername or server ip address for connection to Parallels
        WebPresence Builder instance. Optional parameter.

    api_version
        API version, used in API url constructing. Optional parameter.

    debug
        Debug flag, requests will be loogged to stderr. Optional parameter.

    timeout
        Connection timeout. Optional parameter.

  f_request($self, $url_array_ref, $data)
    "Free" request. Now for internal usage only.

    $data: req_type : HTTP request type: get, post, put, delete. GET by
    default. post_data: data for POST request. Must be hashref.

README.md  view on Meta::CPAN


```perl
my $client = API::ParallelsWPB->new(username => 'admin', password => 'passw0rd', server => 'builder.server.mysite.ru');
my $response = $client->get_sites_info;
if ($response->success) {
    for my $site (@{$response->response}) {
        say "UUID: ". $site->{ uuid };
    }
}
else {
    warn "Error occured: " . $response->error . ", Status: " . $response->status;
}
```
# METHODS

## new

Creates new client instance. Parameters for ```new``` are:

- username

README.md  view on Meta::CPAN

- server

Servername or server ip address for connection to Parallels WebPresence Builder instance. Optional parameter.

- api_version

API version, used in API url constructing. Optional parameter.

- debug

Debug flag, requests will be loogged to stderr. Optional parameter.

- timeout

Connection timeout. Optional parameter.

# SEE ALSO
   
[Parallels Presence Builder Guide](http://download1.parallels.com/WPB/Doc/11.5/en-US/online/presence-builder-standalone-installation-administration-guide)

# AUTHORS

lib/API/ParallelsWPB.pm  view on Meta::CPAN

=head1 SYNOPSIS

    my $client = API::ParallelsWPB->new( username => 'admin', password => 'passw0rd', server => 'builder.server.mysite.ru' );
    my $response = $client->get_sites_info;
    if ( $response->success ) {
        for my $site ( @{ $response->response } ) {
            say "UUID: ". $site->{uuid};
        }
    }
    else {
        warn "Error occured: " . $response->error . ", Status: " . $response->status;
    }

=head1 METHODS

=head2 B<new($class, %param)>

Creates new client instance. Parameters for C<new> are:

=over

lib/API/ParallelsWPB.pm  view on Meta::CPAN

=item server

Servername or server ip address for connection to Parallels WebPresence Builder instance. Optional parameter.

=item api_version

API version, used in API url constructing. Optional parameter.

=item debug

Debug flag, requests will be loogged to stderr. Optional parameter.

=item timeout

Connection timeout. Optional parameter.

=back

=head2 B<f_request($self, $url_array_ref, $data)>

"Free" request. Now for internal usage only.

lib/API/ParallelsWPB/Response.pm  view on Meta::CPAN

our $VERSION = '0.03'; # VERSION
our $AUTHORITY = 'cpan:IMAGO'; # AUTHORITY


sub new {
    my ( $class, $res ) = @_;

    my $success    = $res->is_success;
    my $status     = $res->status_line;

    my ( $json_content, $response, $error );

    if ( $success ) {
        $json_content = $res->content;
        $response = decode_json( $json_content )->{response} if $json_content;
    }
    else {
        my $error_json = $res->content;
        eval { $error = decode_json( $error_json )->{error}->{message}; 1; }
        or do { $error = $error_json };
    }

    return bless(
        {
            success  => $success,
            json     => $json_content,
            error    => $error,
            response => $response,
            status   => $status
        },
        $class
    );
}


sub json {
    my $self = shift;

lib/API/ParallelsWPB/Response.pm  view on Meta::CPAN



sub status {
    my $self = shift;

    return $self->{status};
}



sub error {
    my $self = shift;

    return $self->{error};
}

1;

__END__

=pod

=encoding UTF-8

lib/API/ParallelsWPB/Response.pm  view on Meta::CPAN

Returns 1 if request succeeded, 0 otherwise.

=head2 B<response($self)>

Returns munged response from service. According to method, it can be scalar, hashref of arrayref.

=head2 B<status($self)>

Returns response status line.

=head2 B<error($self)>

Returns munged error text.

=head1 SEE ALSO

L<Parallels Presence Builder Guide|http://download1.parallels.com/WPB/Doc/11.5/en-US/online/presence-builder-standalone-installation-administration-guide>

L<API::ParallelsWPB>

L<API::ParallelsWPB::Requests>

=head1 AUTHORS

t/00-compile.t  view on Meta::CPAN


use File::Spec;
use IPC::Open3;
use IO::Handle;

my @warnings;
for my $lib (@module_files)
{
    # see L<perlfaq8/How can I capture STDERR from an external command?>
    open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
    my $stderr = IO::Handle->new;

    my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]");
    binmode $stderr, ':crlf' if $^O eq 'MSWin32';
    my @_warnings = <$stderr>;
    waitpid($pid, 0);
    is($?, 0, "$lib loaded ok");

    if (@_warnings)
    {
        warn @_warnings;
        push @warnings, @_warnings;
    }
}

t/02_response.t  view on Meta::CPAN

    ok( $response->success, 'Response status succeeded' );
    is(
        $response->response,
        'b6a09c08f880f229c091de03b91bdbc3',
        'Response content is ok'
    );

    is( $response->status, '200 OK', 'Status line is ok' );
};

subtest 'Response errored' => sub {

    plan tests => 4;

    my $r = HTTP::Response->new;
    $r->code( 404 );
    $r->content(
'{"error":{"message":"Requested resource does not exist by URI: /api/5.3/sites/"}}'
    );

    my $response = API::ParallelsWPB::Response->new( $r );
    ok( !$response->success, 'Response is not succeeded' );
    like(
        $response->error,
        qr/Requested resource does not exist/,
        'Error message is ok'
    );

    ok( !$response->response, 'No content given ok' );
    is( $response->status, '404 Not Found', 'Response status is ok' );
};



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