// Code generated by openapi-nexus. DO NOT EDIT.
//
// Petstore API — 1.0.0
// This is a sample Pet Store Server based on the OpenAPI 3.1 specification
package com.example.sdk.apis;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.example.sdk.models.*;
import com.example.sdk.runtime.ApiClient;
import com.example.sdk.runtime.ApiException;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import okhttp3.Request;
import okhttp3.Response;
/**
* UpdatePetResponse carries the response from updatePet.
*/
public class UpdatePetResponse {
private final int statusCode;
private final Response raw;
private final Pet status200;
public UpdatePetResponse(int statusCode, Response raw, Pet status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public Pet getStatus200() {
return this.status200;
}
}
/**
* AddPetResponse carries the response from addPet.
*/
public class AddPetResponse {
private final int statusCode;
private final Response raw;
private final Pet status200;
public AddPetResponse(int statusCode, Response raw, Pet status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public Pet getStatus200() {
return this.status200;
}
}
/**
* FindPetsByStatusResponse carries the response from findPetsByStatus.
*/
public class FindPetsByStatusResponse {
private final int statusCode;
private final Response raw;
private final List<Pet> status200;
public FindPetsByStatusResponse(int statusCode, Response raw, List<Pet> status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public List<Pet> getStatus200() {
return this.status200;
}
}
/**
* FindPetsByTagsResponse carries the response from findPetsByTags.
*/
public class FindPetsByTagsResponse {
private final int statusCode;
private final Response raw;
private final List<Pet> status200;
public FindPetsByTagsResponse(int statusCode, Response raw, List<Pet> status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public List<Pet> getStatus200() {
return this.status200;
}
}
/**
* GetPetByIdResponse carries the response from getPetById.
*/
public class GetPetByIdResponse {
private final int statusCode;
private final Response raw;
private final Pet status200;
public GetPetByIdResponse(int statusCode, Response raw, Pet status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public Pet getStatus200() {
return this.status200;
}
}
/**
* UpdatePetWithFormResponse carries the response from updatePetWithForm.
*/
public class UpdatePetWithFormResponse {
private final int statusCode;
private final Response raw;
private final Pet status200;
public UpdatePetWithFormResponse(int statusCode, Response raw, Pet status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public Pet getStatus200() {
return this.status200;
}
}
/**
* DeletePetResponse carries the response from deletePet.
*/
public class DeletePetResponse {
private final int statusCode;
private final Response raw;
public DeletePetResponse(int statusCode, Response raw) {
this.statusCode = statusCode;
this.raw = raw;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
}
/**
* UploadFileResponse carries the response from uploadFile.
*/
public class UploadFileResponse {
private final int statusCode;
private final Response raw;
private final UploadResponse status200;
public UploadFileResponse(int statusCode, Response raw, UploadResponse status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public UploadResponse getStatus200() {
return this.status200;
}
}
/**
* PetApi groups operations under the pet tag.
*/
public class PetApi {
private final ApiClient client;
private final Gson gson = new Gson();
public PetApi(ApiClient client) {
this.client = client;
}
/**
* Update an existing pet
*/
public UpdatePetResponse updatePet(Pet body) throws IOException {
String path = "/pet";
String jsonBody = gson.toJson(body);
Request request = client.newRequest("PUT", path, null, jsonBody);
Response response = client.execute(request);
if (!response.isSuccessful()) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new ApiException(response.code(), response.message(), errorBody);
}
String responseBody = response.body() != null ? response.body().string() : "null";
Pet status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<Pet>() {}.getType());
}
return new UpdatePetResponse(response.code(), response, status200);
}
/**
* Add a new pet to the store
*/
public AddPetResponse addPet(Pet body) throws IOException {
String path = "/pet";
String jsonBody = gson.toJson(body);
Request request = client.newRequest("POST", path, null, jsonBody);
Response response = client.execute(request);
if (!response.isSuccessful()) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new ApiException(response.code(), response.message(), errorBody);
}
String responseBody = response.body() != null ? response.body().string() : "null";
Pet status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<Pet>() {}.getType());
}
return new AddPetResponse(response.code(), response, status200);
}
/**
* Find pets by status
*/
public FindPetsByStatusResponse findPetsByStatus(String status) throws IOException {
String path = "/pet/findByStatus";
Map<String, String> query = new HashMap<>();
query.put("status", status);
Request request = client.newRequest("GET", path, query, null);
Response response = client.execute(request);
if (!response.isSuccessful()) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new ApiException(response.code(), response.message(), errorBody);
}
String responseBody = response.body() != null ? response.body().string() : "null";
List<Pet> status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<List<Pet>>() {}.getType());
}
return new FindPetsByStatusResponse(response.code(), response, status200);
}
/**
* Find pets by tags
*/
public FindPetsByTagsResponse findPetsByTags(List<String> tags) throws IOException {
String path = "/pet/findByTags";
Map<String, String> query = new HashMap<>();
query.put("tags", String.valueOf(tags));
Request request = client.newRequest("GET", path, query, null);
Response response = client.execute(request);
if (!response.isSuccessful()) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new ApiException(response.code(), response.message(), errorBody);
}
String responseBody = response.body() != null ? response.body().string() : "null";
List<Pet> status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<List<Pet>>() {}.getType());
}
return new FindPetsByTagsResponse(response.code(), response, status200);
}
/**
* Find pet by ID
*/
public GetPetByIdResponse getPetById(long petId) throws IOException {
String path = "/pet/{petId}".replace("{petId}", String.valueOf(petId));
Request request = client.newRequest("GET", path, null, null);
Response response = client.execute(request);
if (!response.isSuccessful()) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new ApiException(response.code(), response.message(), errorBody);
}
String responseBody = response.body() != null ? response.body().string() : "null";
Pet status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<Pet>() {}.getType());
}
return new GetPetByIdResponse(response.code(), response, status200);
}
/**
* Update a pet in the store with form data
*/
public UpdatePetWithFormResponse updatePetWithForm(long petId, String name, String status) throws IOException {
String path = "/pet/{petId}".replace("{petId}", String.valueOf(petId));
Map<String, String> query = new HashMap<>();
if (name != null) {
query.put("name", name);
}
if (status != null) {
query.put("status", status);
}
Request request = client.newRequest("POST", path, query, null);
Response response = client.execute(request);
if (!response.isSuccessful()) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new ApiException(response.code(), response.message(), errorBody);
}
String responseBody = response.body() != null ? response.body().string() : "null";
Pet status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<Pet>() {}.getType());
}
return new UpdatePetWithFormResponse(response.code(), response, status200);
}
/**
* Delete a pet
*/
public DeletePetResponse deletePet(long petId) throws IOException {
String path = "/pet/{petId}".replace("{petId}", String.valueOf(petId));
Request request = client.newRequest("DELETE", path, null, null);
Response response = client.execute(request);
if (!response.isSuccessful()) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new ApiException(response.code(), response.message(), errorBody);
}
return new DeletePetResponse(response.code(), response);
}
/**
* Upload an image
*/
public UploadFileResponse uploadFile(long petId, String additionalMetadata) throws IOException {
String path = "/pet/{petId}/uploadImage".replace("{petId}", String.valueOf(petId));
Map<String, String> query = new HashMap<>();
if (additionalMetadata != null) {
query.put("additionalMetadata", additionalMetadata);
}
Request request = client.newRequest("POST", path, query, null);
Response response = client.execute(request);
if (!response.isSuccessful()) {
String errorBody = response.body() != null ? response.body().string() : "";
throw new ApiException(response.code(), response.message(), errorBody);
}
String responseBody = response.body() != null ? response.body().string() : "null";
UploadResponse status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<UploadResponse>() {}.getType());
}
return new UploadFileResponse(response.code(), response, status200);
}
}