| 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::ApiFactory; | ||
| 33 | |||
| 34 | use strict; | ||
| 35 | use warnings; | ||
| 36 | use utf8; | ||
| 37 | |||
| 38 | use Carp; | ||
| 39 | use Module::Find; | ||
| 40 | |||
| 41 | usesub SQL::QueryBuilder::WebApi::Object; | ||
| 42 | |||
| 43 | use SQL::QueryBuilder::WebApi::ApiClient; | ||
| 44 | |||
| 45 | =head1 Name | ||
| 46 | |||
| 47 | SQL::QueryBuilder::WebApi::ApiFactory - constructs APIs to retrieve SQL::QueryBuilder::WebApi objects | ||
| 48 | |||
| 49 | =head1 Synopsis | ||
| 50 | |||
| 51 | package My::Petstore::App; | ||
| 52 | |||
| 53 | use SQL::QueryBuilder::WebApi::ApiFactory; | ||
| 54 | |||
| 55 | my $api_factory = SQL::QueryBuilder::WebApi::ApiFactory->new( ... ); # any args for ApiClient constructor | ||
| 56 | |||
| 57 | # later... | ||
| 58 | my $pet_api = $api_factory->get_api('Pet'); | ||
| 59 | |||
| 60 | # $pet_api isa SQL::QueryBuilder::WebApi::PetApi | ||
| 61 | |||
| 62 | my $pet = $pet_api->get_pet_by_id(pet_id => $pet_id); | ||
| 63 | |||
| 64 | # object attributes have proper accessors: | ||
| 65 | printf "Pet's name is %s", $pet->name; | ||
| 66 | |||
| 67 | # change the value stored on the object: | ||
| 68 | $pet->name('Dave'); | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | # Load all the API classes and construct a lookup table at startup time | ||
| 73 | my %_apis = map { $_ =~ /^SQL::QueryBuilder::WebApi::(.*)$/; $1 => $_ } | ||
| 74 | grep {$_ =~ /Api$/} | ||
| 75 | usesub 'SQL::QueryBuilder::WebApi'; | ||
| 76 | |||
| 77 | =head1 new() | ||
| 78 | |||
| 79 | Any parameters are optional, and are passed to and stored on the api_client object. | ||
| 80 | |||
| 81 | base_url: (optional) | ||
| 82 | supply this to change the default base URL taken from the Swagger definition. | ||
| 83 | |||
| 84 | =cut | ||
| 85 | |||
| 86 | sub new { | ||
| 87 | my ($class, %p) = (shift, @_); | ||
| 88 | $p{api_client} = SQL::QueryBuilder::WebApi::ApiClient->instance(%p); | ||
| 89 | return bless \%p, $class; | ||
| 90 | } | ||
| 91 | |||
| 92 | =head1 get_api($which) | ||
| 93 | |||
| 94 | Returns an API object of the requested type. | ||
| 95 | |||
| 96 | $which is a nickname for the class: | ||
| 97 | |||
| 98 | FooBarClient::BazApi has nickname 'Baz' | ||
| 99 | |||
| 100 | =cut | ||
| 101 | |||
| 102 | sub get_api { | ||
| 103 | my ($self, $which) = @_; | ||
| 104 | croak "API not specified" unless $which; | ||
| 105 | my $api_class = $_apis{"${which}Api"} || croak "No known API for '$which'"; | ||
| 106 | return $api_class->new(api_client => $self->api_client); | ||
| 107 | } | ||
| 108 | |||
| 109 | =head1 api_client() | ||
| 110 | |||
| 111 | Returns the api_client object, should you ever need it. | ||
| 112 | |||
| 113 | =cut | ||
| 114 | |||
| 115 | sub api_client { $_[0]->{api_client} } | ||
| 116 | |||
| 117 | =head1 apis_available() | ||
| 118 | =cut | ||
| 119 | |||
| 120 | sub apis_available { return map { $_ =~ s/Api$//; $_ } sort keys %_apis } | ||
| 121 | |||
| 122 | =head1 classname_for() | ||
| 123 | =cut | ||
| 124 | |||
| 125 | sub classname_for { | ||
| 126 | my ($self, $api_name) = @_; | ||
| 127 | return $_apis{"${api_name}Api"}; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | 1; |