AsposeDiagramCloud-DiagramApi

 view release on metacpan or  search on metacpan

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

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
                                           $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

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# @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

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
has 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

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
        with 'https://metacpan.org/pod/AsposeDiagramCloud::Role">AsposeDiagramCloud::Role';
 
        package main;
 
        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

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
=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

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
  -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 )