AsposeCellsCloud-CellsApi
view release on metacpan or search on metacpan
lib/AsposeCellsCloud/ApiClient.pm view on Meta::CPAN
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 Log::Any qw($log);
use Carp;
use Module::Runtime qw(use_module);
use AsposeCellsCloud::Configuration;
sub new {
my $class = shift;
my $config;
my $get_access_token_time;
if ( $_[0] && ref $_[0] && ref $_[0] eq 'AsposeCellsCloud::Configuration' ) {
$config = $_[0];
} else {
$config = AsposeCellsCloud::Configuration->new(@_);
}
my (%args) = (
'ua' => LWP::UserAgent->new,
'config' => $config,
'get_access_token_time' =>$get_access_token_time,
);
return bless \%args, $class;
}
sub need_auth{
my ($self) = @_;
if( $self->{config}->{client_id} || $self->{config}->{client_secret} ) {
return 1;
}
return 0;
}
# Set the user agent of the API client
#
# @param string $user_agent The user agent of the API client
#
sub set_user_agent {
my ($self, $user_agent) = @_;
$self->{http_user_agent}= $user_agent;
}
# Set timeout
#
# @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
#
sub set_timeout {
my ($self, $seconds) = @_;
if (!looks_like_number($seconds)) {
croak('Timeout variable must be numeric.');
}
$self->{http_timeout} = $seconds;
}
# @return AccessTokenResponse
#
sub o_auth_post {
my ($self, %args) = @_;
# verify the required parameter 'grant_type' is set
unless (exists $args{'grant_type'}) {
croak("Missing the required parameter 'grant_type' when calling o_auth_post");
}
# verify the required parameter 'client_id' is set
unless (exists $args{'client_id'}) {
croak("Missing the required parameter 'client_id' when calling o_auth_post");
}
# verify the required parameter 'client_secret' is set
unless (exists $args{'client_secret'}) {
croak("Missing the required parameter 'client_secret' when calling o_auth_post");
}
# parse inputs
my $_resource_path = '/v3.0/cells/connect/token';
if($self->{config}->{api_version} eq "v1.1"){
$_resource_path = '/oauth2/token';
}
my $_method = 'POST';
my $query_params = {};
my $header_params = {};
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->select_header_accept('application/json');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
$header_params->{'Content-Type'} = $self->select_header_content_type('application/x-www-form-urlencoded');
# form params
if ( exists $args{'grant_type'} ) {
$form_params->{'grant_type'} = $self->to_form_value($args{'grant_type'});
}
# form params
if ( exists $args{'client_id'} ) {
$form_params->{'client_id'} = $self->to_form_value($args{'client_id'});
}
# form params
if ( exists $args{'client_secret'} ) {
$form_params->{'client_secret'} = $self->to_form_value($args{'client_secret'});
}
my $_body_data;
# authentication setting, if any
my $auth_settings = [qw()];
( run in 3.527 seconds using v1.01-cache-2.11-cpan-c966e8aa7e8 )