AsposeDiagramCloud-DiagramApi
view release on metacpan or search on metacpan
lib/AsposeDiagramCloud/ApiClient.pm view on Meta::CPAN
140141142143144145146147148149150151152153154155156157158159160
$header_params
,
$_body_data
,
$auth_settings
);
if
(!
$response
) {
return
;
}
my
$_response_object
=
$self
->deserialize(
'AccessTokenResponse'
,
$response
);
$self
->{get_access_token_time} =
time
();
return
$_response_object
;
}
# 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 $postData parameters to be placed in POST body
# @param array $headerParams parameters to be place in request header
# @return mixed
sub
call_api {
my
$self
=
shift
;
my
(
$resource_path
,
$method
,
$query_params
,
$post_params
,
$header_params
,
$body_data
,
$auth_settings
) =
@_
;
# update parameters based on authentication settings
lib/AsposeDiagramCloud/ApiClient.pm view on Meta::CPAN
398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439#
# @param array $headerParams header parameters (by ref)
# @param array $queryParams query parameters (by ref)
# @param array $authSettings array of authentication scheme (e.g ['api_key'])
sub
update_params_for_auth {
my
(
$self
,
$header_params
,
$query_params
,
$auth_settings
) =
@_
;
return
$self
->_global_auth_setup(
$header_params
,
$query_params
)
unless
$auth_settings
&&
@$auth_settings
;
# one endpoint can have more than 1 auth settings
foreach
my
$auth
(
@$auth_settings
) {
# determine which one to use
if
(!
defined
(
$auth
)) {
# TODO show warning about auth setting not defined
}
elsif
(
$auth
eq
'JWT'
) {
if
(
$self
->{config}{access_token}) {
$header_params
->{
'Authorization'
} =
'Bearer '
.
$self
->{config}{access_token};
}
}
else
{
# TODO show warning about security definition not found
}
}
}
# The endpoint API class has not found any settings for auth. This may be deliberate,
# in which case update_params_for_auth() will be a no-op. But it may also be that the
# OpenAPI Spec does not describe the intended authorization. So we check in the config for any
# auth tokens and if we find any, we use them for all endpoints;
sub
_global_auth_setup {
my
(
$self
,
$header_params
,
$query_params
) =
@_
;
my
$tokens
=
$self
->{config}->get_tokens;
return
unless
keys
%$tokens
;
# basic
if
(
my
$uname
=
delete
$tokens
->{username}) {
my
$pword
=
delete
$tokens
->{password};
$header_params
->{
'Authorization'
} =
'Basic '
.encode_base64(
$uname
.
":"
.
$pword
);
lib/AsposeDiagramCloud/Role.pm view on Meta::CPAN
293031323334353637383940414243444546474849has
base_url
=> (
is
=>
'ro'
,
required
=> 0,
isa
=>
'Str'
,
documentation
=>
'Root of the server that requests are sent to'
,
);
has
api_factory
=> (
is
=>
'ro'
,
isa
=>
'AsposeDiagramCloud::ApiFactory'
,
builder
=>
'_build_af'
,
lazy
=> 1,
documentation
=>
'Builds an instance of the endpoint API class'
,
);
has
tokens
=> (
is
=>
'ro'
,
isa
=>
'HashRef'
,
required
=> 0,
default
=>
sub
{ {} },
documentation
=>
'The auth tokens required by the application - basic, OAuth and/or API key(s)'
,
);
has
_cfg
=> (
is
=>
'ro'
,
lib/AsposeDiagramCloud/Role.pm view on Meta::CPAN
146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
my
$api
= MyApp->new({
tokens
=>
$tokens
});
my
$pet
=
$api
->get_pet_by_id(
pet_id
=>
$pet_id
);
=head2 Structure of the library
The library consists of a set of API classes, one for each endpoint. These APIs
implement the method calls available on each endpoint.
Additionally, there is a set of "object" classes, which represent the objects
returned by and sent to the methods on the endpoints.
An API factory class is provided, which builds instances of each endpoint API.
This Moose role flattens all the methods from the endpoint APIs onto the consuming
class. It also provides methods to retrieve the endpoint API objects, and the API
factory object, should you need it.
For documentation of all these methods, see AUTOMATIC DOCUMENTATION below.
=head2 Configuring authentication
In the normal case, the OpenAPI Spec will describe what parameters are
required and where to put them. You just need to supply the tokens.
my $tokens = {
lib/AsposeDiagramCloud/Role.pm view on Meta::CPAN
249250251252253254255256257258259260261262263264265266267268269270=head2 C<api_factory>
Returns an API factory object. You probably won't need to call this directly.
$self->api_factory('Pet'); # returns a AsposeDiagramCloud::PetApi instance
$self->pet_api; # the same
=head1 MISSING METHODS
Most of the methods on the API are delegated to individual endpoint API objects
(e.g. Pet API, Store API, User API etc). Where different endpoint APIs use the
same method name (e.g. C<new()>), these methods can't be delegated. So you need
to call C<$api-E<gt>pet_api-E<gt>new()>.
In principle, every API is susceptible to the presence of a few, random, undelegatable
method names. In practice, because of the way method names are constructed, it's
unlikely in general that any methods will be undelegatable, except for:
new()
class_documentation()
method_documentation()
lib/AsposeDiagramCloud/Role.pm view on Meta::CPAN
316317318319320321322323324325326327328329330331332333334335
-c your application class
The C<-c> option allows you to load and inspect your own application. A dummy
namespace is used
if
you don't supply your own class.
=head1 DOCUMENTATION FROM THE OpenAPI Spec
Additional documentation for each class and method may be provided by the Swagger
spec. If so, this is available via the C<class_documentation()> and
C<method_documentation()> methods on each generated object class, and the
C<method_documentation()> method on the endpoint API classes:
my $cmdoc = $api->pet_api->method_documentation->{$method_name};
my $odoc = $api->get_pet_by_id->(pet_id => $pet_id)->class_documentation;
my $omdoc = $api->get_pet_by_id->(pet_id => $pet_id)->method_documentation->{method_name};
Each of these calls returns a hashref with various useful pieces of information.
=cut
( run in 1.049 second using v1.01-cache-2.11-cpan-49f99fa48dc )