API-PureStorage

 view release on metacpan or  search on metacpan

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

use Net::SSL;

use warnings;
use strict;

$API::PureStorage::VERSION = '0.03';

our %ENV;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

my $debug = 0;

sub new {
    my $class = shift @_;
    my $self = {
        cookie_file => '/tmp/cookies.txt',
        host => $_[0],
        token => $_[1]
    };
    bless $self, $class;

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

    my $url = shift @_;
    my $ret = $self->{client}->GET($url);
    my $num = $ret->responseCode();
    my $con = $ret->responseContent();
    if ( $num == 500 ) {
        die "API returned error 500 for '$url' - $con\n";
    }
    if ( $num != 200 ) {
        die "API returned code $num for URL '$url'\n";
    }
    print 'DEBUG: GET ', $url, ' -> ', $num, ":\n", Dumper(from_json($con)), "\n" if $debug;
    return from_json($con);
}

sub _api_post {
    my $self = shift @_;
    my $url = shift @_;
    my $data = shift @_;
    my $ret = $self->{client}->POST($url, to_json($data));
    my $num = $ret->responseCode();
    my $con = $ret->responseContent();
    if ( $num == 500 ) {
        die "API returned error 500 for '$url' - $con\n";
    }
    if ( $num != 200 ) {
        die "API returned code $num for URL '$url'\n";
    }
    print 'DEBUG: POST ', $url, ' -> ', $num, ":\n", Dumper(from_json($con)), "\n" if $debug;
    return from_json($con);
}

1;
__END__
=head1 NAME

API::PureStorage - Interacting with Pure Storage devices

=head1 SYNOPSIS



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