// 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;
/**
* GetInventoryResponse carries the response from getInventory.
*/
public class GetInventoryResponse {
private final int statusCode;
private final Response raw;
private final Map<String, Integer> status200;
public GetInventoryResponse(int statusCode, Response raw, Map<String, Integer> status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public Map<String, Integer> getStatus200() {
return this.status200;
}
}
/**
* PlaceOrderResponse carries the response from placeOrder.
*/
public class PlaceOrderResponse {
private final int statusCode;
private final Response raw;
private final Order status200;
public PlaceOrderResponse(int statusCode, Response raw, Order status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public Order getStatus200() {
return this.status200;
}
}
/**
* GetOrderByIdResponse carries the response from getOrderById.
*/
public class GetOrderByIdResponse {
private final int statusCode;
private final Response raw;
private final Order status200;
public GetOrderByIdResponse(int statusCode, Response raw, Order status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public Order getStatus200() {
return this.status200;
}
}
/**
* DeleteOrderResponse carries the response from deleteOrder.
*/
public class DeleteOrderResponse {
private final int statusCode;
private final Response raw;
public DeleteOrderResponse(int statusCode, Response raw) {
this.statusCode = statusCode;
this.raw = raw;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
}
/**
* StoreApi groups operations under the store tag.
*/
public class StoreApi {
private final ApiClient client;
private final Gson gson = new Gson();
public StoreApi(ApiClient client) {
this.client = client;
}
/**
* Returns pet inventories by status
*/
public GetInventoryResponse getInventory() throws IOException {
String path = "/store/inventory";
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";
Map<String, Integer> status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<Map<String, Integer>>() {}.getType());
}
return new GetInventoryResponse(response.code(), response, status200);
}
/**
* Place an order for a pet
*/
public PlaceOrderResponse placeOrder(Order body) throws IOException {
String path = "/store/order";
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";
Order status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<Order>() {}.getType());
}
return new PlaceOrderResponse(response.code(), response, status200);
}
/**
* Find purchase order by ID
*/
public GetOrderByIdResponse getOrderById(long orderId) throws IOException {
String path = "/store/order/{orderId}".replace("{orderId}", String.valueOf(orderId));
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";
Order status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<Order>() {}.getType());
}
return new GetOrderByIdResponse(response.code(), response, status200);
}
/**
* Delete purchase order by ID
*/
public DeleteOrderResponse deleteOrder(long orderId) throws IOException {
String path = "/store/order/{orderId}".replace("{orderId}", String.valueOf(orderId));
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 DeleteOrderResponse(response.code(), response);
}
}