WWW::OpenAPIClient::Role - a Moose role for the WhatsAPI Go
The V2 of WhatsAPI Go
Automatically generated by the OpenAPI Generator project:
- API version: 2.0
- Package version: 1.0.0
- Build package: org.openapitools.codegen.languages.PerlClientCodegen
This role is the only component of the library that uses Moose. See WWW::OpenAPIClient::ApiFactory for non-Moosey usage.
The Perl Generator in the OpenAPI Generator 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 library.
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 role.
package MyApp;
use Moose;
with 'WWW::OpenAPIClient::Role';
package main;
my $api = MyApp->new({ tokens => $tokens });
my $pet = $api->get_pet_by_id(pet_id => $pet_id);
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.
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 => $username,
password => $password,
# oauth
access_token => $oauth_token,
# keys
$some_key => { token => $token,
prefix => $prefix,
in => $in, # 'head||query',
},
$another => { token => $token,
prefix => $prefix,
in => $in, # 'head||query',
},
...,
};
my $api = MyApp->new({ tokens => $tokens });
Note these are all optional, as are prefix
and in
, and depend on the API
you are accessing. Usually prefix
and in
will be determined by the code generator from
the spec and you will not need to set them at run time. If not, in
will
default to 'head' and prefix
to the empty string.
The tokens will be placed in a LWWW::OpenAPIClient::Configuration instance as follows, but you don't need to know about this.
-
$cfg->{username}
String. The username for basic auth.
-
$cfg->{password}
String. The password for basic auth.
-
$cfg->{api_key}
Hashref. Keyed on the name of each key (there can be multiple tokens).
$cfg->{api_key} = { secretKey => 'aaaabbbbccccdddd', anotherKey => '1111222233334444', };
-
$cfg->{api_key_prefix}
Hashref. Keyed on the name of each key (there can be multiple tokens). Note not all api keys require a prefix.
$cfg->{api_key_prefix} = { secretKey => 'string', anotherKey => 'same or some other string', };
-
$cfg->{access_token}
String. The OAuth access token.
The generated code has the base_url
already set as a default value. This method
returns the current value of base_url
.
Returns an API factory object. You probably won't need to call this directly.
$self->api_factory('Pet'); # returns a WWW::OpenAPIClient::PetApi instance
$self->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. new()
), these methods can't be delegated. So you need
to call $api->pet_api->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()
To call these methods, you need to get a handle on the relevant object, either
by calling $api->foo_api
or by retrieving an object, e.g.
$api->get_pet_by_id(pet_id => $pet_id)
. They are class methods, so
you could also call them on class names.
See the homepage https://openapi-generator.tech
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:
{"moduleName":"WWW::MyProjectName"}
Your library files will be built under WWW::MyProjectName
.
$ git clone https://github.com/openapitools/openapi-generator
$ cd openapi-generator
$ mvn package
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i [URL or file path to JSON OpenAPI API spec] \
-g perl \
-c /path/to/config/file.json \
-o /path/to/output/folder
Bang, all done. Run the autodoc
script in the bin
directory to see the API
you just built.
You can print out a summary of the generated API by running the included
autodoc
script in the bin
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
The -c
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 OpenAPI
spec. If so, this is available via the class_documentation()
and
method_documentation()
methods on each generated object class, and the
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.
Use cpanm to install the module dependencies:
cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
cpanm --quiet --no-interactive Class::Accessor Test::Exception Test::More Log::Any LWP::UserAgent URI::Query Module::Runtime DateTime Module::Find Moose::Role JSON
To load the API packages:
use WWW::OpenAPIClient::BusinessManagementApi;
use WWW::OpenAPIClient::GroupManagementApi;
use WWW::OpenAPIClient::InstanceApi;
use WWW::OpenAPIClient::MessageSendingApi;
use WWW::OpenAPIClient::MiscellaneousApi;
To load the models:
use WWW::OpenAPIClient::Object::APIResponse;
use WWW::OpenAPIClient::Object::ButtonMessagePayload;
use WWW::OpenAPIClient::Object::ButtonMessageWithMediaPayload;
use WWW::OpenAPIClient::Object::ContactMessagePayload;
use WWW::OpenAPIClient::Object::ContactMessagePayloadVcard;
use WWW::OpenAPIClient::Object::CreateInstancePayload;
use WWW::OpenAPIClient::Object::FileUpload;
use WWW::OpenAPIClient::Object::GroupCreatePayload;
use WWW::OpenAPIClient::Object::GroupInviteMessagePayload;
use WWW::OpenAPIClient::Object::GroupUpdateDescriptionPayload;
use WWW::OpenAPIClient::Object::GroupUpdateNamePayload;
use WWW::OpenAPIClient::Object::GroupUpdateParticipantsPayload;
use WWW::OpenAPIClient::Object::ListItem;
use WWW::OpenAPIClient::Object::ListMessagePayload;
use WWW::OpenAPIClient::Object::ListSection;
use WWW::OpenAPIClient::Object::LocationMessagePayload;
use WWW::OpenAPIClient::Object::LocationMessagePayloadLocation;
use WWW::OpenAPIClient::Object::PaymentRequestPayload;
use WWW::OpenAPIClient::Object::PollMessagePayload;
use WWW::OpenAPIClient::Object::ReplyButton;
use WWW::OpenAPIClient::Object::SendAudioRequest;
use WWW::OpenAPIClient::Object::SendDocumentRequest;
use WWW::OpenAPIClient::Object::SendMediaPayload;
use WWW::OpenAPIClient::Object::SendVideoRequest;
use WWW::OpenAPIClient::Object::SetGroupPictureRequest;
use WWW::OpenAPIClient::Object::TemplateButton;
use WWW::OpenAPIClient::Object::TemplateButtonPayload;
use WWW::OpenAPIClient::Object::TemplateButtonWithMediaPayload;
use WWW::OpenAPIClient::Object::TextMessage;
use WWW::OpenAPIClient::Object::UpdateProfilePicRequest;
use WWW::OpenAPIClient::Object::UploadMediaRequest;
use WWW::OpenAPIClient::Object::UrlMediaUploadPayload;
use WWW::OpenAPIClient::Object::UserInfoPayload;
use WWW::OpenAPIClient::Object::WebhookPayload;
Put the Perl SDK under the 'lib' folder in your project directory, then run the following
#!/usr/bin/perl
use lib 'lib';
use strict;
use warnings;
# load the API package
use WWW::OpenAPIClient::BusinessManagementApi;
use WWW::OpenAPIClient::GroupManagementApi;
use WWW::OpenAPIClient::InstanceApi;
use WWW::OpenAPIClient::MessageSendingApi;
use WWW::OpenAPIClient::MiscellaneousApi;
# load the models
use WWW::OpenAPIClient::Object::APIResponse;
use WWW::OpenAPIClient::Object::ButtonMessagePayload;
use WWW::OpenAPIClient::Object::ButtonMessageWithMediaPayload;
use WWW::OpenAPIClient::Object::ContactMessagePayload;
use WWW::OpenAPIClient::Object::ContactMessagePayloadVcard;
use WWW::OpenAPIClient::Object::CreateInstancePayload;
use WWW::OpenAPIClient::Object::FileUpload;
use WWW::OpenAPIClient::Object::GroupCreatePayload;
use WWW::OpenAPIClient::Object::GroupInviteMessagePayload;
use WWW::OpenAPIClient::Object::GroupUpdateDescriptionPayload;
use WWW::OpenAPIClient::Object::GroupUpdateNamePayload;
use WWW::OpenAPIClient::Object::GroupUpdateParticipantsPayload;
use WWW::OpenAPIClient::Object::ListItem;
use WWW::OpenAPIClient::Object::ListMessagePayload;
use WWW::OpenAPIClient::Object::ListSection;
use WWW::OpenAPIClient::Object::LocationMessagePayload;
use WWW::OpenAPIClient::Object::LocationMessagePayloadLocation;
use WWW::OpenAPIClient::Object::PaymentRequestPayload;
use WWW::OpenAPIClient::Object::PollMessagePayload;
use WWW::OpenAPIClient::Object::ReplyButton;
use WWW::OpenAPIClient::Object::SendAudioRequest;
use WWW::OpenAPIClient::Object::SendDocumentRequest;
use WWW::OpenAPIClient::Object::SendMediaPayload;
use WWW::OpenAPIClient::Object::SendVideoRequest;
use WWW::OpenAPIClient::Object::SetGroupPictureRequest;
use WWW::OpenAPIClient::Object::TemplateButton;
use WWW::OpenAPIClient::Object::TemplateButtonPayload;
use WWW::OpenAPIClient::Object::TemplateButtonWithMediaPayload;
use WWW::OpenAPIClient::Object::TextMessage;
use WWW::OpenAPIClient::Object::UpdateProfilePicRequest;
use WWW::OpenAPIClient::Object::UploadMediaRequest;
use WWW::OpenAPIClient::Object::UrlMediaUploadPayload;
use WWW::OpenAPIClient::Object::UserInfoPayload;
use WWW::OpenAPIClient::Object::WebhookPayload;
# for displaying the API response data
use Data::Dumper;
my $api_instance = WWW::OpenAPIClient::BusinessManagementApi->new(
# Configure API key authorization: ApiKeyAuth
api_key => {'Authorization' => 'YOUR_API_KEY'},
# uncomment below to setup prefix (e.g. Bearer) for API key, if needed
#api_key_prefix => {'Authorization' => 'Bearer'},
);
my $instance_key = "instance_key_example"; # string | Instance key
eval {
my $result = $api_instance->fetch_catlog(instance_key => $instance_key);
print Dumper($result);
};
if ($@) {
warn "Exception when calling BusinessManagementApi->fetch_catlog: $@\n";
}
All URIs are relative to /api
Class | Method | HTTP request | Description |
---|---|---|---|
BusinessManagementApi | fetch_catlog | GET /instances/{instance_key}/business/catalog | Fetches the catlog. |
BusinessManagementApi | send_payment_request | POST /instances/{instance_key}/business/payment-request | Send a payment request. |
GroupManagementApi | add_participant | POST /instances/{instance_key}/groups/{group_id}/participants/add | Add participant. |
GroupManagementApi | create_group | POST /instances/{instance_key}/groups/create | Create group. |
GroupManagementApi | demote_participant | PUT /instances/{instance_key}/groups/{group_id}/participants/demote | Demote participant. |
GroupManagementApi | get_admin_groups | GET /instances/{instance_key}/groups/admin | Get admin groups. |
GroupManagementApi | get_all_groups | GET /instances/{instance_key}/groups/ | Get all groups. |
GroupManagementApi | get_all_participants | GET /instances/{instance_key}/groups/{group_id}/participants | Get all participants. |
GroupManagementApi | get_group | GET /instances/{instance_key}/groups/{group_id} | Get group. |
GroupManagementApi | get_group_from_invite_link | GET /instances/{instance_key}/groups/invite-info | Get group from invite link. |
GroupManagementApi | get_group_invite_code | GET /instances/{instance_key}/groups/{group_id}/invite-code | Get group invite code. |
GroupManagementApi | join_group_with_link | GET /instances/{instance_key}/groups/join | Join group with invite code. |
GroupManagementApi | leave_group | DELETE /instances/{instance_key}/groups/{group_id}/ | Leaves the group. |
GroupManagementApi | promote_participant | PUT /instances/{instance_key}/groups/{group_id}/participants/promote | Promote participant. |
GroupManagementApi | remove_participant | DELETE /instances/{instance_key}/groups/{group_id}/participants/remove | Remove participant. |
GroupManagementApi | set_group_announce | PUT /instances/{instance_key}/groups/{group_id}/announce | Set group announce. |
GroupManagementApi | set_group_description | PUT /instances/{instance_key}/groups/{group_id}/description | Set group description. |
GroupManagementApi | set_group_locked | PUT /instances/{instance_key}/groups/{group_id}/lock | Set group locked. |
GroupManagementApi | set_group_name | PUT /instances/{instance_key}/groups/{group_id}/name | Set group name. |
GroupManagementApi | set_group_picture | PUT /instances/{instance_key}/groups/{group_id}/profile-pic | Set group picture. |
InstanceApi | change_webhook_url | PUT /instances/{instance_key}/webhook | Change Webhook url. |
InstanceApi | create_instance | POST /instances/create | Creates a new instance key. |
InstanceApi | delete_instance | DELETE /instances/{instance_key}/delete | Delete Instance. |
InstanceApi | get_contacts | GET /instances/{instance_key}/contacts | Get contacts. |
InstanceApi | get_instance | GET /instances/{instance_key}/ | Get Instance. |
InstanceApi | get_qr_code | GET /instances/{instance_key}/qrcode | Get QrCode. |
InstanceApi | list_instances | GET /instances/list | Get all instances. |
InstanceApi | logout_instance | DELETE /instances/{instance_key}/logout | Logout Instance. |
MessageSendingApi | send_audio | POST /instances/{instance_key}/send/audio | Send raw audio. |
MessageSendingApi | send_button_message | POST /instances/{instance_key}/send/buttons | Send a button message. |
MessageSendingApi | send_button_with_media | POST /instances/{instance_key}/send/button-media | Send a button message with a media header. |
MessageSendingApi | send_contact | POST /instances/{instance_key}/send/contact | Send a contact message. |
MessageSendingApi | send_document | POST /instances/{instance_key}/send/document | Send raw document. |
MessageSendingApi | send_group_invite | POST /instances/{instance_key}/send/group-invite | Send a group invite message |
MessageSendingApi | send_image | POST /instances/{instance_key}/send/image | Send raw image. |
MessageSendingApi | send_list_message | POST /instances/{instance_key}/send/list | Send a List message. |
MessageSendingApi | send_location | POST /instances/{instance_key}/send/location | Send a location message. |
MessageSendingApi | send_media_message | POST /instances/{instance_key}/send/media | Send a media message. |
MessageSendingApi | send_poll_message | POST /instances/{instance_key}/send/poll | Send a Poll message. |
MessageSendingApi | send_template | POST /instances/{instance_key}/send/template | Send a template message. |
MessageSendingApi | send_template_with_media | POST /instances/{instance_key}/send/template-media | Send a template message with media. |
MessageSendingApi | send_text_message | POST /instances/{instance_key}/send/text | Send a text message. |
MessageSendingApi | send_video | POST /instances/{instance_key}/send/video | Send raw video. |
MessageSendingApi | upload_media | POST /instances/{instance_key}/send/upload | Upload media. |
MessageSendingApi | upload_media_from_url | POST /instances/{instance_key}/send/upload-url | Upload media from url. |
MiscellaneousApi | download_media | POST /instances/{instance_key}/misc/download | Download media |
MiscellaneousApi | get_profile_pic | GET /instances/{instance_key}/misc/profile-pic | Get profile pic. |
MiscellaneousApi | get_users_info | POST /instances/{instance_key}/misc/user-info | Fetches the users info. |
MiscellaneousApi | set_chat_presence | POST /instances/{instance_key}/misc/chat-presence | Set chat presence |
MiscellaneousApi | update_profile_pic | PUT /instances/{instance_key}/misc/profile-pic | Update profile picture |
- WWW::OpenAPIClient::Object::APIResponse
- WWW::OpenAPIClient::Object::ButtonMessagePayload
- WWW::OpenAPIClient::Object::ButtonMessageWithMediaPayload
- WWW::OpenAPIClient::Object::ContactMessagePayload
- WWW::OpenAPIClient::Object::ContactMessagePayloadVcard
- WWW::OpenAPIClient::Object::CreateInstancePayload
- WWW::OpenAPIClient::Object::FileUpload
- WWW::OpenAPIClient::Object::GroupCreatePayload
- WWW::OpenAPIClient::Object::GroupInviteMessagePayload
- WWW::OpenAPIClient::Object::GroupUpdateDescriptionPayload
- WWW::OpenAPIClient::Object::GroupUpdateNamePayload
- WWW::OpenAPIClient::Object::GroupUpdateParticipantsPayload
- WWW::OpenAPIClient::Object::ListItem
- WWW::OpenAPIClient::Object::ListMessagePayload
- WWW::OpenAPIClient::Object::ListSection
- WWW::OpenAPIClient::Object::LocationMessagePayload
- WWW::OpenAPIClient::Object::LocationMessagePayloadLocation
- WWW::OpenAPIClient::Object::PaymentRequestPayload
- WWW::OpenAPIClient::Object::PollMessagePayload
- WWW::OpenAPIClient::Object::ReplyButton
- WWW::OpenAPIClient::Object::SendAudioRequest
- WWW::OpenAPIClient::Object::SendDocumentRequest
- WWW::OpenAPIClient::Object::SendMediaPayload
- WWW::OpenAPIClient::Object::SendVideoRequest
- WWW::OpenAPIClient::Object::SetGroupPictureRequest
- WWW::OpenAPIClient::Object::TemplateButton
- WWW::OpenAPIClient::Object::TemplateButtonPayload
- WWW::OpenAPIClient::Object::TemplateButtonWithMediaPayload
- WWW::OpenAPIClient::Object::TextMessage
- WWW::OpenAPIClient::Object::UpdateProfilePicRequest
- WWW::OpenAPIClient::Object::UploadMediaRequest
- WWW::OpenAPIClient::Object::UrlMediaUploadPayload
- WWW::OpenAPIClient::Object::UserInfoPayload
- WWW::OpenAPIClient::Object::WebhookPayload
- Type: API key
- API key parameter name: Authorization
- Location: HTTP header