WWW::SwaggerClient::Role – a Moose role for the <PBXDom API>


Automatically generated by the Swagger Codegen project:

  • API version: 2.1.0
  • Package version: 1.0.0
  • Build date: 2016-06-25T14:20:13.328Z
  • Build package: class io.swagger.codegen.languages.PerlClientCodegen

A note on Moose

This role is the only component of the library that uses Moose. See
WWW::SwaggerClient::ApiFactory for non-Moosey usage.


The Perl Swagger Codegen project builds a library of Perl modules to interact with
a web service defined by a OpenAPI Specification. See below for how to build the

This module provides an interface to the generated library. All the classes,
objects, and methods (well, not quite *all*, see below) are flattened into this

    package MyApp;
    use Moose;
    with 'WWW::SwaggerClient::Role';
    package main;
    my $api = MyApp-&gt;new({ tokens =&gt; $tokens });
    my $pet = $api-&gt;get_pet_by_id(pet_id =&gt; $pet_id);

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.

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 = {
    # basic
    username =&gt; $username,
    password =&gt; $password,
    # oauth
    access_token =&gt; $oauth_token,
    # keys
    $some_key =&gt; { token =&gt; $token,
                   prefix =&gt; $prefix,
                   in =&gt; $in,             # 'head||query',    
    $another =&gt; { token =&gt; $token,
                  prefix =&gt; $prefix,
                  in =&gt; $in,              # 'head||query',      
    my $api = MyApp-&gt;new({ tokens =&gt; $tokens });

Note these are all optional, as are




, and depend on the API
you are accessing. Usually




will be determined by the code generator from
the spec and you will not need to set them at run time. If not,


default to ‘head’ and


to the empty string.

The tokens will be placed in the


as follows, but you don’t need to know about this.

  • $WWW::SwaggerClient::Configuration::username

    String. The username for basic auth.

  • $WWW::SwaggerClient::Configuration::password

    String. The password for basic auth.

  • $WWW::SwaggerClient::Configuration::api_key

    Hashref. Keyed on the name of each key (there can be multiple tokens).

          $WWW::SwaggerClient::Configuration::api_key = {
                  secretKey =&gt; 'aaaabbbbccccdddd',
                  anotherKey =&gt; '1111222233334444',
  • $WWW::SwaggerClient::Configuration::api_key_prefix

    Hashref. Keyed on the name of each key (there can be multiple tokens). Note not
    all api keys require a prefix.

          $WWW::SwaggerClient::Configuration::api_key_prefix = {
                  secretKey =&gt; 'string',
                  anotherKey =&gt; 'same or some other string',
  • $WWW::SwaggerClient::Configuration::access_token

    String. The OAuth access token.



The generated code has the


already set as a default value. This method
returns (and optionally sets, but only if the API client has not been
created yet) the current value of




Returns an API factory object. You probably won’t need to call this directly.

    $self-&gt;api_factory('Pet'); # returns a WWW::SwaggerClient::PetApi instance
    $self-&gt;pet_api;            # the same


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.


), these methods can’t be delegated. So you need
to call



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:


To call these methods, you need to get a handle on the relevant object, either
by calling


or by retrieving an object, e.g.

$api-&gt;get_pet_by_id(pet_id =&gt; $pet_id)

. They are class methods, so
you could also call them on class names.


See the homepage

for full details.
But briefly, clone the git repository, build the codegen codebase, set up your build
config file, then run the API build script. You will need git, Java 7 or 8 and Apache
maven 3.0.3 or better already installed.

The config file should specify the project name for the generated library:


Your library files will be built under



      $ git clone
      $ cd swagger-codegen
      $ mvn package
      $ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i [URL or file path to JSON swagger API spec] \
-l perl \
-c /path/to/config/file.json \
-o /path/to/output/folder

Bang, all done. Run the


script in the


directory to see the API
you just built.


You can print out a summary of the generated API by running the included


script in the


directory of your generated library. A few
output formats are supported:

      Usage: autodoc [OPTION]

-w           wide format (default)
-n           narrow format
-p           POD format
-H           HTML format
-m           Markdown format
-h           print this help message
-c           your application class



option allows you to load and inspect your own application. A dummy
namespace is used if you don’t supply your own class.


Additional documentation for each class and method may be provided by the Swagger
spec. If so, this is available via the




methods on each generated object class, and the


method on the endpoint API classes:

    my $cmdoc = $api-&gt;pet_api-&gt;method_documentation-&gt;{$method_name};
    my $odoc = $api-&gt;get_pet_by_id-&gt;(pet_id =&gt; $pet_id)-&gt;class_documentation;                                  
    my $omdoc = $api-&gt;get_pet_by_id-&gt;(pet_id =&gt; $pet_id)-&gt;method_documentation-&gt;{method_name};

Each of these calls returns a hashref with various useful pieces of information.


To load the API packages:

<span class="hljs-keyword">use</span> WWW::SwaggerClient::DefaultApi;

To load the models:

<span class="hljs-keyword">use</span> WWW::SwaggerClient::Object::InlineResponse20<span class="hljs-number">0</span>;


Put the Perl SDK under the ‘lib’ folder in your project directory, then run the following

<span class="hljs-comment">#!/usr/bin/perl</span>
<span class="hljs-keyword">use</span> lib <span class="hljs-string">'lib'</span>;
<span class="hljs-keyword">use</span> strict;
<span class="hljs-keyword">use</span> warnings;
<span class="hljs-comment"># load the API package</span>
<span class="hljs-keyword">use</span> WWW::SwaggerClient::DefaultApi;

<span class="hljs-comment"># load the models</span>
<span class="hljs-keyword">use</span> WWW::SwaggerClient::Object::InlineResponse20<span class="hljs-number">0</span>;

<span class="hljs-comment"># for displaying the API response data</span>
<span class="hljs-keyword">use</span> Data::Dumper;

<span class="hljs-keyword">my</span> <span class="hljs-variable">$api_instance</span> = WWW::SwaggerClient::DefaultApi-&gt;new();
<span class="hljs-keyword">my</span> <span class="hljs-variable">$rpt_type</span> = <span class="hljs-number">1.2</span>; <span class="hljs-comment"># double | Report type. (0 report, 1 widget, 2 chart).</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$rpt_id</span> = <span class="hljs-number">1.2</span>; <span class="hljs-comment"># double | Report id.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$start</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | Start offset.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$limit</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | Number of results to return. Max 10K.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$sort_by</span> = <span class="hljs-string">'sort_by_example'</span>; <span class="hljs-comment"># string | Sort column.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$sort_type</span> = <span class="hljs-string">'sort_type_example'</span>; <span class="hljs-comment"># string | Sort mode asc/desc.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$from_date</span> = <span class="hljs-string">'from_date_example'</span>; <span class="hljs-comment"># string | Start date time.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$to_date</span> = <span class="hljs-string">'to_date_example'</span>; <span class="hljs-comment"># string | End date time.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$duration</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | Duration range.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$phone</span> = <span class="hljs-string">'phone_example'</span>; <span class="hljs-comment"># string | List of caller phone.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$phone1</span> = <span class="hljs-string">'phone1_example'</span>; <span class="hljs-comment"># string | List of dialled phones.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$co</span> = <span class="hljs-string">'co_example'</span>; <span class="hljs-comment"># string | List of trunk/co.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$ext</span> = <span class="hljs-string">'ext_example'</span>; <span class="hljs-comment"># string | list of extensions.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$pbx_id</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | list of PBX Ids.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$call_source</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | list of callsource.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$call_type</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | list of call type signatures.(5 Unanswered Calls, 7 Transfered Calls, 8 Forwarded Calls)</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$direction</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | list of direction.(0 incoming, 1 outgoing, 2 internal)</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$caller_name</span> = <span class="hljs-string">'caller_name_example'</span>; <span class="hljs-comment"># string | list of caller name.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$did</span> = <span class="hljs-string">'did_example'</span>; <span class="hljs-comment"># string | list of did.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$dnis</span> = <span class="hljs-string">'dnis_example'</span>; <span class="hljs-comment"># string | list of dnis.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$acc</span> = <span class="hljs-string">'acc_example'</span>; <span class="hljs-comment"># string | list of account code.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$ring</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | Ring range.Seconds unit.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$cost</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | Cost range.</span>
<span class="hljs-keyword">my</span> <span class="hljs-variable">$group</span> = <span class="hljs-number">3.4</span>; <span class="hljs-comment"># Number | Department/Group id.</span>

<span class="hljs-keyword">eval</span> {
    <span class="hljs-keyword">my</span> <span class="hljs-variable">$result</span> = <span class="hljs-variable">$api_instance</span>-&gt;calls_get(<span class="hljs-string">rpt_type =&gt;</span> <span class="hljs-variable">$rpt_type</span>, <span class="hljs-string">rpt_id =&gt;</span> <span class="hljs-variable">$rpt_id</span>, <span class="hljs-string">start =&gt;</span> <span class="hljs-variable">$start</span>, <span class="hljs-string">limit =&gt;</span> <span class="hljs-variable">$limit</span>, <span class="hljs-string">sort_by =&gt;</span> <span class="hljs-variable">$sort_by</span>, <span class="hljs-string">sort_type =&gt;</span> <span class="hljs-variable">$sort_type</span>, <span class="hljs-string">from_date =&gt;</span> <span class="hljs-variable">$from_date</span>, <span class="hljs-string">to_date =&gt;</span> <span class="hljs-variable">$to_date</span>, <span class="hljs-string">duration =&gt;</span> <span class="hljs-variable">$duration</span>, <span class="hljs-string">phone =&gt;</span> <span class="hljs-variable">$phone</span>, <span class="hljs-string">phone1 =&gt;</span> <span class="hljs-variable">$phone1</span>, <span class="hljs-string">co =&gt;</span> <span class="hljs-variable">$co</span>, <span class="hljs-string">ext =&gt;</span> <span class="hljs-variable">$ext</span>, <span class="hljs-string">pbx_id =&gt;</span> <span class="hljs-variable">$pbx_id</span>, <span class="hljs-string">call_source =&gt;</span> <span class="hljs-variable">$call_source</span>, <span class="hljs-string">call_type =&gt;</span> <span class="hljs-variable">$call_type</span>, <span class="hljs-string">direction =&gt;</span> <span class="hljs-variable">$direction</span>, <span class="hljs-string">caller_name =&gt;</span> <span class="hljs-variable">$caller_name</span>, <span class="hljs-string">did =&gt;</span> <span class="hljs-variable">$did</span>, <span class="hljs-string">dnis =&gt;</span> <span class="hljs-variable">$dnis</span>, <span class="hljs-string">acc =&gt;</span> <span class="hljs-variable">$acc</span>, <span class="hljs-string">ring =&gt;</span> <span class="hljs-variable">$ring</span>, <span class="hljs-string">cost =&gt;</span> <span class="hljs-variable">$cost</span>, <span class="hljs-string">group =&gt;</span> <span class="hljs-variable">$group</span>);
    <span class="hljs-keyword">print</span> Dumper(<span class="hljs-variable">$result</span>);
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$@</span>) {
    <span class="hljs-keyword">warn</span> <span class="hljs-string">"Exception when calling DefaultApi-&gt;calls_get: <span class="hljs-variable">$@</span>\n"</span>;


All URIs are relative to

ClassMethodHTTP requestDescription
DefaultApicalls_getGET /Calls
DefaultApifeatures_charts_getGET /Features/charts
DefaultApifeatures_reports_getGET /Features/reports
DefaultApifeatures_widget_getGET /Features/widget

Download Perl Sample Code