AsposeSlidesCloud-SlidesApi

 view release on metacpan or  search on metacpan

lib/AsposeSlidesCloud/ApiClient.pm  view on Meta::CPAN

=begin comment

Copyright (c) 2019 Aspose Pty Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

=end comment

=cut

package AsposeSlidesCloud::ApiClient;

use strict;
use warnings;
use utf8;

use MIME::Base64;
use LWP::UserAgent;
use HTTP::Date;
use HTTP::Headers;
use HTTP::Response;
use HTTP::Request::Common qw(DELETE POST GET HEAD PUT);
use HTTP::Status;
use URI::Query;
use JSON;
use URI::Escape;
use Scalar::Util;
use Carp;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Log::Any::Adapter ('Stderr');
use AsposeSlidesCloud::ApiInfo;
use AsposeSlidesCloud::ClassRegistry;
use AsposeSlidesCloud::Configuration;

sub new {
    my $class = shift;

    my $config;

    my %params = @_;

    if (defined $params{config}) {
        $config = $params{config};
    } else {
        $config = AsposeSlidesCloud::Configuration->new(@_);
    }

    my $ua = LWP::UserAgent->new;

    if ($config->{allow_insecure_requests}) {
        $ua->ssl_opts(SSL_verify_mode => 0);
        $ua->ssl_opts(verify_hostname => 0);
    }

    if (defined $config->{http_request_timeout}) {
        $ua->{timeout} = $config->{http_request_timeout};
    }

    my (%args) = ('ua' => $ua, 'config' => $config);
  
    return bless \%args, $class;
}

# make the HTTP request
# @param string $resourcePath path to method endpoint
# @param string $method method to call
# @param array $queryParams parameters to be place in query URL
# @param array $postParams parameters to be placed in POST body
# @param array $headerParams parameters to be place in request header
# @param array $body_data data to be place in request body
# @param array $files files to be posted
# @return mixed
sub call_api {
    my $self = shift;
    my ($resource_path, $method, $query_params, $post_params, $header_params, $body_data, $files) = @_;

    my $had_token = defined $self->{config}{access_token} && $self->{config}{access_token} ne "";
    my $response = $self->call_api_once($resource_path, $method, $query_params, $post_params, $header_params, $body_data, $files);
    my $content = sprintf("%s", $response->content);
    if ($had_token && ($response->code eq 401 || ($response->code eq 500 && !$content))) {
        $self->{config}{access_token} = "";



( run in 2.306 seconds using v1.01-cache-2.11-cpan-995e09ba956 )