2015-05-06 10:46:31 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
#
|
2015-05-07 10:01:56 +00:00
|
|
|
use lib 'lib';
|
2015-05-06 10:46:31 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use WWW::SwaggerClient::PetApi;
|
2015-06-10 02:53:21 +00:00
|
|
|
use WWW::SwaggerClient::StoreApi;
|
2015-05-28 02:51:36 +00:00
|
|
|
use WWW::SwaggerClient::ApiClient;
|
2015-05-27 14:44:56 +00:00
|
|
|
use WWW::SwaggerClient::Configuration;
|
2015-05-07 02:03:30 +00:00
|
|
|
use WWW::SwaggerClient::Object::Pet;
|
|
|
|
use WWW::SwaggerClient::Object::Tag;
|
|
|
|
use WWW::SwaggerClient::Object::Category;
|
2015-05-06 10:46:31 +00:00
|
|
|
use JSON;
|
|
|
|
use Data::Dumper;
|
2015-05-07 06:41:58 +00:00
|
|
|
use DateTime;
|
2015-05-06 10:46:31 +00:00
|
|
|
|
2015-05-27 14:44:56 +00:00
|
|
|
$WWW::SwaggerClient::Configuration::http_user_agent = 'Perl-Swagger-Test';
|
2015-06-03 00:34:45 +00:00
|
|
|
$WWW::SwaggerClient::Configuration::api_key->{'api_key'} = 'ZZZZZZZZZZZZZZ';
|
2016-05-05 19:54:22 +00:00
|
|
|
$WWW::SwaggerClient::Configuration::api_key_prefix->{'api_key'} = 'Bearer';
|
2015-05-27 14:44:56 +00:00
|
|
|
|
2015-06-03 03:21:10 +00:00
|
|
|
$WWW::SwaggerClient::Configuration::username = 'username';
|
|
|
|
$WWW::SwaggerClient::Configuration::password = 'password';
|
|
|
|
|
|
|
|
|
2015-05-06 10:46:31 +00:00
|
|
|
my $api = WWW::SwaggerClient::PetApi->new();
|
|
|
|
|
2016-02-11 10:43:51 +00:00
|
|
|
# exception handling
|
|
|
|
#eval {
|
|
|
|
# print "\nget_pet_by_id:".Dumper $api->get_pet_by_id(pet_id => 9999);
|
|
|
|
#};
|
|
|
|
#if ($@) {
|
|
|
|
# print "Exception when calling: $@\n";
|
|
|
|
#}
|
|
|
|
|
2015-05-07 19:56:35 +00:00
|
|
|
my $pet_id = 10008;
|
2015-05-07 10:01:56 +00:00
|
|
|
|
2015-05-07 12:49:35 +00:00
|
|
|
my $category = WWW::SwaggerClient::Object::Category->new('id' => '2', 'name' => 'perl');
|
|
|
|
my $tag = WWW::SwaggerClient::Object::Tag->new('id' => '1', 'name' => 'just kidding');
|
|
|
|
my $pet = WWW::SwaggerClient::Object::Pet->new('id' => $pet_id, 'name' => 'perl test',
|
|
|
|
"photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'status' => 'pending', 'category' => $category);
|
2015-05-06 10:46:31 +00:00
|
|
|
|
2015-05-07 10:01:56 +00:00
|
|
|
print "\npet(object)=".Dumper $pet;
|
2015-05-06 10:46:31 +00:00
|
|
|
my $json = JSON->new->convert_blessed;
|
|
|
|
|
2015-05-07 10:01:56 +00:00
|
|
|
my $new_pet = WWW::SwaggerClient::Object::Pet->new();
|
|
|
|
$new_pet = $new_pet->from_hash($pet->to_hash);
|
|
|
|
print "new_pet(hash):".Dumper($new_pet->to_hash);
|
|
|
|
|
|
|
|
print "\nTest Petstore endpoints\n";
|
2015-05-07 19:56:35 +00:00
|
|
|
print "\nupload_file:".Dumper $api->upload_file(pet_id => $pet_id, additional_metadata => 'testabc', file => './test.pl');
|
2015-05-07 12:49:35 +00:00
|
|
|
print "\nadd_pet:".Dumper $api->add_pet(body => $pet);
|
|
|
|
print "\nget_pet_by_id:".Dumper $api->get_pet_by_id(pet_id => $pet_id);
|
|
|
|
print "\nupdate_pet_with_form:".Dumper $api->update_pet_with_form(pet_id => $pet_id, name => 'test_name', status => 'test status');
|
|
|
|
print "\ndelete_pet:".Dumper $api->delete_pet(pet_id => $pet_id);
|
2015-05-07 07:46:43 +00:00
|
|
|
|
2015-06-10 02:53:21 +00:00
|
|
|
my $store_api = WWW::SwaggerClient::StoreApi->new();
|
|
|
|
print "\nget_inventory:".Dumper $store_api->get_inventory();
|
2015-05-07 07:46:43 +00:00
|
|
|
|
2015-06-10 02:53:21 +00:00
|
|
|
my $pet_json = <<JSON;
|
|
|
|
{
|
|
|
|
"pet": {
|
|
|
|
"id": 0,
|
|
|
|
"category": {
|
|
|
|
"id": 0,
|
|
|
|
"name": "string"
|
|
|
|
},
|
|
|
|
"name": "doggie",
|
|
|
|
"photoUrls": [
|
|
|
|
"string"
|
|
|
|
],
|
|
|
|
"tags": [
|
|
|
|
{
|
|
|
|
"id": 0,
|
|
|
|
"name": "tag string"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"status": "available"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
|
|
|
|
print "\napi_client->deserialize:".Dumper($api->{api_client}->deserialize("HASH[string,Pet]", $pet_json));
|