| 1 | =begin comment | ||
| 2 | |||
| 3 | Fastly API | ||
| 4 | |||
| 5 | Via the Fastly API you can perform any of the operations that are possible within the management console, including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) | ||
| 6 | |||
| 7 | The version of the API Spec document: 1.0.0 | ||
| 8 | Contact: oss@fastly.com | ||
| 9 | |||
| 10 | =end comment | ||
| 11 | |||
| 12 | =cut | ||
| 13 | |||
| 14 | # | ||
| 15 | # NOTE: This class is auto generated. | ||
| 16 | # Do not edit the class manually. | ||
| 17 | # | ||
| 18 | package WebService::Fastly::ApiFactory; | ||
| 19 | |||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | use utf8; | ||
| 23 | |||
| 24 | use Carp; | ||
| 25 | use Module::Find; | ||
| 26 | |||
| 27 | usesub WebService::Fastly::Object; | ||
| 28 | |||
| 29 | use WebService::Fastly::ApiClient; | ||
| 30 | |||
| 31 | =head1 Name | ||
| 32 | |||
| 33 | WebService::Fastly::ApiFactory - constructs APIs to retrieve WebService::Fastly objects | ||
| 34 | |||
| 35 | =head1 Synopsis | ||
| 36 | |||
| 37 | package My::Petstore::App; | ||
| 38 | |||
| 39 | use WebService::Fastly::ApiFactory; | ||
| 40 | |||
| 41 | my $api_factory = WebService::Fastly::ApiFactory->new( ... ); # any args for ApiClient constructor | ||
| 42 | |||
| 43 | # later... | ||
| 44 | my $pet_api = $api_factory->get_api('Pet'); | ||
| 45 | |||
| 46 | # $pet_api isa WebService::Fastly::PetApi | ||
| 47 | |||
| 48 | my $pet = $pet_api->get_pet_by_id(pet_id => $pet_id); | ||
| 49 | |||
| 50 | # object attributes have proper accessors: | ||
| 51 | printf "Pet's name is %s", $pet->name; | ||
| 52 | |||
| 53 | # change the value stored on the object: | ||
| 54 | $pet->name('Dave'); | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | # Load all the API classes and construct a lookup table at startup time | ||
| 59 | my %_apis = map { $_ =~ /^WebService::Fastly::(.*)$/; $1 => $_ } | ||
| 60 | grep {$_ =~ /Api$/} | ||
| 61 | usesub 'WebService::Fastly'; | ||
| 62 | |||
| 63 | =head1 new($api_client) | ||
| 64 | |||
| 65 | create a new WebService::Fastly::ApiFactory instance with the given WebService::Fastly::ApiClient instance. | ||
| 66 | |||
| 67 | =head1 new(%parameters) | ||
| 68 | |||
| 69 | Any parameters are optional, and are passed to and stored on the api_client object. | ||
| 70 | |||
| 71 | See L<WebService::Fastly::ApiClient> and L<WebService::Fastly::Configuration> for valid parameters | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | sub new { | ||
| 76 | my ($class) = shift; | ||
| 77 | |||
| 78 | my $api_client; | ||
| 79 | if ($_[0] && ref $_[0] && ref $_[0] eq 'WebService::Fastly::ApiClient' ) { | ||
| 80 | $api_client = $_[0]; | ||
| 81 | } else { | ||
| 82 | $api_client = WebService::Fastly::ApiClient->new(@_); | ||
| 83 | } | ||
| 84 | bless { api_client => $api_client }, $class; | ||
| 85 | } | ||
| 86 | |||
| 87 | =head1 get_api($which) | ||
| 88 | |||
| 89 | Returns an API object of the requested type. | ||
| 90 | |||
| 91 | $which is a nickname for the class: | ||
| 92 | |||
| 93 | FooBarClient::BazApi has nickname 'Baz' | ||
| 94 | |||
| 95 | =cut | ||
| 96 | |||
| 97 | sub get_api { | ||
| 98 | my ($self, $which) = @_; | ||
| 99 | croak "API not specified" unless $which; | ||
| 100 | my $api_class = $_apis{"${which}Api"} || croak "No known API for '$which'"; | ||
| 101 | return $api_class->new($self->api_client); | ||
| 102 | } | ||
| 103 | |||
| 104 | =head1 api_client() | ||
| 105 | |||
| 106 | Returns the api_client object, should you ever need it. | ||
| 107 | |||
| 108 | =cut | ||
| 109 | |||
| 110 | sub api_client { $_[0]->{api_client} } | ||
| 111 | |||
| 112 | =head1 apis_available() | ||
| 113 | =cut | ||
| 114 | |||
| 115 | sub apis_available { return map { $_ =~ s/Api$//; $_ } sort keys %_apis } | ||
| 116 | |||
| 117 | =head1 classname_for() | ||
| 118 | =cut | ||
| 119 | |||
| 120 | sub classname_for { | ||
| 121 | my ($self, $api_name) = @_; | ||
| 122 | return $_apis{"${api_name}Api"}; | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | 1; |