// 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;
/**
* CreateUserResponse carries the response from createUser.
*/
public class CreateUserResponse {
private final int statusCode;
private final Response raw;
private final User status200;
public CreateUserResponse(int statusCode, Response raw, User status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public User getStatus200() {
return this.status200;
}
}
/**
* CreateUsersWithListInputResponse carries the response from createUsersWithListInput.
*/
public class CreateUsersWithListInputResponse {
private final int statusCode;
private final Response raw;
private final User status200;
public CreateUsersWithListInputResponse(int statusCode, Response raw, User status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public User getStatus200() {
return this.status200;
}
}
/**
* LoginUserResponse carries the response from loginUser.
*/
public class LoginUserResponse {
private final int statusCode;
private final Response raw;
public LoginUserResponse(int statusCode, Response raw) {
this.statusCode = statusCode;
this.raw = raw;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
}
/**
* LogoutUserResponse carries the response from logoutUser.
*/
public class LogoutUserResponse {
private final int statusCode;
private final Response raw;
public LogoutUserResponse(int statusCode, Response raw) {
this.statusCode = statusCode;
this.raw = raw;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
}
/**
* GetUserByNameResponse carries the response from getUserByName.
*/
public class GetUserByNameResponse {
private final int statusCode;
private final Response raw;
private final User status200;
public GetUserByNameResponse(int statusCode, Response raw, User status200) {
this.statusCode = statusCode;
this.raw = raw;
this.status200 = status200;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
public User getStatus200() {
return this.status200;
}
}
/**
* UpdateUserResponse carries the response from updateUser.
*/
public class UpdateUserResponse {
private final int statusCode;
private final Response raw;
public UpdateUserResponse(int statusCode, Response raw) {
this.statusCode = statusCode;
this.raw = raw;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
}
/**
* DeleteUserResponse carries the response from deleteUser.
*/
public class DeleteUserResponse {
private final int statusCode;
private final Response raw;
public DeleteUserResponse(int statusCode, Response raw) {
this.statusCode = statusCode;
this.raw = raw;
}
public int getStatusCode() {
return this.statusCode;
}
public Response getRaw() {
return this.raw;
}
}
/**
* UserApi groups operations under the user tag.
*/
public class UserApi {
private final ApiClient client;
private final Gson gson = new Gson();
public UserApi(ApiClient client) {
this.client = client;
}
/**
* Create user
*/
public CreateUserResponse createUser(User body) throws IOException {
String path = "/user";
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";
User status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<User>() {}.getType());
}
return new CreateUserResponse(response.code(), response, status200);
}
/**
* Creates list of users with given input array
*/
public CreateUsersWithListInputResponse createUsersWithListInput(List<User> body) throws IOException {
String path = "/user/createWithList";
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";
User status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<User>() {}.getType());
}
return new CreateUsersWithListInputResponse(response.code(), response, status200);
}
/**
* Logs user into the system
*/
public LoginUserResponse loginUser(String username, String password) throws IOException {
String path = "/user/login";
Map<String, String> query = new HashMap<>();
if (username != null) {
query.put("username", username);
}
if (password != null) {
query.put("password", password);
}
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);
}
return new LoginUserResponse(response.code(), response);
}
/**
* Logs out current logged in user session
*/
public LogoutUserResponse logoutUser() throws IOException {
String path = "/user/logout";
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);
}
return new LogoutUserResponse(response.code(), response);
}
/**
* Get user by user name
*/
public GetUserByNameResponse getUserByName(String username) throws IOException {
String path = "/user/{username}".replace("{username}", username);
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";
User status200 = null;
if (response.code() == 200) {
status200 = gson.fromJson(responseBody, new TypeToken<User>() {}.getType());
}
return new GetUserByNameResponse(response.code(), response, status200);
}
/**
* Update user
*/
public UpdateUserResponse updateUser(String username, User body) throws IOException {
String path = "/user/{username}".replace("{username}", username);
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);
}
return new UpdateUserResponse(response.code(), response);
}
/**
* Delete user
*/
public DeleteUserResponse deleteUser(String username) throws IOException {
String path = "/user/{username}".replace("{username}", username);
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 DeleteUserResponse(response.code(), response);
}
}