| 1 | =begin comment | ||
| 2 | |||
| 3 | QueryBuilderApi | ||
| 4 | |||
| 5 | Active Query Builder Web API lets create, analyze and modify SQL queries for different database servers using RESTful HTTP requests to a cloud-based service. It requires SQL execution context (information about database schema and used database server) to be stored under the registered account at https://webapi.activequerybuilder.com/. | ||
| 6 | |||
| 7 | OpenAPI spec version: 1.1.8 | ||
| 8 | Contact: support@activedbsoft.com | ||
| 9 | Generated by: https://github.com/swagger-api/swagger-codegen.git | ||
| 10 | |||
| 11 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 12 | you may not use this file except in compliance with the License. | ||
| 13 | You may obtain a copy of the License at | ||
| 14 | |||
| 15 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 16 | |||
| 17 | Unless required by applicable law or agreed to in writing, software | ||
| 18 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 19 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 20 | See the License for the specific language governing permissions and | ||
| 21 | limitations under the License. | ||
| 22 | |||
| 23 | =end comment | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | # | ||
| 28 | # NOTE: This class is auto generated by the swagger code generator program. | ||
| 29 | # Do not edit the class manually. | ||
| 30 | # Ref: https://github.com/swagger-api/swagger-codegen | ||
| 31 | # | ||
| 32 | package SQL::QueryBuilder::WebApi::Role; | ||
| 33 | use utf8; | ||
| 34 | |||
| 35 | use Moose::Role; | ||
| 36 | use namespace::autoclean; | ||
| 37 | use Class::Inspector; | ||
| 38 | use Log::Any qw($log); | ||
| 39 | use SQL::QueryBuilder::WebApi::ApiFactory; | ||
| 40 | |||
| 41 | has base_url => ( is => 'ro', | ||
| 42 | required => 0, | ||
| 43 | isa => 'Str', | ||
| 44 | documentation => 'Root of the server that requests are sent to', | ||
| 45 | ); | ||
| 46 | |||
| 47 | has api_factory => ( is => 'ro', | ||
| 48 | isa => 'SQL::QueryBuilder::WebApi::ApiFactory', | ||
| 49 | builder => '_build_af', | ||
| 50 | lazy => 1, | ||
| 51 | documentation => 'Builds an instance of the endpoint API class', | ||
| 52 | ); | ||
| 53 | |||
| 54 | has tokens => ( is => 'ro', | ||
| 55 | isa => 'HashRef', | ||
| 56 | required => 0, | ||
| 57 | default => sub { {} }, | ||
| 58 | documentation => 'The auth tokens required by the application - basic, OAuth and/or API key(s)', | ||
| 59 | ); | ||
| 60 | |||
| 61 | has _cfg => ( is => 'ro', | ||
| 62 | isa => 'Str', | ||
| 63 | default => 'SQL::QueryBuilder::WebApi::Configuration', | ||
| 64 | ); | ||
| 65 | |||
| 66 | has version_info => ( is => 'ro', | ||
| 67 | isa => 'HashRef', | ||
| 68 | default => sub { { | ||
| 69 | app_name => 'QueryBuilderApi', | ||
| 70 | app_version => '1.1.8', | ||
| 71 | generated_date => '2016-11-29T18:45:19.605+06:00', | ||
| 72 | generator_class => 'class io.swagger.codegen.languages.PerlClientCodegen', | ||
| 73 | } }, | ||
| 74 | documentation => 'Information about the application version and the codegen codebase version' | ||
| 75 | ); | ||
| 76 | |||
| 77 | sub BUILD { | ||
| 78 | my $self = shift; | ||
| 79 | |||
| 80 | $self->_cfg->accept_tokens( $self->tokens ) if keys %{$self->tokens}; | ||
| 81 | |||
| 82 | # ignore these symbols imported into API namespaces | ||
| 83 | my %outsiders = map {$_ => 1} qw( croak ); | ||
| 84 | |||
| 85 | my %delegates; | ||
| 86 | |||
| 87 | # collect the methods callable on each API | ||
| 88 | foreach my $api_name ($self->api_factory->apis_available) { | ||
| 89 | my $api_class = $self->api_factory->classname_for($api_name); | ||
| 90 | my $methods = Class::Inspector->methods($api_class, 'expanded'); # not Moose, so use CI instead | ||
| 91 | my @local_methods = grep {! /^_/} grep {! $outsiders{$_}} map {$_->[2]} grep {$_->[1] eq $api_class} @$methods; | ||
| 92 | push( @{$delegates{$_}}, {api_name => $api_name, api_class => $api_class} ) for @local_methods; | ||
| 93 | } | ||
| 94 | |||
| 95 | # remove clashes | ||
| 96 | foreach my $method (keys %delegates) { | ||
| 97 | if ( @{$delegates{$method}} > 1 ) { | ||
| 98 | my ($apis) = delete $delegates{$method}; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | # build the flattened API | ||
| 103 | foreach my $api_name ($self->api_factory->apis_available) { | ||
| 104 | my $att_name = sprintf "%s_api", lc($api_name); | ||
| 105 | my $api_class = $self->api_factory->classname_for($api_name); | ||
| 106 | my @delegated = grep { $delegates{$_}->[0]->{api_name} eq $api_name } keys %delegates; | ||
| 107 | $log->debugf("Adding API: '%s' handles %s", $att_name, join ', ', @delegated); | ||
| 108 | $self->meta->add_attribute( $att_name => ( | ||
| 109 | is => 'ro', | ||
| 110 | isa => $api_class, | ||
| 111 | default => sub {$self->api_factory->get_api($api_name)}, | ||
| 112 | lazy => 1, | ||
| 113 | handles => \@delegated, | ||
| 114 | ) ); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | sub _build_af { | ||
| 119 | my $self = shift; | ||
| 120 | my %args; | ||
| 121 | $args{base_url} = $self->base_url if $self->base_url; | ||
| 122 | return SQL::QueryBuilder::WebApi::ApiFactory->new(%args); | ||
| 123 | } | ||
| 124 | |||
| 125 | =head1 NAME | ||
| 126 | |||
| 127 | SQL::QueryBuilder::WebApi::Role - a Moose role for the QueryBuilderApi | ||
| 128 | |||
| 129 | =head2 QueryBuilderApi version: 1.1.8 | ||
| 130 | |||
| 131 | =head1 VERSION | ||
| 132 | |||
| 133 | Automatically generated by the Perl Swagger Codegen project: | ||
| 134 | |||
| 135 | =over 4 | ||
| 136 | |||
| 137 | =item Build date: 2016-11-29T18:45:19.605+06:00 | ||
| 138 | |||
| 139 | =item Build package: class io.swagger.codegen.languages.PerlClientCodegen | ||
| 140 | |||
| 141 | =item Codegen version: | ||
| 142 | |||
| 143 | =back | ||
| 144 | |||
| 145 | =head2 A note on Moose | ||
| 146 | |||
| 147 | This role is the only component of the library that uses Moose. See | ||
| 148 | SQL::QueryBuilder::WebApi::ApiFactory for non-Moosey usage. | ||
| 149 | |||
| 150 | =head1 SYNOPSIS | ||
| 151 | |||
| 152 | The Perl Swagger Codegen project builds a library of Perl modules to interact with | ||
| 153 | a web service defined by a OpenAPI Specification. See below for how to build the | ||
| 154 | library. | ||
| 155 | |||
| 156 | This module provides an interface to the generated library. All the classes, | ||
| 157 | objects, and methods (well, not quite *all*, see below) are flattened into this | ||
| 158 | role. | ||
| 159 | |||
| 160 | package MyApp; | ||
| 161 | use Moose; | ||
| 162 | with 'SQL::QueryBuilder::WebApi::Role'; | ||
| 163 | |||
| 164 | package main; | ||
| 165 | |||
| 166 | my $api = MyApp->new({ tokens => $tokens }); | ||
| 167 | |||
| 168 | my $pet = $api->get_pet_by_id(pet_id => $pet_id); | ||
| 169 | |||
| 170 | =head2 Structure of the library | ||
| 171 | |||
| 172 | The library consists of a set of API classes, one for each endpoint. These APIs | ||
| 173 | implement the method calls available on each endpoint. | ||
| 174 | |||
| 175 | Additionally, there is a set of "object" classes, which represent the objects | ||
| 176 | returned by and sent to the methods on the endpoints. | ||
| 177 | |||
| 178 | An API factory class is provided, which builds instances of each endpoint API. | ||
| 179 | |||
| 180 | This Moose role flattens all the methods from the endpoint APIs onto the consuming | ||
| 181 | class. It also provides methods to retrieve the endpoint API objects, and the API | ||
| 182 | factory object, should you need it. | ||
| 183 | |||
| 184 | For documentation of all these methods, see AUTOMATIC DOCUMENTATION below. | ||
| 185 | |||
| 186 | =head2 Configuring authentication | ||
| 187 | |||
| 188 | In the normal case, the OpenAPI Spec will describe what parameters are | ||
| 189 | required and where to put them. You just need to supply the tokens. | ||
| 190 | |||
| 191 | my $tokens = { | ||
| 192 | # basic | ||
| 193 | username => $username, | ||
| 194 | password => $password, | ||
| 195 | |||
| 196 | # oauth | ||
| 197 | access_token => $oauth_token, | ||
| 198 | |||
| 199 | # keys | ||
| 200 | $some_key => { token => $token, | ||
| 201 | prefix => $prefix, | ||
| 202 | in => $in, # 'head||query', | ||
| 203 | }, | ||
| 204 | |||
| 205 | $another => { token => $token, | ||
| 206 | prefix => $prefix, | ||
| 207 | in => $in, # 'head||query', | ||
| 208 | }, | ||
| 209 | ..., | ||
| 210 | |||
| 211 | }; | ||
| 212 | |||
| 213 | my $api = MyApp->new({ tokens => $tokens }); | ||
| 214 | |||
| 215 | Note these are all optional, as are C<prefix> and C<in>, and depend on the API | ||
| 216 | you are accessing. Usually C<prefix> and C<in> will be determined by the code generator from | ||
| 217 | the spec and you will not need to set them at run time. If not, C<in> will | ||
| 218 | default to 'head' and C<prefix> to the empty string. | ||
| 219 | |||
| 220 | The tokens will be placed in the C<SQL::QueryBuilder::WebApi::Configuration> namespace | ||
| 221 | as follows, but you don't need to know about this. | ||
| 222 | |||
| 223 | =over 4 | ||
| 224 | |||
| 225 | =item C<$SQL::QueryBuilder::WebApi::Configuration::username> | ||
| 226 | |||
| 227 | String. The username for basic auth. | ||
| 228 | |||
| 229 | =item C<$SQL::QueryBuilder::WebApi::Configuration::password> | ||
| 230 | |||
| 231 | String. The password for basic auth. | ||
| 232 | |||
| 233 | =item C<$SQL::QueryBuilder::WebApi::Configuration::api_key> | ||
| 234 | |||
| 235 | Hashref. Keyed on the name of each key (there can be multiple tokens). | ||
| 236 | |||
| 237 | $SQL::QueryBuilder::WebApi::Configuration::api_key = { | ||
| 238 | secretKey => 'aaaabbbbccccdddd', | ||
| 239 | anotherKey => '1111222233334444', | ||
| 240 | }; | ||
| 241 | |||
| 242 | =item C<$SQL::QueryBuilder::WebApi::Configuration::api_key_prefix> | ||
| 243 | |||
| 244 | Hashref. Keyed on the name of each key (there can be multiple tokens). Note not | ||
| 245 | all api keys require a prefix. | ||
| 246 | |||
| 247 | $SQL::QueryBuilder::WebApi::Configuration::api_key_prefix = { | ||
| 248 | secretKey => 'string', | ||
| 249 | anotherKey => 'same or some other string', | ||
| 250 | }; | ||
| 251 | |||
| 252 | =item C<$SQL::QueryBuilder::WebApi::Configuration::access_token> | ||
| 253 | |||
| 254 | String. The OAuth access token. | ||
| 255 | |||
| 256 | =back | ||
| 257 | |||
| 258 | =head1 METHODS | ||
| 259 | |||
| 260 | =head2 C<base_url> | ||
| 261 | |||
| 262 | The generated code has the C<base_url> already set as a default value. This method | ||
| 263 | returns (and optionally sets, but only if the API client has not been | ||
| 264 | created yet) the current value of C<base_url>. | ||
| 265 | |||
| 266 | =head2 C<api_factory> | ||
| 267 | |||
| 268 | Returns an API factory object. You probably won't need to call this directly. | ||
| 269 | |||
| 270 | $self->api_factory('Pet'); # returns a SQL::QueryBuilder::WebApi::PetApi instance | ||
| 271 | |||
| 272 | $self->pet_api; # the same | ||
| 273 | |||
| 274 | =head1 MISSING METHODS | ||
| 275 | |||
| 276 | Most of the methods on the API are delegated to individual endpoint API objects | ||
| 277 | (e.g. Pet API, Store API, User API etc). Where different endpoint APIs use the | ||
| 278 | same method name (e.g. C<new()>), these methods can't be delegated. So you need | ||
| 279 | to call C<$api-E<gt>pet_api-E<gt>new()>. | ||
| 280 | |||
| 281 | In principle, every API is susceptible to the presence of a few, random, undelegatable | ||
| 282 | method names. In practice, because of the way method names are constructed, it's | ||
| 283 | unlikely in general that any methods will be undelegatable, except for: | ||
| 284 | |||
| 285 | new() | ||
| 286 | class_documentation() | ||
| 287 | method_documentation() | ||
| 288 | |||
| 289 | To call these methods, you need to get a handle on the relevant object, either | ||
| 290 | by calling C<$api-E<gt>foo_api> or by retrieving an object, e.g. | ||
| 291 | C<$api-E<gt>get_pet_by_id(pet_id =E<gt> $pet_id)>. They are class methods, so | ||
| 292 | you could also call them on class names. | ||
| 293 | |||
| 294 | =head1 BUILDING YOUR LIBRARY | ||
| 295 | |||
| 296 | See the homepage C<https://github.com/swagger-api/swagger-codegen> for full details. | ||
| 297 | But briefly, clone the git repository, build the codegen codebase, set up your build | ||
| 298 | config file, then run the API build script. You will need git, Java 7 or 8 and Apache | ||
| 299 | maven 3.0.3 or better already installed. | ||
| 300 | |||
| 301 | The config file should specify the project name for the generated library: | ||
| 302 | |||
| 303 | {"moduleName":"WWW::MyProjectName"} | ||
| 304 | |||
| 305 | Your library files will be built under C<WWW::MyProjectName>. | ||
| 306 | |||
| 307 | $ git clone https://github.com/swagger-api/swagger-codegen.git | ||
| 308 | $ cd swagger-codegen | ||
| 309 | $ mvn package | ||
| 310 | $ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ | ||
| 311 | -i [URL or file path to JSON swagger API spec] \ | ||
| 312 | -l perl \ | ||
| 313 | -c /path/to/config/file.json \ | ||
| 314 | -o /path/to/output/folder | ||
| 315 | |||
| 316 | Bang, all done. Run the C<autodoc> script in the C<bin> directory to see the API | ||
| 317 | you just built. | ||
| 318 | |||
| 319 | =head1 AUTOMATIC DOCUMENTATION | ||
| 320 | |||
| 321 | You can print out a summary of the generated API by running the included | ||
| 322 | C<autodoc> script in the C<bin> directory of your generated library. A few | ||
| 323 | output formats are supported: | ||
| 324 | |||
| 325 | Usage: autodoc [OPTION] | ||
| 326 | |||
| 327 | -w wide format (default) | ||
| 328 | -n narrow format | ||
| 329 | -p POD format | ||
| 330 | -H HTML format | ||
| 331 | -m Markdown format | ||
| 332 | -h print this help message | ||
| 333 | -c your application class | ||
| 334 | |||
| 335 | The C<-c> option allows you to load and inspect your own application. A dummy | ||
| 336 | namespace is used if you don't supply your own class. | ||
| 337 | |||
| 338 | =head1 DOCUMENTATION FROM THE OpenAPI Spec | ||
| 339 | |||
| 340 | Additional documentation for each class and method may be provided by the Swagger | ||
| 341 | spec. If so, this is available via the C<class_documentation()> and | ||
| 342 | C<method_documentation()> methods on each generated object class, and the | ||
| 343 | C<method_documentation()> method on the endpoint API classes: | ||
| 344 | |||
| 345 | my $cmdoc = $api->pet_api->method_documentation->{$method_name}; | ||
| 346 | |||
| 347 | my $odoc = $api->get_pet_by_id->(pet_id => $pet_id)->class_documentation; | ||
| 348 | my $omdoc = $api->get_pet_by_id->(pet_id => $pet_id)->method_documentation->{method_name}; | ||
| 349 | |||
| 350 | Each of these calls returns a hashref with various useful pieces of information. | ||
| 351 | |||
| 352 | =cut | ||
| 353 | |||
| 354 | 1; |