diff --git a/app/build.gradle b/app/build.gradle index eb774ee..33ebe4a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,6 +27,9 @@ android { lintOptions { disable 'GoogleAppIndexingWarning' } + packagingOptions { + exclude 'META-INF/DEPENDENCIES' + } } dependencies { diff --git a/app/src/main/java/com/github/gotify/api/Api.java b/app/src/main/java/com/github/gotify/api/Api.java index 23b4e9a..bb10e23 100644 --- a/app/src/main/java/com/github/gotify/api/Api.java +++ b/app/src/main/java/com/github/gotify/api/Api.java @@ -1,75 +1,4 @@ package com.github.gotify.api; -import android.app.Activity; -import com.github.gotify.client.ApiCallback; -import com.github.gotify.client.ApiException; -import com.github.gotify.log.Log; -import java.util.List; -import java.util.Map; - public class Api { - public static CallExecutor withLogging(ApiCall call) { - return new CallExecutor(call); - } - - private static Callback loggingCallback() { - return Callback.call( - (data) -> {}, - (exception) -> - Log.e("Error while api call: " + exception.getResponseBody(), exception)); - } - - public interface ApiCall { - void call(ApiCallback callback) throws ApiException; - } - - public static class CallExecutor { - private ApiCall call; - - private CallExecutor(ApiCall call) { - this.call = call; - } - - public void handle(Callback callback) { - Callback merged = Callback.merge(callback, loggingCallback()); - try { - call.call(fromCallback(merged)); - } catch (ApiException e) { - merged.onError(e); - } - } - - public void handleInUIThread( - Activity activity, - Callback.SuccessCallback onSuccess, - Callback.ErrorCallback onError) { - handle(Callback.runInUIThread(activity, Callback.call(onSuccess, onError))); - } - - public void handle(Callback.SuccessCallback onSuccess, Callback.ErrorCallback onError) { - handle(Callback.call(onSuccess, onError)); - } - } - - private static ApiCallback fromCallback(Callback callback) { - return new ApiCallback() { - @Override - public void onFailure( - ApiException e, int statusCode, Map> responseHeaders) { - callback.onError(e); - } - - @Override - public void onSuccess( - T result, int statusCode, Map> responseHeaders) { - callback.onSuccess(result); - } - - @Override - public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {} - - @Override - public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {} - }; - } } diff --git a/app/src/main/java/com/github/gotify/api/ApiException.java b/app/src/main/java/com/github/gotify/api/ApiException.java new file mode 100644 index 0000000..64c30e2 --- /dev/null +++ b/app/src/main/java/com/github/gotify/api/ApiException.java @@ -0,0 +1,4 @@ +package com.github.gotify.api; + +class ApiException { +} diff --git a/client/README.md b/client/README.md index 41f3c7c..4a53c01 100644 --- a/client/README.md +++ b/client/README.md @@ -4,7 +4,7 @@ Building the API client library requires [Maven](https://maven.apache.org/) to be installed. -## Installation +## Installation & Usage To install the API client library to your local Maven repository, simply execute: @@ -20,9 +20,7 @@ mvn deploy Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information. -### Maven users - -Add this dependency to your project's POM: +After the client library is installed/deployed, you can use it in your Maven project by adding the following to your *pom.xml*: ```xml @@ -31,153 +29,11 @@ Add this dependency to your project's POM: 1.0.0 compile -``` - -### Gradle users - -Add this dependency to your project's build file: - -```groovy -compile "io.swagger:swagger-java-client:1.0.0" -``` - -### Others - -At first generate the JAR by executing: - - mvn package - -Then manually install the following JARs: - -* target/swagger-java-client-1.0.0.jar -* target/lib/*.jar - -## Getting Started - -Please follow the [installation](#installation) instruction and execute the following Java code: - -```java - -import com.github.gotify.client.*; -import com.github.gotify.client.auth.*; -import com.github.gotify.client.model.*; -import com.github.gotify.client.api.MessageApi; - -import java.io.File; -import java.util.*; - -public class MessageApiExample { - - public static void main(String[] args) { - ApiClient defaultClient = Configuration.getDefaultApiClient(); - - // Configure API key authorization: appTokenHeader - ApiKeyAuth appTokenHeader = (ApiKeyAuth) defaultClient.getAuthentication("appTokenHeader"); - appTokenHeader.setApiKey("YOUR API KEY"); - // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) - //appTokenHeader.setApiKeyPrefix("Token"); - - // Configure API key authorization: appTokenQuery - ApiKeyAuth appTokenQuery = (ApiKeyAuth) defaultClient.getAuthentication("appTokenQuery"); - appTokenQuery.setApiKey("YOUR API KEY"); - // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) - //appTokenQuery.setApiKeyPrefix("Token"); - - MessageApi apiInstance = new MessageApi(); - Message body = new Message(); // Message | the message to add - try { - Message result = apiInstance.createMessage(body); - System.out.println(result); - } catch (ApiException e) { - System.err.println("Exception when calling MessageApi#createMessage"); - e.printStackTrace(); - } - } -} ``` -## Documentation for API Endpoints - -All URIs are relative to *http://localhost* - -Class | Method | HTTP request | Description ------------- | ------------- | ------------- | ------------- -*MessageApi* | [**createMessage**](docs/MessageApi.md#createMessage) | **POST** /message | Create a message. -*MessageApi* | [**deleteAppMessages**](docs/MessageApi.md#deleteAppMessages) | **DELETE** /application/{id}/message | Delete all messages from a specific application. -*MessageApi* | [**deleteMessage**](docs/MessageApi.md#deleteMessage) | **DELETE** /message/{id} | Deletes a message with an id. -*MessageApi* | [**deleteMessages**](docs/MessageApi.md#deleteMessages) | **DELETE** /message | Delete all messages. -*MessageApi* | [**getAppMessages**](docs/MessageApi.md#getAppMessages) | **GET** /application/{id}/message | Return all messages from a specific application. -*MessageApi* | [**getMessages**](docs/MessageApi.md#getMessages) | **GET** /message | Return all messages. -*MessageApi* | [**streamMessages**](docs/MessageApi.md#streamMessages) | **GET** /stream | Websocket, return newly created messages. -*TokenApi* | [**createApp**](docs/TokenApi.md#createApp) | **POST** /application | Create an application. -*TokenApi* | [**createClient**](docs/TokenApi.md#createClient) | **POST** /client | Create a client. -*TokenApi* | [**deleteApp**](docs/TokenApi.md#deleteApp) | **DELETE** /application/{id} | Delete an application. -*TokenApi* | [**deleteClient**](docs/TokenApi.md#deleteClient) | **DELETE** /client/{id} | Delete a client. -*TokenApi* | [**getApps**](docs/TokenApi.md#getApps) | **GET** /application | Return all applications. -*TokenApi* | [**getClients**](docs/TokenApi.md#getClients) | **GET** /client | Return all clients. -*TokenApi* | [**uploadAppImage**](docs/TokenApi.md#uploadAppImage) | **POST** /application/{id}/image | -*UserApi* | [**createUser**](docs/UserApi.md#createUser) | **POST** /user | Create a user. -*UserApi* | [**currentUser**](docs/UserApi.md#currentUser) | **GET** /current/user | Return the current user. -*UserApi* | [**deleteUser**](docs/UserApi.md#deleteUser) | **DELETE** /user/{id} | Deletes a user. -*UserApi* | [**getUser**](docs/UserApi.md#getUser) | **GET** /user/{id} | Get a user. -*UserApi* | [**getUsers**](docs/UserApi.md#getUsers) | **GET** /user | Return all users. -*UserApi* | [**updateCurrentUser**](docs/UserApi.md#updateCurrentUser) | **POST** /current/user/password | Update the password of the current user. -*UserApi* | [**updateUser**](docs/UserApi.md#updateUser) | **POST** /user/{id} | Update a user. -*VersionApi* | [**getVersion**](docs/VersionApi.md#getVersion) | **GET** /version | Get version information. - - -## Documentation for Models - - - [Application](docs/Application.md) - - [Client](docs/Client.md) - - [Error](docs/Error.md) - - [Message](docs/Message.md) - - [PagedMessages](docs/PagedMessages.md) - - [Paging](docs/Paging.md) - - [User](docs/User.md) - - [UserPass](docs/UserPass.md) - - [UserWithPass](docs/UserWithPass.md) - - [VersionInfo](docs/VersionInfo.md) - - -## Documentation for Authorization - -Authentication schemes defined for the API: -### appTokenHeader - -- **Type**: API key -- **API key parameter name**: X-Gotify-Key -- **Location**: HTTP header - -### appTokenQuery - -- **Type**: API key -- **API key parameter name**: token -- **Location**: URL query string - -### basicAuth - -- **Type**: HTTP basic authentication - -### clientTokenHeader - -- **Type**: API key -- **API key parameter name**: X-Gotify-Key -- **Location**: HTTP header - -### clientTokenQuery - -- **Type**: API key -- **API key parameter name**: token -- **Location**: URL query string - - -## Recommendation - -It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues. - ## Author + diff --git a/client/build.gradle b/client/build.gradle index 4ebc486..0ca4f71 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -25,11 +25,10 @@ if(hasProperty('target') && target == 'android') { apply plugin: 'com.github.dcendents.android-maven' android { - compileSdkVersion 25 - buildToolsVersion '25.0.2' + compileSdkVersion 28 defaultConfig { - minSdkVersion 14 - targetSdkVersion 25 + minSdkVersion 19 + targetSdkVersion 28 } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 @@ -93,12 +92,22 @@ if(hasProperty('target') && target == 'android') { } } -dependencies { - compile 'io.swagger:swagger-annotations:1.5.15' - compile 'com.squareup.okhttp:okhttp:2.7.5' - compile 'com.squareup.okhttp:logging-interceptor:2.7.5' - compile 'com.google.code.gson:gson:2.8.1' - compile 'io.gsonfire:gson-fire:1.8.0' - compile 'org.threeten:threetenbp:1.3.5' - testCompile 'junit:junit:4.12' +ext { + oltu_version = "1.0.0" + retrofit_version = "2.3.0" + swagger_annotations_version = "1.5.15" + junit_version = "4.12" + threetenbp_version = "1.3.5" + json_fire_version = "1.8.0" +} + +dependencies { + compile "com.squareup.retrofit2:retrofit:$retrofit_version" + compile "com.squareup.retrofit2:converter-scalars:$retrofit_version" + compile "com.squareup.retrofit2:converter-gson:$retrofit_version" + compile "io.swagger:swagger-annotations:$swagger_annotations_version" + compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" + compile "io.gsonfire:gson-fire:$json_fire_version" + compile "org.threeten:threetenbp:$threetenbp_version" + testCompile "junit:junit:$junit_version" } diff --git a/client/build.sbt b/client/build.sbt index 485ccb3..d0d4e26 100644 --- a/client/build.sbt +++ b/client/build.sbt @@ -9,13 +9,14 @@ lazy val root = (project in file(".")). publishArtifact in (Compile, packageDoc) := false, resolvers += Resolver.mavenLocal, libraryDependencies ++= Seq( - "io.swagger" % "swagger-annotations" % "1.5.15", - "com.squareup.okhttp" % "okhttp" % "2.7.5", - "com.squareup.okhttp" % "logging-interceptor" % "2.7.5", - "com.google.code.gson" % "gson" % "2.8.1", + "com.squareup.retrofit2" % "retrofit" % "2.3.0" % "compile", + "com.squareup.retrofit2" % "converter-scalars" % "2.3.0" % "compile", + "com.squareup.retrofit2" % "converter-gson" % "2.3.0" % "compile", + "io.swagger" % "swagger-annotations" % "1.5.15" % "compile", + "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", "org.threeten" % "threetenbp" % "1.3.5" % "compile", "io.gsonfire" % "gson-fire" % "1.8.0" % "compile", "junit" % "junit" % "4.12" % "test", - "com.novocode" % "junit-interface" % "0.10" % "test" + "com.novocode" % "junit-interface" % "0.11" % "test" ) ) diff --git a/client/docs/MessageApi.md b/client/docs/MessageApi.md index 4a43464..22e8c03 100644 --- a/client/docs/MessageApi.md +++ b/client/docs/MessageApi.md @@ -4,13 +4,13 @@ All URIs are relative to *http://localhost* Method | HTTP request | Description ------------- | ------------- | ------------- -[**createMessage**](MessageApi.md#createMessage) | **POST** /message | Create a message. -[**deleteAppMessages**](MessageApi.md#deleteAppMessages) | **DELETE** /application/{id}/message | Delete all messages from a specific application. -[**deleteMessage**](MessageApi.md#deleteMessage) | **DELETE** /message/{id} | Deletes a message with an id. -[**deleteMessages**](MessageApi.md#deleteMessages) | **DELETE** /message | Delete all messages. -[**getAppMessages**](MessageApi.md#getAppMessages) | **GET** /application/{id}/message | Return all messages from a specific application. -[**getMessages**](MessageApi.md#getMessages) | **GET** /message | Return all messages. -[**streamMessages**](MessageApi.md#streamMessages) | **GET** /stream | Websocket, return newly created messages. +[**createMessage**](MessageApi.md#createMessage) | **POST** message | Create a message. +[**deleteAppMessages**](MessageApi.md#deleteAppMessages) | **DELETE** application/{id}/message | Delete all messages from a specific application. +[**deleteMessage**](MessageApi.md#deleteMessage) | **DELETE** message/{id} | Deletes a message with an id. +[**deleteMessages**](MessageApi.md#deleteMessages) | **DELETE** message | Delete all messages. +[**getAppMessages**](MessageApi.md#getAppMessages) | **GET** application/{id}/message | Return all messages from a specific application. +[**getMessages**](MessageApi.md#getMessages) | **GET** message | Return all messages. +[**streamMessages**](MessageApi.md#streamMessages) | **GET** stream | Websocket, return newly created messages. @@ -76,7 +76,7 @@ Name | Type | Description | Notes # **deleteAppMessages** -> deleteAppMessages(id) +> Void deleteAppMessages(id) Delete all messages from a specific application. @@ -111,7 +111,8 @@ clientTokenQuery.setApiKey("YOUR API KEY"); MessageApi apiInstance = new MessageApi(); Integer id = 56; // Integer | the application id try { - apiInstance.deleteAppMessages(id); + Void result = apiInstance.deleteAppMessages(id); + System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling MessageApi#deleteAppMessages"); e.printStackTrace(); @@ -126,7 +127,7 @@ Name | Type | Description | Notes ### Return type -null (empty response body) +[**Void**](.md) ### Authorization @@ -139,7 +140,7 @@ null (empty response body) # **deleteMessage** -> deleteMessage(id) +> Void deleteMessage(id) Deletes a message with an id. @@ -174,7 +175,8 @@ clientTokenQuery.setApiKey("YOUR API KEY"); MessageApi apiInstance = new MessageApi(); Integer id = 56; // Integer | the message id try { - apiInstance.deleteMessage(id); + Void result = apiInstance.deleteMessage(id); + System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling MessageApi#deleteMessage"); e.printStackTrace(); @@ -189,7 +191,7 @@ Name | Type | Description | Notes ### Return type -null (empty response body) +[**Void**](.md) ### Authorization @@ -202,7 +204,7 @@ null (empty response body) # **deleteMessages** -> deleteMessages() +> Void deleteMessages() Delete all messages. @@ -236,7 +238,8 @@ clientTokenQuery.setApiKey("YOUR API KEY"); MessageApi apiInstance = new MessageApi(); try { - apiInstance.deleteMessages(); + Void result = apiInstance.deleteMessages(); + System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling MessageApi#deleteMessages"); e.printStackTrace(); @@ -248,7 +251,7 @@ This endpoint does not need any parameter. ### Return type -null (empty response body) +[**Void**](.md) ### Authorization diff --git a/client/docs/TokenApi.md b/client/docs/TokenApi.md index 7d3a4ea..afb55ea 100644 --- a/client/docs/TokenApi.md +++ b/client/docs/TokenApi.md @@ -4,13 +4,13 @@ All URIs are relative to *http://localhost* Method | HTTP request | Description ------------- | ------------- | ------------- -[**createApp**](TokenApi.md#createApp) | **POST** /application | Create an application. -[**createClient**](TokenApi.md#createClient) | **POST** /client | Create a client. -[**deleteApp**](TokenApi.md#deleteApp) | **DELETE** /application/{id} | Delete an application. -[**deleteClient**](TokenApi.md#deleteClient) | **DELETE** /client/{id} | Delete a client. -[**getApps**](TokenApi.md#getApps) | **GET** /application | Return all applications. -[**getClients**](TokenApi.md#getClients) | **GET** /client | Return all clients. -[**uploadAppImage**](TokenApi.md#uploadAppImage) | **POST** /application/{id}/image | +[**createApp**](TokenApi.md#createApp) | **POST** application | Create an application. +[**createClient**](TokenApi.md#createClient) | **POST** client | Create a client. +[**deleteApp**](TokenApi.md#deleteApp) | **DELETE** application/{id} | Delete an application. +[**deleteClient**](TokenApi.md#deleteClient) | **DELETE** client/{id} | Delete a client. +[**getApps**](TokenApi.md#getApps) | **GET** application | Return all applications. +[**getClients**](TokenApi.md#getClients) | **GET** client | Return all clients. +[**uploadAppImage**](TokenApi.md#uploadAppImage) | **POST** application/{id}/image | @@ -143,7 +143,7 @@ Name | Type | Description | Notes # **deleteApp** -> deleteApp(id) +> Void deleteApp(id) Delete an application. @@ -178,7 +178,8 @@ clientTokenQuery.setApiKey("YOUR API KEY"); TokenApi apiInstance = new TokenApi(); Integer id = 56; // Integer | the application id try { - apiInstance.deleteApp(id); + Void result = apiInstance.deleteApp(id); + System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling TokenApi#deleteApp"); e.printStackTrace(); @@ -193,7 +194,7 @@ Name | Type | Description | Notes ### Return type -null (empty response body) +[**Void**](.md) ### Authorization @@ -206,7 +207,7 @@ null (empty response body) # **deleteClient** -> deleteClient(id) +> Void deleteClient(id) Delete a client. @@ -241,7 +242,8 @@ clientTokenQuery.setApiKey("YOUR API KEY"); TokenApi apiInstance = new TokenApi(); Integer id = 56; // Integer | the client id try { - apiInstance.deleteClient(id); + Void result = apiInstance.deleteClient(id); + System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling TokenApi#deleteClient"); e.printStackTrace(); @@ -256,7 +258,7 @@ Name | Type | Description | Notes ### Return type -null (empty response body) +[**Void**](.md) ### Authorization diff --git a/client/docs/UserApi.md b/client/docs/UserApi.md index 25903d7..3d8fd33 100644 --- a/client/docs/UserApi.md +++ b/client/docs/UserApi.md @@ -4,13 +4,13 @@ All URIs are relative to *http://localhost* Method | HTTP request | Description ------------- | ------------- | ------------- -[**createUser**](UserApi.md#createUser) | **POST** /user | Create a user. -[**currentUser**](UserApi.md#currentUser) | **GET** /current/user | Return the current user. -[**deleteUser**](UserApi.md#deleteUser) | **DELETE** /user/{id} | Deletes a user. -[**getUser**](UserApi.md#getUser) | **GET** /user/{id} | Get a user. -[**getUsers**](UserApi.md#getUsers) | **GET** /user | Return all users. -[**updateCurrentUser**](UserApi.md#updateCurrentUser) | **POST** /current/user/password | Update the password of the current user. -[**updateUser**](UserApi.md#updateUser) | **POST** /user/{id} | Update a user. +[**createUser**](UserApi.md#createUser) | **POST** user | Create a user. +[**currentUser**](UserApi.md#currentUser) | **GET** current/user | Return the current user. +[**deleteUser**](UserApi.md#deleteUser) | **DELETE** user/{id} | Deletes a user. +[**getUser**](UserApi.md#getUser) | **GET** user/{id} | Get a user. +[**getUsers**](UserApi.md#getUsers) | **GET** user | Return all users. +[**updateCurrentUser**](UserApi.md#updateCurrentUser) | **POST** current/user/password | Update the password of the current user. +[**updateUser**](UserApi.md#updateUser) | **POST** user/{id} | Update a user. @@ -139,7 +139,7 @@ This endpoint does not need any parameter. # **deleteUser** -> deleteUser(id) +> Void deleteUser(id) Deletes a user. @@ -174,7 +174,8 @@ clientTokenQuery.setApiKey("YOUR API KEY"); UserApi apiInstance = new UserApi(); Integer id = 56; // Integer | the user id try { - apiInstance.deleteUser(id); + Void result = apiInstance.deleteUser(id); + System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling UserApi#deleteUser"); e.printStackTrace(); @@ -189,7 +190,7 @@ Name | Type | Description | Notes ### Return type -null (empty response body) +[**Void**](.md) ### Authorization @@ -326,7 +327,7 @@ This endpoint does not need any parameter. # **updateCurrentUser** -> updateCurrentUser(body) +> Void updateCurrentUser(body) Update the password of the current user. @@ -361,7 +362,8 @@ clientTokenQuery.setApiKey("YOUR API KEY"); UserApi apiInstance = new UserApi(); UserPass body = new UserPass(); // UserPass | the user try { - apiInstance.updateCurrentUser(body); + Void result = apiInstance.updateCurrentUser(body); + System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling UserApi#updateCurrentUser"); e.printStackTrace(); @@ -376,7 +378,7 @@ Name | Type | Description | Notes ### Return type -null (empty response body) +[**Void**](.md) ### Authorization diff --git a/client/docs/VersionApi.md b/client/docs/VersionApi.md index afc00a3..0e17583 100644 --- a/client/docs/VersionApi.md +++ b/client/docs/VersionApi.md @@ -4,7 +4,7 @@ All URIs are relative to *http://localhost* Method | HTTP request | Description ------------- | ------------- | ------------- -[**getVersion**](VersionApi.md#getVersion) | **GET** /version | Get version information. +[**getVersion**](VersionApi.md#getVersion) | **GET** version | Get version information. diff --git a/client/pom.xml b/client/pom.xml index e0050ed..448b58d 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -194,19 +194,24 @@ ${swagger-core-version} - com.squareup.okhttp - okhttp - ${okhttp-version} + com.squareup.retrofit2 + converter-gson + ${retrofit-version} - com.squareup.okhttp - logging-interceptor - ${okhttp-version} + com.squareup.retrofit2 + retrofit + ${retrofit-version} - com.google.code.gson - gson - ${gson-version} + com.squareup.retrofit2 + converter-scalars + ${retrofit-version} + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.client + ${oltu-version} io.gsonfire @@ -218,6 +223,9 @@ threetenbp ${threetenbp-version} + + + junit @@ -227,16 +235,15 @@ + UTF-8 1.7 ${java.version} ${java.version} 1.8.0 1.5.15 - 2.7.5 - 2.8.1 + 2.3.0 1.3.5 - 1.0.0 + 1.0.1 4.12 - UTF-8 diff --git a/client/settings.gradle b/client/settings.gradle deleted file mode 100644 index 55640f7..0000000 --- a/client/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = "swagger-java-client" \ No newline at end of file diff --git a/client/src/main/AndroidManifest.xml b/client/src/main/AndroidManifest.xml deleted file mode 100644 index 3212fe4..0000000 --- a/client/src/main/AndroidManifest.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/client/src/main/java/com/github/gotify/client/ApiCallback.java b/client/src/main/java/com/github/gotify/client/ApiCallback.java deleted file mode 100644 index 644214a..0000000 --- a/client/src/main/java/com/github/gotify/client/ApiCallback.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package com.github.gotify.client; - -import java.io.IOException; - -import java.util.Map; -import java.util.List; - -/** - * Callback for asynchronous API call. - * - * @param The return type - */ -public interface ApiCallback { - /** - * This is called when the API call fails. - * - * @param e The exception causing the failure - * @param statusCode Status code of the response if available, otherwise it would be 0 - * @param responseHeaders Headers of the response if available, otherwise it would be null - */ - void onFailure(ApiException e, int statusCode, Map> responseHeaders); - - /** - * This is called when the API call succeeded. - * - * @param result The result deserialized from response - * @param statusCode Status code of the response - * @param responseHeaders Headers of the response - */ - void onSuccess(T result, int statusCode, Map> responseHeaders); - - /** - * This is called when the API upload processing. - * - * @param bytesWritten bytes Written - * @param contentLength content length of request body - * @param done write end - */ - void onUploadProgress(long bytesWritten, long contentLength, boolean done); - - /** - * This is called when the API downlond processing. - * - * @param bytesRead bytes Read - * @param contentLength content lenngth of the response - * @param done Read end - */ - void onDownloadProgress(long bytesRead, long contentLength, boolean done); -} diff --git a/client/src/main/java/com/github/gotify/client/ApiClient.java b/client/src/main/java/com/github/gotify/client/ApiClient.java index efa3fa5..f8466e0 100644 --- a/client/src/main/java/com/github/gotify/client/ApiClient.java +++ b/client/src/main/java/com/github/gotify/client/ApiClient.java @@ -1,1210 +1,382 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client; -import com.squareup.okhttp.*; -import com.squareup.okhttp.internal.http.HttpMethod; -import com.squareup.okhttp.logging.HttpLoggingInterceptor; -import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level; -import okio.BufferedSink; -import okio.Okio; -import org.threeten.bp.LocalDate; -import org.threeten.bp.OffsetDateTime; +import com.google.gson.Gson; +import com.google.gson.JsonParseException; +import com.google.gson.JsonElement; +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; import org.threeten.bp.format.DateTimeFormatter; - -import javax.net.ssl.*; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Type; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.security.GeneralSecurityException; -import java.security.KeyStore; -import java.security.SecureRandom; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.text.DateFormat; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import com.github.gotify.client.auth.Authentication; +import retrofit2.Converter; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; +import retrofit2.converter.scalars.ScalarsConverterFactory; import com.github.gotify.client.auth.HttpBasicAuth; import com.github.gotify.client.auth.ApiKeyAuth; import com.github.gotify.client.auth.OAuth; +import com.github.gotify.client.auth.OAuth.AccessTokenListener; +import com.github.gotify.client.auth.OAuthFlow; + +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.text.DateFormat; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.HashMap; public class ApiClient { - private String basePath = "http://localhost"; - private boolean debugging = false; - private Map defaultHeaderMap = new HashMap(); - private String tempFolderPath = null; + private Map apiAuthorizations; + private OkHttpClient.Builder okBuilder; + private Retrofit.Builder adapterBuilder; + private JSON json; - private Map authentications; + public ApiClient() { + apiAuthorizations = new LinkedHashMap(); + createDefaultAdapter(); + } - private DateFormat dateFormat; - private DateFormat datetimeFormat; - private boolean lenientDatetimeFormat; - private int dateLength; + public ApiClient(String[] authNames) { + this(); + for(String authName : authNames) { + Interceptor auth; + if ("appTokenHeader".equals(authName)) { + auth = new ApiKeyAuth("header", "X-Gotify-Key"); + } else if ("appTokenQuery".equals(authName)) { + auth = new ApiKeyAuth("query", "token"); + } else if ("basicAuth".equals(authName)) { + auth = new HttpBasicAuth(); + } else if ("clientTokenHeader".equals(authName)) { + auth = new ApiKeyAuth("header", "X-Gotify-Key"); + } else if ("clientTokenQuery".equals(authName)) { + auth = new ApiKeyAuth("query", "token"); + } else { + throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); + } - private InputStream sslCaCert; - private boolean verifyingSsl; - private KeyManager[] keyManagers; - - private OkHttpClient httpClient; - private JSON json; - - private HttpLoggingInterceptor loggingInterceptor; - - /* - * Constructor for ApiClient - */ - public ApiClient() { - httpClient = new OkHttpClient(); - - - verifyingSsl = true; - - json = new JSON(); - - // Set default User-Agent. - setUserAgent("Swagger-Codegen/1.0.0/java"); - - // Setup authentications (key: authentication name, value: authentication). - authentications = new HashMap(); - authentications.put("appTokenHeader", new ApiKeyAuth("header", "X-Gotify-Key")); - authentications.put("appTokenQuery", new ApiKeyAuth("query", "token")); - authentications.put("basicAuth", new HttpBasicAuth()); - authentications.put("clientTokenHeader", new ApiKeyAuth("header", "X-Gotify-Key")); - authentications.put("clientTokenQuery", new ApiKeyAuth("query", "token")); - // Prevent the authentications from being modified. - authentications = Collections.unmodifiableMap(authentications); + addAuthorization(authName, auth); } + } - /** - * Get base path - * - * @return Baes path - */ - public String getBasePath() { - return basePath; - } + /** + * Basic constructor for single auth name + * @param authName Authentication name + */ + public ApiClient(String authName) { + this(new String[]{authName}); + } - /** - * Set base path - * - * @param basePath Base path of the URL (e.g http://localhost - * @return An instance of OkHttpClient - */ - public ApiClient setBasePath(String basePath) { - this.basePath = basePath; + /** + * Helper constructor for single api key + * @param authName Authentication name + * @param apiKey API key + */ + public ApiClient(String authName, String apiKey) { + this(authName); + this.setApiKey(apiKey); + } + + /** + * Helper constructor for single basic auth or password oauth2 + * @param authName Authentication name + * @param username Username + * @param password Password + */ + public ApiClient(String authName, String username, String password) { + this(authName); + this.setCredentials(username, password); + } + + /** + * Helper constructor for single password oauth2 + * @param authName Authentication name + * @param clientId Client ID + * @param secret Client Secret + * @param username Username + * @param password Password + */ + public ApiClient(String authName, String clientId, String secret, String username, String password) { + this(authName); + this.getTokenEndPoint() + .setClientId(clientId) + .setClientSecret(secret) + .setUsername(username) + .setPassword(password); + } + + public void createDefaultAdapter() { + json = new JSON(); + okBuilder = new OkHttpClient.Builder(); + + String baseUrl = "http://localhost"; + if (!baseUrl.endsWith("/")) + baseUrl = baseUrl + "/"; + + adapterBuilder = new Retrofit + .Builder() + .baseUrl(baseUrl) + .addConverterFactory(ScalarsConverterFactory.create()) + .addConverterFactory(GsonCustomConverterFactory.create(json.getGson())); + } + + public S createService(Class serviceClass) { + return adapterBuilder + .client(okBuilder.build()) + .build() + .create(serviceClass); + } + + public ApiClient setDateFormat(DateFormat dateFormat) { + this.json.setDateFormat(dateFormat); + return this; + } + + public ApiClient setSqlDateFormat(DateFormat dateFormat) { + this.json.setSqlDateFormat(dateFormat); + return this; + } + + public ApiClient setOffsetDateTimeFormat(DateTimeFormatter dateFormat) { + this.json.setOffsetDateTimeFormat(dateFormat); + return this; + } + + public ApiClient setLocalDateFormat(DateTimeFormatter dateFormat) { + this.json.setLocalDateFormat(dateFormat); + return this; + } + + + /** + * Helper method to configure the first api key found + * @param apiKey API key + * @return ApiClient + */ + public ApiClient setApiKey(String apiKey) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof ApiKeyAuth) { + ApiKeyAuth keyAuth = (ApiKeyAuth) apiAuthorization; + keyAuth.setApiKey(apiKey); return this; + } } + return this; + } - /** - * Get HTTP client - * - * @return An instance of OkHttpClient - */ - public OkHttpClient getHttpClient() { - return httpClient; - } - - /** - * Set HTTP client - * - * @param httpClient An instance of OkHttpClient - * @return Api Client - */ - public ApiClient setHttpClient(OkHttpClient httpClient) { - this.httpClient = httpClient; + /** + * Helper method to configure the username/password for basic auth or password oauth + * @param username Username + * @param password Password + * @return ApiClient + */ + public ApiClient setCredentials(String username, String password) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof HttpBasicAuth) { + HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization; + basicAuth.setCredentials(username, password); return this; - } - - /** - * Get JSON - * - * @return JSON object - */ - public JSON getJSON() { - return json; - } - - /** - * Set JSON - * - * @param json JSON object - * @return Api client - */ - public ApiClient setJSON(JSON json) { - this.json = json; + } + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + oauth.getTokenRequestBuilder().setUsername(username).setPassword(password); return this; + } } + return this; + } - /** - * True if isVerifyingSsl flag is on - * - * @return True if isVerifySsl flag is on - */ - public boolean isVerifyingSsl() { - return verifyingSsl; + /** + * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one) + * @return Token request builder + */ + public TokenRequestBuilder getTokenEndPoint() { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + return oauth.getTokenRequestBuilder(); + } } + return null; + } - /** - * Configure whether to verify certificate and hostname when making https requests. - * Default to true. - * NOTE: Do NOT set to false in production code, otherwise you would face multiple types of cryptographic attacks. - * - * @param verifyingSsl True to verify TLS/SSL connection - * @return ApiClient - */ - public ApiClient setVerifyingSsl(boolean verifyingSsl) { - this.verifyingSsl = verifyingSsl; - applySslSettings(); + /** + * Helper method to configure authorization endpoint of the first oauth found in the apiAuthorizations (there should be only one) + * @return Authentication request builder + */ + public AuthenticationRequestBuilder getAuthorizationEndPoint() { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + return oauth.getAuthenticationRequestBuilder(); + } + } + return null; + } + + /** + * Helper method to pre-set the oauth access token of the first oauth found in the apiAuthorizations (there should be only one) + * @param accessToken Access token + * @return ApiClient + */ + public ApiClient setAccessToken(String accessToken) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + oauth.setAccessToken(accessToken); return this; + } } + return this; + } - /** - * Get SSL CA cert. - * - * @return Input stream to the SSL CA cert - */ - public InputStream getSslCaCert() { - return sslCaCert; - } - - /** - * Configure the CA certificate to be trusted when making https requests. - * Use null to reset to default. - * - * @param sslCaCert input stream for SSL CA cert - * @return ApiClient - */ - public ApiClient setSslCaCert(InputStream sslCaCert) { - this.sslCaCert = sslCaCert; - applySslSettings(); + /** + * Helper method to configure the oauth accessCode/implicit flow parameters + * @param clientId Client ID + * @param clientSecret Client secret + * @param redirectURI Redirect URI + * @return ApiClient + */ + public ApiClient configureAuthorizationFlow(String clientId, String clientSecret, String redirectURI) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + oauth.getTokenRequestBuilder() + .setClientId(clientId) + .setClientSecret(clientSecret) + .setRedirectURI(redirectURI); + oauth.getAuthenticationRequestBuilder() + .setClientId(clientId) + .setRedirectURI(redirectURI); return this; + } } + return this; + } - public KeyManager[] getKeyManagers() { - return keyManagers; - } - - /** - * Configure client keys to use for authorization in an SSL session. - * Use null to reset to default. - * - * @param managers The KeyManagers to use - * @return ApiClient - */ - public ApiClient setKeyManagers(KeyManager[] managers) { - this.keyManagers = managers; - applySslSettings(); + /** + * Configures a listener which is notified when a new access token is received. + * @param accessTokenListener Access token listener + * @return ApiClient + */ + public ApiClient registerAccessTokenListener(AccessTokenListener accessTokenListener) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + oauth.registerAccessTokenListener(accessTokenListener); return this; + } } + return this; + } - public DateFormat getDateFormat() { - return dateFormat; + /** + * Adds an authorization to be used by the client + * @param authName Authentication name + * @param authorization Authorization interceptor + * @return ApiClient + */ + public ApiClient addAuthorization(String authName, Interceptor authorization) { + if (apiAuthorizations.containsKey(authName)) { + throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations"); } + apiAuthorizations.put(authName, authorization); + okBuilder.addInterceptor(authorization); + return this; + } - public ApiClient setDateFormat(DateFormat dateFormat) { - this.json.setDateFormat(dateFormat); - return this; - } - - public ApiClient setSqlDateFormat(DateFormat dateFormat) { - this.json.setSqlDateFormat(dateFormat); - return this; - } - - public ApiClient setOffsetDateTimeFormat(DateTimeFormatter dateFormat) { - this.json.setOffsetDateTimeFormat(dateFormat); - return this; - } - - public ApiClient setLocalDateFormat(DateTimeFormatter dateFormat) { - this.json.setLocalDateFormat(dateFormat); - return this; - } - - public ApiClient setLenientOnJson(boolean lenientOnJson) { - this.json.setLenientOnJson(lenientOnJson); - return this; - } - - /** - * Get authentications (key: authentication name, value: authentication). - * - * @return Map of authentication objects - */ - public Map getAuthentications() { - return authentications; - } - - /** - * Get authentication for the given name. - * - * @param authName The authentication name - * @return The authentication, null if not found - */ - public Authentication getAuthentication(String authName) { - return authentications.get(authName); - } - - /** - * Helper method to set username for the first HTTP basic authentication. - * - * @param username Username - */ - public void setUsername(String username) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setUsername(username); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); - } - - /** - * Helper method to set password for the first HTTP basic authentication. - * - * @param password Password - */ - public void setPassword(String password) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setPassword(password); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); - } - - /** - * Helper method to set API key value for the first API key authentication. - * - * @param apiKey API key - */ - public void setApiKey(String apiKey) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKey(apiKey); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); - } - - /** - * Helper method to set API key prefix for the first API key authentication. - * - * @param apiKeyPrefix API key prefix - */ - public void setApiKeyPrefix(String apiKeyPrefix) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); - } - - /** - * Helper method to set access token for the first OAuth2 authentication. - * - * @param accessToken Access token - */ - public void setAccessToken(String accessToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof OAuth) { - ((OAuth) auth).setAccessToken(accessToken); - return; - } - } - throw new RuntimeException("No OAuth2 authentication configured!"); - } - - /** - * Set the User-Agent header's value (by adding to the default header map). - * - * @param userAgent HTTP request's user agent - * @return ApiClient - */ - public ApiClient setUserAgent(String userAgent) { - addDefaultHeader("User-Agent", userAgent); - return this; - } - - /** - * Add a default header. - * - * @param key The header's key - * @param value The header's value - * @return ApiClient - */ - public ApiClient addDefaultHeader(String key, String value) { - defaultHeaderMap.put(key, value); - return this; - } - - /** - * Check that whether debugging is enabled for this API client. - * - * @return True if debugging is enabled, false otherwise. - */ - public boolean isDebugging() { - return debugging; - } - - /** - * Enable/disable debugging for this API client. - * - * @param debugging To enable (true) or disable (false) debugging - * @return ApiClient - */ - public ApiClient setDebugging(boolean debugging) { - if (debugging != this.debugging) { - if (debugging) { - loggingInterceptor = new HttpLoggingInterceptor(); - loggingInterceptor.setLevel(Level.BODY); - httpClient.interceptors().add(loggingInterceptor); - } else { - httpClient.interceptors().remove(loggingInterceptor); - loggingInterceptor = null; - } - } - this.debugging = debugging; - return this; - } - - /** - * The path of temporary folder used to store downloaded files from endpoints - * with file response. The default value is null, i.e. using - * the system's default tempopary folder. - * - * @see createTempFile - * @return Temporary folder path - */ - public String getTempFolderPath() { - return tempFolderPath; - } - - /** - * Set the temporary folder path (for downloading files) - * - * @param tempFolderPath Temporary folder path - * @return ApiClient - */ - public ApiClient setTempFolderPath(String tempFolderPath) { - this.tempFolderPath = tempFolderPath; - return this; - } - - /** - * Get connection timeout (in milliseconds). - * - * @return Timeout in milliseconds - */ - public int getConnectTimeout() { - return httpClient.getConnectTimeout(); - } - - /** - * Sets the connect timeout (in milliseconds). - * A value of 0 means no timeout, otherwise values must be between 1 and - * {@link Integer#MAX_VALUE}. - * - * @param connectionTimeout connection timeout in milliseconds - * @return Api client - */ - public ApiClient setConnectTimeout(int connectionTimeout) { - httpClient.setConnectTimeout(connectionTimeout, TimeUnit.MILLISECONDS); - return this; - } - - /** - * Get read timeout (in milliseconds). - * - * @return Timeout in milliseconds - */ - public int getReadTimeout() { - return httpClient.getReadTimeout(); - } - - /** - * Sets the read timeout (in milliseconds). - * A value of 0 means no timeout, otherwise values must be between 1 and - * {@link Integer#MAX_VALUE}. - * - * @param readTimeout read timeout in milliseconds - * @return Api client - */ - public ApiClient setReadTimeout(int readTimeout) { - httpClient.setReadTimeout(readTimeout, TimeUnit.MILLISECONDS); - return this; - } - - /** - * Get write timeout (in milliseconds). - * - * @return Timeout in milliseconds - */ - public int getWriteTimeout() { - return httpClient.getWriteTimeout(); - } - - /** - * Sets the write timeout (in milliseconds). - * A value of 0 means no timeout, otherwise values must be between 1 and - * {@link Integer#MAX_VALUE}. - * - * @param writeTimeout connection timeout in milliseconds - * @return Api client - */ - public ApiClient setWriteTimeout(int writeTimeout) { - httpClient.setWriteTimeout(writeTimeout, TimeUnit.MILLISECONDS); - return this; - } - - /** - * Format the given parameter object into string. - * - * @param param Parameter - * @return String representation of the parameter - */ - public String parameterToString(Object param) { - if (param == null) { - return ""; - } else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) { - //Serialize to json string and remove the " enclosing characters - String jsonStr = json.serialize(param); - return jsonStr.substring(1, jsonStr.length() - 1); - } else if (param instanceof Collection) { - StringBuilder b = new StringBuilder(); - for (Object o : (Collection)param) { - if (b.length() > 0) { - b.append(","); - } - b.append(String.valueOf(o)); - } - return b.toString(); - } else { - return String.valueOf(param); - } - } - - /** - * Formats the specified query parameter to a list containing a single {@code Pair} object. - * - * Note that {@code value} must not be a collection. - * - * @param name The name of the parameter. - * @param value The value of the parameter. - * @return A list containing a single {@code Pair} object. - */ - public List parameterToPair(String name, Object value) { - List params = new ArrayList(); - - // preconditions - if (name == null || name.isEmpty() || value == null || value instanceof Collection) return params; - - params.add(new Pair(name, parameterToString(value))); - return params; - } - - /** - * Formats the specified collection query parameters to a list of {@code Pair} objects. - * - * Note that the values of each of the returned Pair objects are percent-encoded. - * - * @param collectionFormat The collection format of the parameter. - * @param name The name of the parameter. - * @param value The value of the parameter. - * @return A list of {@code Pair} objects. - */ - public List parameterToPairs(String collectionFormat, String name, Collection value) { - List params = new ArrayList(); - - // preconditions - if (name == null || name.isEmpty() || value == null || value.isEmpty()) { - return params; - } - - // create the params based on the collection format - if ("multi".equals(collectionFormat)) { - for (Object item : value) { - params.add(new Pair(name, escapeString(parameterToString(item)))); - } - return params; - } - - // collectionFormat is assumed to be "csv" by default - String delimiter = ","; - - // escape all delimiters except commas, which are URI reserved - // characters - if ("ssv".equals(collectionFormat)) { - delimiter = escapeString(" "); - } else if ("tsv".equals(collectionFormat)) { - delimiter = escapeString("\t"); - } else if ("pipes".equals(collectionFormat)) { - delimiter = escapeString("|"); - } - - StringBuilder sb = new StringBuilder() ; - for (Object item : value) { - sb.append(delimiter); - sb.append(escapeString(parameterToString(item))); - } - - params.add(new Pair(name, sb.substring(delimiter.length()))); - - return params; - } - - /** - * Sanitize filename by removing path. - * e.g. ../../sun.gif becomes sun.gif - * - * @param filename The filename to be sanitized - * @return The sanitized filename - */ - public String sanitizeFilename(String filename) { - return filename.replaceAll(".*[/\\\\]", ""); - } - - /** - * Check if the given MIME is a JSON MIME. - * JSON MIME examples: - * application/json - * application/json; charset=UTF8 - * APPLICATION/JSON - * application/vnd.company+json - * "* / *" is also default to JSON - * @param mime MIME (Multipurpose Internet Mail Extensions) - * @return True if the given MIME is JSON, false otherwise. - */ - public boolean isJsonMime(String mime) { - String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && (mime.matches(jsonMime) || mime.equals("*/*")); - } - - /** - * Select the Accept header's value from the given accepts array: - * if JSON exists in the given array, use it; - * otherwise use all of them (joining into a string) - * - * @param accepts The accepts array to select from - * @return The Accept header to use. If the given array is empty, - * null will be returned (not to set the Accept header explicitly). - */ - public String selectHeaderAccept(String[] accepts) { - if (accepts.length == 0) { - return null; - } - for (String accept : accepts) { - if (isJsonMime(accept)) { - return accept; - } - } - return StringUtil.join(accepts, ","); - } - - /** - * Select the Content-Type header's value from the given array: - * if JSON exists in the given array, use it; - * otherwise use the first one of the array. - * - * @param contentTypes The Content-Type array to select from - * @return The Content-Type header to use. If the given array is empty, - * or matches "any", JSON will be used. - */ - public String selectHeaderContentType(String[] contentTypes) { - if (contentTypes.length == 0 || contentTypes[0].equals("*/*")) { - return "application/json"; - } - for (String contentType : contentTypes) { - if (isJsonMime(contentType)) { - return contentType; - } - } - return contentTypes[0]; - } - - /** - * Escape the given string to be used as URL query value. - * - * @param str String to be escaped - * @return Escaped string - */ - public String escapeString(String str) { - try { - return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20"); - } catch (UnsupportedEncodingException e) { - return str; - } - } - - /** - * Deserialize response body to Java object, according to the return type and - * the Content-Type response header. - * - * @param Type - * @param response HTTP response - * @param returnType The type of the Java object - * @return The deserialized Java object - * @throws ApiException If fail to deserialize response body, i.e. cannot read response body - * or the Content-Type of the response is not supported. - */ - @SuppressWarnings("unchecked") - public T deserialize(Response response, Type returnType) throws ApiException { - if (response == null || returnType == null) { - return null; - } - - if ("byte[]".equals(returnType.toString())) { - // Handle binary response (byte array). - try { - return (T) response.body().bytes(); - } catch (IOException e) { - throw new ApiException(e); - } - } else if (returnType.equals(File.class)) { - // Handle file downloading. - return (T) downloadFileFromResponse(response); - } - - String respBody; - try { - if (response.body() != null) - respBody = response.body().string(); - else - respBody = null; - } catch (IOException e) { - throw new ApiException(e); - } - - if (respBody == null || "".equals(respBody)) { - return null; - } - - String contentType = response.headers().get("Content-Type"); - if (contentType == null) { - // ensuring a default content type - contentType = "application/json"; - } - if (isJsonMime(contentType)) { - return json.deserialize(respBody, returnType); - } else if (returnType.equals(String.class)) { - // Expecting string, return the raw response body. - return (T) respBody; - } else { - throw new ApiException( - "Content type \"" + contentType + "\" is not supported for type: " + returnType, - response.code(), - response.headers().toMultimap(), - respBody); - } - } - - /** - * Serialize the given Java object into request body according to the object's - * class and the request Content-Type. - * - * @param obj The Java object - * @param contentType The request Content-Type - * @return The serialized request body - * @throws ApiException If fail to serialize the given object - */ - public RequestBody serialize(Object obj, String contentType) throws ApiException { - if (obj instanceof byte[]) { - // Binary (byte array) body parameter support. - return RequestBody.create(MediaType.parse(contentType), (byte[]) obj); - } else if (obj instanceof File) { - // File body parameter support. - return RequestBody.create(MediaType.parse(contentType), (File) obj); - } else if (isJsonMime(contentType)) { - String content; - if (obj != null) { - content = json.serialize(obj); - } else { - content = null; - } - return RequestBody.create(MediaType.parse(contentType), content); - } else { - throw new ApiException("Content type \"" + contentType + "\" is not supported"); - } - } - - /** - * Download file from the given response. - * - * @param response An instance of the Response object - * @throws ApiException If fail to read file content from response and write to disk - * @return Downloaded file - */ - public File downloadFileFromResponse(Response response) throws ApiException { - try { - File file = prepareDownloadFile(response); - BufferedSink sink = Okio.buffer(Okio.sink(file)); - sink.writeAll(response.body().source()); - sink.close(); - return file; - } catch (IOException e) { - throw new ApiException(e); - } - } - - /** - * Prepare file for download - * - * @param response An instance of the Response object - * @throws IOException If fail to prepare file for download - * @return Prepared file for the download - */ - public File prepareDownloadFile(Response response) throws IOException { - String filename = null; - String contentDisposition = response.header("Content-Disposition"); - if (contentDisposition != null && !"".equals(contentDisposition)) { - // Get filename from the Content-Disposition header. - Pattern pattern = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?"); - Matcher matcher = pattern.matcher(contentDisposition); - if (matcher.find()) { - filename = sanitizeFilename(matcher.group(1)); - } - } - - String prefix = null; - String suffix = null; - if (filename == null) { - prefix = "download-"; - suffix = ""; - } else { - int pos = filename.lastIndexOf("."); - if (pos == -1) { - prefix = filename + "-"; - } else { - prefix = filename.substring(0, pos) + "-"; - suffix = filename.substring(pos); - } - // File.createTempFile requires the prefix to be at least three characters long - if (prefix.length() < 3) - prefix = "download-"; - } - - if (tempFolderPath == null) - return File.createTempFile(prefix, suffix); - else - return File.createTempFile(prefix, suffix, new File(tempFolderPath)); - } - - /** - * {@link #execute(Call, Type)} - * - * @param Type - * @param call An instance of the Call object - * @throws ApiException If fail to execute the call - * @return ApiResponse<T> - */ - public ApiResponse execute(Call call) throws ApiException { - return execute(call, null); - } - - /** - * Execute HTTP call and deserialize the HTTP response body into the given return type. - * - * @param returnType The return type used to deserialize HTTP response body - * @param The return type corresponding to (same with) returnType - * @param call Call - * @return ApiResponse object containing response status, headers and - * data, which is a Java object deserialized from response body and would be null - * when returnType is null. - * @throws ApiException If fail to execute the call - */ - public ApiResponse execute(Call call, Type returnType) throws ApiException { - try { - Response response = call.execute(); - T data = handleResponse(response, returnType); - return new ApiResponse(response.code(), response.headers().toMultimap(), data); - } catch (IOException e) { - throw new ApiException(e); - } - } - - /** - * {@link #executeAsync(Call, Type, ApiCallback)} - * - * @param Type - * @param call An instance of the Call object - * @param callback ApiCallback<T> - */ - public void executeAsync(Call call, ApiCallback callback) { - executeAsync(call, null, callback); - } - - /** - * Execute HTTP call asynchronously. - * - * @see #execute(Call, Type) - * @param Type - * @param call The callback to be executed when the API call finishes - * @param returnType Return type - * @param callback ApiCallback - */ - @SuppressWarnings("unchecked") - public void executeAsync(Call call, final Type returnType, final ApiCallback callback) { - call.enqueue(new Callback() { - @Override - public void onFailure(Request request, IOException e) { - callback.onFailure(new ApiException(e), 0, null); - } - - @Override - public void onResponse(Response response) throws IOException { - T result; - try { - result = (T) handleResponse(response, returnType); - } catch (ApiException e) { - callback.onFailure(e, response.code(), response.headers().toMultimap()); - return; - } - callback.onSuccess(result, response.code(), response.headers().toMultimap()); - } - }); - } - - /** - * Handle the given response, return the deserialized object when the response is successful. - * - * @param Type - * @param response Response - * @param returnType Return type - * @throws ApiException If the response has a unsuccessful status code or - * fail to deserialize the response body - * @return Type - */ - public T handleResponse(Response response, Type returnType) throws ApiException { - if (response.isSuccessful()) { - if (returnType == null || response.code() == 204) { - // returning null if the returnType is not defined, - // or the status code is 204 (No Content) - if (response.body() != null) { - try { - response.body().close(); - } catch (IOException e) { - throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap()); - } - } - return null; - } else { - return deserialize(response, returnType); - } - } else { - String respBody = null; - if (response.body() != null) { - try { - respBody = response.body().string(); - } catch (IOException e) { - throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap()); - } - } - throw new ApiException(response.message(), response.code(), response.headers().toMultimap(), respBody); - } - } - - /** - * Build HTTP call with the given options. - * - * @param path The sub-path of the HTTP URL - * @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE" - * @param queryParams The query parameters - * @param collectionQueryParams The collection query parameters - * @param body The request body object - * @param headerParams The header parameters - * @param formParams The form parameters - * @param authNames The authentications to apply - * @param progressRequestListener Progress request listener - * @return The HTTP call - * @throws ApiException If fail to serialize the request body object - */ - public Call buildCall(String path, String method, List queryParams, List collectionQueryParams, Object body, Map headerParams, Map formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Request request = buildRequest(path, method, queryParams, collectionQueryParams, body, headerParams, formParams, authNames, progressRequestListener); - - return httpClient.newCall(request); - } - - /** - * Build an HTTP request with the given options. - * - * @param path The sub-path of the HTTP URL - * @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE" - * @param queryParams The query parameters - * @param collectionQueryParams The collection query parameters - * @param body The request body object - * @param headerParams The header parameters - * @param formParams The form parameters - * @param authNames The authentications to apply - * @param progressRequestListener Progress request listener - * @return The HTTP request - * @throws ApiException If fail to serialize the request body object - */ - public Request buildRequest(String path, String method, List queryParams, List collectionQueryParams, Object body, Map headerParams, Map formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - updateParamsForAuth(authNames, queryParams, headerParams); - - final String url = buildUrl(path, queryParams, collectionQueryParams); - final Request.Builder reqBuilder = new Request.Builder().url(url); - processHeaderParams(headerParams, reqBuilder); - - String contentType = (String) headerParams.get("Content-Type"); - // ensuring a default content type - if (contentType == null) { - contentType = "application/json"; - } - - RequestBody reqBody; - if (!HttpMethod.permitsRequestBody(method)) { - reqBody = null; - } else if ("application/x-www-form-urlencoded".equals(contentType)) { - reqBody = buildRequestBodyFormEncoding(formParams); - } else if ("multipart/form-data".equals(contentType)) { - reqBody = buildRequestBodyMultipart(formParams); - } else if (body == null) { - if ("DELETE".equals(method)) { - // allow calling DELETE without sending a request body - reqBody = null; - } else { - // use an empty request body (for POST, PUT and PATCH) - reqBody = RequestBody.create(MediaType.parse(contentType), ""); - } - } else { - reqBody = serialize(body, contentType); - } - - Request request = null; - - if(progressRequestListener != null && reqBody != null) { - ProgressRequestBody progressRequestBody = new ProgressRequestBody(reqBody, progressRequestListener); - request = reqBuilder.method(method, progressRequestBody).build(); - } else { - request = reqBuilder.method(method, reqBody).build(); - } - - return request; - } - - /** - * Build full URL by concatenating base path, the given sub path and query parameters. - * - * @param path The sub path - * @param queryParams The query parameters - * @param collectionQueryParams The collection query parameters - * @return The full URL - */ - public String buildUrl(String path, List queryParams, List collectionQueryParams) { - final StringBuilder url = new StringBuilder(); - url.append(basePath).append(path); - - if (queryParams != null && !queryParams.isEmpty()) { - // support (constant) query string in `path`, e.g. "/posts?draft=1" - String prefix = path.contains("?") ? "&" : "?"; - for (Pair param : queryParams) { - if (param.getValue() != null) { - if (prefix != null) { - url.append(prefix); - prefix = null; - } else { - url.append("&"); - } - String value = parameterToString(param.getValue()); - url.append(escapeString(param.getName())).append("=").append(escapeString(value)); - } - } - } - - if (collectionQueryParams != null && !collectionQueryParams.isEmpty()) { - String prefix = url.toString().contains("?") ? "&" : "?"; - for (Pair param : collectionQueryParams) { - if (param.getValue() != null) { - if (prefix != null) { - url.append(prefix); - prefix = null; - } else { - url.append("&"); - } - String value = parameterToString(param.getValue()); - // collection query parameter value already escaped as part of parameterToPairs - url.append(escapeString(param.getName())).append("=").append(value); - } - } - } - - return url.toString(); - } - - /** - * Set header parameters to the request builder, including default headers. - * - * @param headerParams Header parameters in the ofrm of Map - * @param reqBuilder Reqeust.Builder - */ - public void processHeaderParams(Map headerParams, Request.Builder reqBuilder) { - for (Entry param : headerParams.entrySet()) { - reqBuilder.header(param.getKey(), parameterToString(param.getValue())); - } - for (Entry header : defaultHeaderMap.entrySet()) { - if (!headerParams.containsKey(header.getKey())) { - reqBuilder.header(header.getKey(), parameterToString(header.getValue())); - } - } - } - - /** - * Update query and header parameters based on authentication settings. - * - * @param authNames The authentications to apply - * @param queryParams List of query parameters - * @param headerParams Map of header parameters - */ - public void updateParamsForAuth(String[] authNames, List queryParams, Map headerParams) { - for (String authName : authNames) { - Authentication auth = authentications.get(authName); - if (auth == null) throw new RuntimeException("Authentication undefined: " + authName); - auth.applyToParams(queryParams, headerParams); - } - } - - /** - * Build a form-encoding request body with the given form parameters. - * - * @param formParams Form parameters in the form of Map - * @return RequestBody - */ - public RequestBody buildRequestBodyFormEncoding(Map formParams) { - FormEncodingBuilder formBuilder = new FormEncodingBuilder(); - for (Entry param : formParams.entrySet()) { - formBuilder.add(param.getKey(), parameterToString(param.getValue())); - } - return formBuilder.build(); - } - - /** - * Build a multipart (file uploading) request body with the given form parameters, - * which could contain text fields and file fields. - * - * @param formParams Form parameters in the form of Map - * @return RequestBody - */ - public RequestBody buildRequestBodyMultipart(Map formParams) { - MultipartBuilder mpBuilder = new MultipartBuilder().type(MultipartBuilder.FORM); - for (Entry param : formParams.entrySet()) { - if (param.getValue() instanceof File) { - File file = (File) param.getValue(); - Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"; filename=\"" + file.getName() + "\""); - MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file)); - mpBuilder.addPart(partHeaders, RequestBody.create(mediaType, file)); - } else { - Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\""); - mpBuilder.addPart(partHeaders, RequestBody.create(null, parameterToString(param.getValue()))); - } - } - return mpBuilder.build(); - } - - /** - * Guess Content-Type header from the given file (defaults to "application/octet-stream"). - * - * @param file The given file - * @return The guessed Content-Type - */ - public String guessContentTypeFromFile(File file) { - String contentType = URLConnection.guessContentTypeFromName(file.getName()); - if (contentType == null) { - return "application/octet-stream"; - } else { - return contentType; - } - } - - /** - * Apply SSL related settings to httpClient according to the current values of - * verifyingSsl and sslCaCert. - */ - private void applySslSettings() { - try { - TrustManager[] trustManagers = null; - HostnameVerifier hostnameVerifier = null; - if (!verifyingSsl) { - TrustManager trustAll = new X509TrustManager() { - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {} - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {} - @Override - public X509Certificate[] getAcceptedIssuers() { return null; } - }; - SSLContext sslContext = SSLContext.getInstance("TLS"); - trustManagers = new TrustManager[]{ trustAll }; - hostnameVerifier = new HostnameVerifier() { - @Override - public boolean verify(String hostname, SSLSession session) { return true; } - }; - } else if (sslCaCert != null) { - char[] password = null; // Any password will work. - CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); - Collection certificates = certificateFactory.generateCertificates(sslCaCert); - if (certificates.isEmpty()) { - throw new IllegalArgumentException("expected non-empty set of trusted certificates"); - } - KeyStore caKeyStore = newEmptyKeyStore(password); - int index = 0; - for (Certificate certificate : certificates) { - String certificateAlias = "ca" + Integer.toString(index++); - caKeyStore.setCertificateEntry(certificateAlias, certificate); - } - TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - trustManagerFactory.init(caKeyStore); - trustManagers = trustManagerFactory.getTrustManagers(); - } - - if (keyManagers != null || trustManagers != null) { - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(keyManagers, trustManagers, new SecureRandom()); - httpClient.setSslSocketFactory(sslContext.getSocketFactory()); - } else { - httpClient.setSslSocketFactory(null); - } - httpClient.setHostnameVerifier(hostnameVerifier); - } catch (GeneralSecurityException e) { - throw new RuntimeException(e); - } - } - - private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException { - try { - KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); - keyStore.load(null, password); - return keyStore; - } catch (IOException e) { - throw new AssertionError(e); - } + public Map getApiAuthorizations() { + return apiAuthorizations; + } + + public ApiClient setApiAuthorizations(Map apiAuthorizations) { + this.apiAuthorizations = apiAuthorizations; + return this; + } + + public Retrofit.Builder getAdapterBuilder() { + return adapterBuilder; + } + + public ApiClient setAdapterBuilder(Retrofit.Builder adapterBuilder) { + this.adapterBuilder = adapterBuilder; + return this; + } + + public OkHttpClient.Builder getOkBuilder() { + return okBuilder; + } + + public void addAuthsToOkBuilder(OkHttpClient.Builder okBuilder) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + okBuilder.addInterceptor(apiAuthorization); } + } + + /** + * Clones the okBuilder given in parameter, adds the auth interceptors and uses it to configure the Retrofit + * @param okClient An instance of OK HTTP client + */ + public void configureFromOkclient(OkHttpClient okClient) { + this.okBuilder = okClient.newBuilder(); + addAuthsToOkBuilder(this.okBuilder); + } +} + +/** + * This wrapper is to take care of this case: + * when the deserialization fails due to JsonParseException and the + * expected type is String, then just return the body string. + */ +class GsonResponseBodyConverterToString implements Converter { + private final Gson gson; + private final Type type; + + GsonResponseBodyConverterToString(Gson gson, Type type) { + this.gson = gson; + this.type = type; + } + + @Override public T convert(ResponseBody value) throws IOException { + String returned = value.string(); + try { + return gson.fromJson(returned, type); + } + catch (JsonParseException e) { + return (T) returned; + } + } +} + +class GsonCustomConverterFactory extends Converter.Factory +{ + private final Gson gson; + private final GsonConverterFactory gsonConverterFactory; + + public static GsonCustomConverterFactory create(Gson gson) { + return new GsonCustomConverterFactory(gson); + } + + private GsonCustomConverterFactory(Gson gson) { + if (gson == null) + throw new NullPointerException("gson == null"); + this.gson = gson; + this.gsonConverterFactory = GsonConverterFactory.create(gson); + } + + @Override + public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + if (type.equals(String.class)) + return new GsonResponseBodyConverterToString(gson, type); + else + return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit); + } + + @Override + public Converter requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) { + return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit); + } } diff --git a/client/src/main/java/com/github/gotify/client/ApiException.java b/client/src/main/java/com/github/gotify/client/ApiException.java deleted file mode 100644 index 48fd857..0000000 --- a/client/src/main/java/com/github/gotify/client/ApiException.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package com.github.gotify.client; - -import java.util.Map; -import java.util.List; - -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") -public class ApiException extends Exception { - private int code = 0; - private Map> responseHeaders = null; - private String responseBody = null; - - public ApiException() {} - - public ApiException(Throwable throwable) { - super(throwable); - } - - public ApiException(String message) { - super(message); - } - - public ApiException(String message, Throwable throwable, int code, Map> responseHeaders, String responseBody) { - super(message, throwable); - this.code = code; - this.responseHeaders = responseHeaders; - this.responseBody = responseBody; - } - - public ApiException(String message, int code, Map> responseHeaders, String responseBody) { - this(message, (Throwable) null, code, responseHeaders, responseBody); - } - - public ApiException(String message, Throwable throwable, int code, Map> responseHeaders) { - this(message, throwable, code, responseHeaders, null); - } - - public ApiException(int code, Map> responseHeaders, String responseBody) { - this((String) null, (Throwable) null, code, responseHeaders, responseBody); - } - - public ApiException(int code, String message) { - super(message); - this.code = code; - } - - public ApiException(int code, String message, Map> responseHeaders, String responseBody) { - this(code, message); - this.responseHeaders = responseHeaders; - this.responseBody = responseBody; - } - - /** - * Get the HTTP status code. - * - * @return HTTP status code - */ - public int getCode() { - return code; - } - - /** - * Get the HTTP response headers. - * - * @return A map of list of string - */ - public Map> getResponseHeaders() { - return responseHeaders; - } - - /** - * Get the HTTP response body. - * - * @return Response body in the form of string - */ - public String getResponseBody() { - return responseBody; - } -} diff --git a/client/src/main/java/com/github/gotify/client/ApiResponse.java b/client/src/main/java/com/github/gotify/client/ApiResponse.java deleted file mode 100644 index c3d5792..0000000 --- a/client/src/main/java/com/github/gotify/client/ApiResponse.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package com.github.gotify.client; - -import java.util.List; -import java.util.Map; - -/** - * API response returned by API call. - * - * @param The type of data that is deserialized from response body - */ -public class ApiResponse { - final private int statusCode; - final private Map> headers; - final private T data; - - /** - * @param statusCode The status code of HTTP response - * @param headers The headers of HTTP response - */ - public ApiResponse(int statusCode, Map> headers) { - this(statusCode, headers, null); - } - - /** - * @param statusCode The status code of HTTP response - * @param headers The headers of HTTP response - * @param data The object deserialized from response bod - */ - public ApiResponse(int statusCode, Map> headers, T data) { - this.statusCode = statusCode; - this.headers = headers; - this.data = data; - } - - public int getStatusCode() { - return statusCode; - } - - public Map> getHeaders() { - return headers; - } - - public T getData() { - return data; - } -} diff --git a/client/src/main/java/com/github/gotify/client/CollectionFormats.java b/client/src/main/java/com/github/gotify/client/CollectionFormats.java new file mode 100644 index 0000000..5942517 --- /dev/null +++ b/client/src/main/java/com/github/gotify/client/CollectionFormats.java @@ -0,0 +1,95 @@ +package com.github.gotify.client; + +import java.util.Arrays; +import java.util.List; + +public class CollectionFormats { + + public static class CSVParams { + + protected List params; + + public CSVParams() { + } + + public CSVParams(List params) { + this.params = params; + } + + public CSVParams(String... params) { + this.params = Arrays.asList(params); + } + + public List getParams() { + return params; + } + + public void setParams(List params) { + this.params = params; + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), ","); + } + + } + + public static class SSVParams extends CSVParams { + + public SSVParams() { + } + + public SSVParams(List params) { + super(params); + } + + public SSVParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), " "); + } + } + + public static class TSVParams extends CSVParams { + + public TSVParams() { + } + + public TSVParams(List params) { + super(params); + } + + public TSVParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join( params.toArray(new String[0]), "\t"); + } + } + + public static class PIPESParams extends CSVParams { + + public PIPESParams() { + } + + public PIPESParams(List params) { + super(params); + } + + public PIPESParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), "|"); + } + } + +} diff --git a/client/src/main/java/com/github/gotify/client/Configuration.java b/client/src/main/java/com/github/gotify/client/Configuration.java deleted file mode 100644 index 6a4bcb5..0000000 --- a/client/src/main/java/com/github/gotify/client/Configuration.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package com.github.gotify.client; - -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") -public class Configuration { - private static ApiClient defaultApiClient = new ApiClient(); - - /** - * Get the default API client, which would be used when creating API - * instances without providing an API client. - * - * @return Default API client - */ - public static ApiClient getDefaultApiClient() { - return defaultApiClient; - } - - /** - * Set the default API client, which would be used when creating API - * instances without providing an API client. - * - * @param apiClient API client - */ - public static void setDefaultApiClient(ApiClient apiClient) { - defaultApiClient = apiClient; - } -} diff --git a/client/src/main/java/com/github/gotify/client/GzipRequestInterceptor.java b/client/src/main/java/com/github/gotify/client/GzipRequestInterceptor.java deleted file mode 100644 index 31e79c4..0000000 --- a/client/src/main/java/com/github/gotify/client/GzipRequestInterceptor.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package com.github.gotify.client; - -import com.squareup.okhttp.*; -import okio.Buffer; -import okio.BufferedSink; -import okio.GzipSink; -import okio.Okio; - -import java.io.IOException; - -/** - * Encodes request bodies using gzip. - * - * Taken from https://github.com/square/okhttp/issues/350 - */ -class GzipRequestInterceptor implements Interceptor { - @Override public Response intercept(Chain chain) throws IOException { - Request originalRequest = chain.request(); - if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) { - return chain.proceed(originalRequest); - } - - Request compressedRequest = originalRequest.newBuilder() - .header("Content-Encoding", "gzip") - .method(originalRequest.method(), forceContentLength(gzip(originalRequest.body()))) - .build(); - return chain.proceed(compressedRequest); - } - - private RequestBody forceContentLength(final RequestBody requestBody) throws IOException { - final Buffer buffer = new Buffer(); - requestBody.writeTo(buffer); - return new RequestBody() { - @Override - public MediaType contentType() { - return requestBody.contentType(); - } - - @Override - public long contentLength() { - return buffer.size(); - } - - @Override - public void writeTo(BufferedSink sink) throws IOException { - sink.write(buffer.snapshot()); - } - }; - } - - private RequestBody gzip(final RequestBody body) { - return new RequestBody() { - @Override public MediaType contentType() { - return body.contentType(); - } - - @Override public long contentLength() { - return -1; // We don't know the compressed length in advance! - } - - @Override public void writeTo(BufferedSink sink) throws IOException { - BufferedSink gzipSink = Okio.buffer(new GzipSink(sink)); - body.writeTo(gzipSink); - gzipSink.close(); - } - }; - } -} \ No newline at end of file diff --git a/client/src/main/java/com/github/gotify/client/JSON.java b/client/src/main/java/com/github/gotify/client/JSON.java index 486f0a1..8c9c770 100644 --- a/client/src/main/java/com/github/gotify/client/JSON.java +++ b/client/src/main/java/com/github/gotify/client/JSON.java @@ -41,7 +41,6 @@ import java.util.HashMap; public class JSON { private Gson gson; - private boolean isLenientOnJson = false; private DateTypeAdapter dateTypeAdapter = new DateTypeAdapter(); private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter(); private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(); @@ -98,49 +97,6 @@ public class JSON { return this; } - public JSON setLenientOnJson(boolean lenientOnJson) { - isLenientOnJson = lenientOnJson; - return this; - } - - /** - * Serialize the given Java object into JSON string. - * - * @param obj Object - * @return String representation of the JSON - */ - public String serialize(Object obj) { - return gson.toJson(obj); - } - - /** - * Deserialize the given JSON string to Java object. - * - * @param Type - * @param body The JSON string - * @param returnType The type to deserialize into - * @return The deserialized Java object - */ - @SuppressWarnings("unchecked") - public T deserialize(String body, Type returnType) { - try { - if (isLenientOnJson) { - JsonReader jsonReader = new JsonReader(new StringReader(body)); - // see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean) - jsonReader.setLenient(true); - return gson.fromJson(jsonReader, returnType); - } else { - return gson.fromJson(body, returnType); - } - } catch (JsonParseException e) { - // Fallback processing when failed to parse JSON form response body: - // return the response body string directly for the String return type; - if (returnType.equals(String.class)) - return (T) body; - else throw (e); - } - } - /** * Gson TypeAdapter for JSR310 OffsetDateTime type */ diff --git a/client/src/main/java/com/github/gotify/client/Pair.java b/client/src/main/java/com/github/gotify/client/Pair.java deleted file mode 100644 index 2e9b9c4..0000000 --- a/client/src/main/java/com/github/gotify/client/Pair.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package com.github.gotify.client; - -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") -public class Pair { - private String name = ""; - private String value = ""; - - public Pair (String name, String value) { - setName(name); - setValue(value); - } - - private void setName(String name) { - if (!isValidString(name)) return; - - this.name = name; - } - - private void setValue(String value) { - if (!isValidString(value)) return; - - this.value = value; - } - - public String getName() { - return this.name; - } - - public String getValue() { - return this.value; - } - - private boolean isValidString(String arg) { - if (arg == null) return false; - if (arg.trim().isEmpty()) return false; - - return true; - } -} diff --git a/client/src/main/java/com/github/gotify/client/ProgressRequestBody.java b/client/src/main/java/com/github/gotify/client/ProgressRequestBody.java deleted file mode 100644 index d19fd7b..0000000 --- a/client/src/main/java/com/github/gotify/client/ProgressRequestBody.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package com.github.gotify.client; - -import com.squareup.okhttp.MediaType; -import com.squareup.okhttp.RequestBody; - -import java.io.IOException; - -import okio.Buffer; -import okio.BufferedSink; -import okio.ForwardingSink; -import okio.Okio; -import okio.Sink; - -public class ProgressRequestBody extends RequestBody { - - public interface ProgressRequestListener { - void onRequestProgress(long bytesWritten, long contentLength, boolean done); - } - - private final RequestBody requestBody; - - private final ProgressRequestListener progressListener; - - public ProgressRequestBody(RequestBody requestBody, ProgressRequestListener progressListener) { - this.requestBody = requestBody; - this.progressListener = progressListener; - } - - @Override - public MediaType contentType() { - return requestBody.contentType(); - } - - @Override - public long contentLength() throws IOException { - return requestBody.contentLength(); - } - - @Override - public void writeTo(BufferedSink sink) throws IOException { - BufferedSink bufferedSink = Okio.buffer(sink(sink)); - requestBody.writeTo(bufferedSink); - bufferedSink.flush(); - } - - private Sink sink(Sink sink) { - return new ForwardingSink(sink) { - - long bytesWritten = 0L; - long contentLength = 0L; - - @Override - public void write(Buffer source, long byteCount) throws IOException { - super.write(source, byteCount); - if (contentLength == 0) { - contentLength = contentLength(); - } - - bytesWritten += byteCount; - progressListener.onRequestProgress(bytesWritten, contentLength, bytesWritten == contentLength); - } - }; - } -} diff --git a/client/src/main/java/com/github/gotify/client/ProgressResponseBody.java b/client/src/main/java/com/github/gotify/client/ProgressResponseBody.java deleted file mode 100644 index 4c8a7bf..0000000 --- a/client/src/main/java/com/github/gotify/client/ProgressResponseBody.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package com.github.gotify.client; - -import com.squareup.okhttp.MediaType; -import com.squareup.okhttp.ResponseBody; - -import java.io.IOException; - -import okio.Buffer; -import okio.BufferedSource; -import okio.ForwardingSource; -import okio.Okio; -import okio.Source; - -public class ProgressResponseBody extends ResponseBody { - - public interface ProgressListener { - void update(long bytesRead, long contentLength, boolean done); - } - - private final ResponseBody responseBody; - private final ProgressListener progressListener; - private BufferedSource bufferedSource; - - public ProgressResponseBody(ResponseBody responseBody, ProgressListener progressListener) { - this.responseBody = responseBody; - this.progressListener = progressListener; - } - - @Override - public MediaType contentType() { - return responseBody.contentType(); - } - - @Override - public long contentLength() throws IOException { - return responseBody.contentLength(); - } - - @Override - public BufferedSource source() throws IOException { - if (bufferedSource == null) { - bufferedSource = Okio.buffer(source(responseBody.source())); - } - return bufferedSource; - } - - private Source source(Source source) { - return new ForwardingSource(source) { - long totalBytesRead = 0L; - - @Override - public long read(Buffer sink, long byteCount) throws IOException { - long bytesRead = super.read(sink, byteCount); - // read() returns the number of bytes read, or -1 if this source is exhausted. - totalBytesRead += bytesRead != -1 ? bytesRead : 0; - progressListener.update(totalBytesRead, responseBody.contentLength(), bytesRead == -1); - return bytesRead; - } - }; - } -} - - diff --git a/client/src/main/java/com/github/gotify/client/StringUtil.java b/client/src/main/java/com/github/gotify/client/StringUtil.java index d9c0df3..30f0cc5 100644 --- a/client/src/main/java/com/github/gotify/client/StringUtil.java +++ b/client/src/main/java/com/github/gotify/client/StringUtil.java @@ -13,7 +13,7 @@ package com.github.gotify.client; -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class StringUtil { /** * Check if the given array contains the given value (with case-insensitive comparison). diff --git a/client/src/main/java/com/github/gotify/client/api/MessageApi.java b/client/src/main/java/com/github/gotify/client/api/MessageApi.java index 2e09151..60df793 100644 --- a/client/src/main/java/com/github/gotify/client/api/MessageApi.java +++ b/client/src/main/java/com/github/gotify/client/api/MessageApi.java @@ -1,901 +1,118 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.api; -import com.github.gotify.client.ApiCallback; -import com.github.gotify.client.ApiClient; -import com.github.gotify.client.ApiException; -import com.github.gotify.client.ApiResponse; -import com.github.gotify.client.Configuration; -import com.github.gotify.client.Pair; -import com.github.gotify.client.ProgressRequestBody; -import com.github.gotify.client.ProgressResponseBody; +import com.github.gotify.client.CollectionFormats.*; -import com.google.gson.reflect.TypeToken; - -import java.io.IOException; +import retrofit2.Call; +import retrofit2.http.*; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; import com.github.gotify.client.model.Error; import com.github.gotify.client.model.Message; import com.github.gotify.client.model.PagedMessages; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -public class MessageApi { - private ApiClient apiClient; +public interface MessageApi { + /** + * Create a message. + * __NOTE__: This API ONLY accepts an application token as authentication. + * @param body the message to add (required) + * @return Call<Message> + */ + @Headers({ + "Content-Type:application/json" + }) + @POST("message") + Call createMessage( + @retrofit2.http.Body Message body + ); + + /** + * Delete all messages from a specific application. + * + * @param id the application id (required) + * @return Call<Void> + */ + @Headers({ + "Content-Type:application/json" + }) + @DELETE("application/{id}/message") + Call deleteAppMessages( + @retrofit2.http.Path("id") Integer id + ); + + /** + * Deletes a message with an id. + * + * @param id the message id (required) + * @return Call<Void> + */ + @Headers({ + "Content-Type:application/json" + }) + @DELETE("message/{id}") + Call deleteMessage( + @retrofit2.http.Path("id") Integer id + ); + + /** + * Delete all messages. + * + * @return Call<Void> + */ + @Headers({ + "Content-Type:application/json" + }) + @DELETE("message") + Call deleteMessages(); + + + /** + * Return all messages from a specific application. + * + * @param id the application id (required) + * @param limit the maximal amount of messages to return (optional, default to 100) + * @param since return all messages with an ID less than this value (optional) + * @return Call<PagedMessages> + */ + @Headers({ + "Content-Type:application/json" + }) + @GET("application/{id}/message") + Call getAppMessages( + @retrofit2.http.Path("id") Integer id, @retrofit2.http.Query("limit") Integer limit, @retrofit2.http.Query("since") Integer since + ); + + /** + * Return all messages. + * + * @param limit the maximal amount of messages to return (optional, default to 100) + * @param since return all messages with an ID less than this value (optional) + * @return Call<PagedMessages> + */ + @Headers({ + "Content-Type:application/json" + }) + @GET("message") + Call getMessages( + @retrofit2.http.Query("limit") Integer limit, @retrofit2.http.Query("since") Integer since + ); + + /** + * Websocket, return newly created messages. + * + * @return Call<Message> + */ + @Headers({ + "Content-Type:application/json" + }) + @GET("stream") + Call streamMessages(); + - public MessageApi() { - this(Configuration.getDefaultApiClient()); - } - - public MessageApi(ApiClient apiClient) { - this.apiClient = apiClient; - } - - public ApiClient getApiClient() { - return apiClient; - } - - public void setApiClient(ApiClient apiClient) { - this.apiClient = apiClient; - } - - /** - * Build call for createMessage - * @param body the message to add (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call createMessageCall(Message body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = body; - - // create path and map variables - String localVarPath = "/message"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "appTokenHeader", "appTokenQuery" }; - return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call createMessageValidateBeforeCall(Message body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException("Missing the required parameter 'body' when calling createMessage(Async)"); - } - - - com.squareup.okhttp.Call call = createMessageCall(body, progressListener, progressRequestListener); - return call; - - } - - /** - * Create a message. - * __NOTE__: This API ONLY accepts an application token as authentication. - * @param body the message to add (required) - * @return Message - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public Message createMessage(Message body) throws ApiException { - ApiResponse resp = createMessageWithHttpInfo(body); - return resp.getData(); - } - - /** - * Create a message. - * __NOTE__: This API ONLY accepts an application token as authentication. - * @param body the message to add (required) - * @return ApiResponse<Message> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse createMessageWithHttpInfo(Message body) throws ApiException { - com.squareup.okhttp.Call call = createMessageValidateBeforeCall(body, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Create a message. (asynchronously) - * __NOTE__: This API ONLY accepts an application token as authentication. - * @param body the message to add (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call createMessageAsync(Message body, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = createMessageValidateBeforeCall(body, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for deleteAppMessages - * @param id the application id (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call deleteAppMessagesCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/application/{id}/message" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call deleteAppMessagesValidateBeforeCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'id' is set - if (id == null) { - throw new ApiException("Missing the required parameter 'id' when calling deleteAppMessages(Async)"); - } - - - com.squareup.okhttp.Call call = deleteAppMessagesCall(id, progressListener, progressRequestListener); - return call; - - } - - /** - * Delete all messages from a specific application. - * - * @param id the application id (required) - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public void deleteAppMessages(Integer id) throws ApiException { - deleteAppMessagesWithHttpInfo(id); - } - - /** - * Delete all messages from a specific application. - * - * @param id the application id (required) - * @return ApiResponse<Void> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse deleteAppMessagesWithHttpInfo(Integer id) throws ApiException { - com.squareup.okhttp.Call call = deleteAppMessagesValidateBeforeCall(id, null, null); - return apiClient.execute(call); - } - - /** - * Delete all messages from a specific application. (asynchronously) - * - * @param id the application id (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call deleteAppMessagesAsync(Integer id, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = deleteAppMessagesValidateBeforeCall(id, progressListener, progressRequestListener); - apiClient.executeAsync(call, callback); - return call; - } - /** - * Build call for deleteMessage - * @param id the message id (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call deleteMessageCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/message/{id}" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call deleteMessageValidateBeforeCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'id' is set - if (id == null) { - throw new ApiException("Missing the required parameter 'id' when calling deleteMessage(Async)"); - } - - - com.squareup.okhttp.Call call = deleteMessageCall(id, progressListener, progressRequestListener); - return call; - - } - - /** - * Deletes a message with an id. - * - * @param id the message id (required) - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public void deleteMessage(Integer id) throws ApiException { - deleteMessageWithHttpInfo(id); - } - - /** - * Deletes a message with an id. - * - * @param id the message id (required) - * @return ApiResponse<Void> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse deleteMessageWithHttpInfo(Integer id) throws ApiException { - com.squareup.okhttp.Call call = deleteMessageValidateBeforeCall(id, null, null); - return apiClient.execute(call); - } - - /** - * Deletes a message with an id. (asynchronously) - * - * @param id the message id (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call deleteMessageAsync(Integer id, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = deleteMessageValidateBeforeCall(id, progressListener, progressRequestListener); - apiClient.executeAsync(call, callback); - return call; - } - /** - * Build call for deleteMessages - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call deleteMessagesCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/message"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call deleteMessagesValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - - com.squareup.okhttp.Call call = deleteMessagesCall(progressListener, progressRequestListener); - return call; - - } - - /** - * Delete all messages. - * - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public void deleteMessages() throws ApiException { - deleteMessagesWithHttpInfo(); - } - - /** - * Delete all messages. - * - * @return ApiResponse<Void> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse deleteMessagesWithHttpInfo() throws ApiException { - com.squareup.okhttp.Call call = deleteMessagesValidateBeforeCall(null, null); - return apiClient.execute(call); - } - - /** - * Delete all messages. (asynchronously) - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call deleteMessagesAsync(final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = deleteMessagesValidateBeforeCall(progressListener, progressRequestListener); - apiClient.executeAsync(call, callback); - return call; - } - /** - * Build call for getAppMessages - * @param id the application id (required) - * @param limit the maximal amount of messages to return (optional, default to 100) - * @param since return all messages with an ID less than this value (optional) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call getAppMessagesCall(Integer id, Integer limit, Integer since, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/application/{id}/message" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - if (limit != null) - localVarQueryParams.addAll(apiClient.parameterToPair("limit", limit)); - if (since != null) - localVarQueryParams.addAll(apiClient.parameterToPair("since", since)); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call getAppMessagesValidateBeforeCall(Integer id, Integer limit, Integer since, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'id' is set - if (id == null) { - throw new ApiException("Missing the required parameter 'id' when calling getAppMessages(Async)"); - } - - - com.squareup.okhttp.Call call = getAppMessagesCall(id, limit, since, progressListener, progressRequestListener); - return call; - - } - - /** - * Return all messages from a specific application. - * - * @param id the application id (required) - * @param limit the maximal amount of messages to return (optional, default to 100) - * @param since return all messages with an ID less than this value (optional) - * @return PagedMessages - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public PagedMessages getAppMessages(Integer id, Integer limit, Integer since) throws ApiException { - ApiResponse resp = getAppMessagesWithHttpInfo(id, limit, since); - return resp.getData(); - } - - /** - * Return all messages from a specific application. - * - * @param id the application id (required) - * @param limit the maximal amount of messages to return (optional, default to 100) - * @param since return all messages with an ID less than this value (optional) - * @return ApiResponse<PagedMessages> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse getAppMessagesWithHttpInfo(Integer id, Integer limit, Integer since) throws ApiException { - com.squareup.okhttp.Call call = getAppMessagesValidateBeforeCall(id, limit, since, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Return all messages from a specific application. (asynchronously) - * - * @param id the application id (required) - * @param limit the maximal amount of messages to return (optional, default to 100) - * @param since return all messages with an ID less than this value (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call getAppMessagesAsync(Integer id, Integer limit, Integer since, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = getAppMessagesValidateBeforeCall(id, limit, since, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for getMessages - * @param limit the maximal amount of messages to return (optional, default to 100) - * @param since return all messages with an ID less than this value (optional) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call getMessagesCall(Integer limit, Integer since, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/message"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - if (limit != null) - localVarQueryParams.addAll(apiClient.parameterToPair("limit", limit)); - if (since != null) - localVarQueryParams.addAll(apiClient.parameterToPair("since", since)); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call getMessagesValidateBeforeCall(Integer limit, Integer since, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - - com.squareup.okhttp.Call call = getMessagesCall(limit, since, progressListener, progressRequestListener); - return call; - - } - - /** - * Return all messages. - * - * @param limit the maximal amount of messages to return (optional, default to 100) - * @param since return all messages with an ID less than this value (optional) - * @return PagedMessages - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public PagedMessages getMessages(Integer limit, Integer since) throws ApiException { - ApiResponse resp = getMessagesWithHttpInfo(limit, since); - return resp.getData(); - } - - /** - * Return all messages. - * - * @param limit the maximal amount of messages to return (optional, default to 100) - * @param since return all messages with an ID less than this value (optional) - * @return ApiResponse<PagedMessages> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse getMessagesWithHttpInfo(Integer limit, Integer since) throws ApiException { - com.squareup.okhttp.Call call = getMessagesValidateBeforeCall(limit, since, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Return all messages. (asynchronously) - * - * @param limit the maximal amount of messages to return (optional, default to 100) - * @param since return all messages with an ID less than this value (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call getMessagesAsync(Integer limit, Integer since, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = getMessagesValidateBeforeCall(limit, since, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for streamMessages - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call streamMessagesCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/stream"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call streamMessagesValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - - com.squareup.okhttp.Call call = streamMessagesCall(progressListener, progressRequestListener); - return call; - - } - - /** - * Websocket, return newly created messages. - * - * @return Message - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public Message streamMessages() throws ApiException { - ApiResponse resp = streamMessagesWithHttpInfo(); - return resp.getData(); - } - - /** - * Websocket, return newly created messages. - * - * @return ApiResponse<Message> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse streamMessagesWithHttpInfo() throws ApiException { - com.squareup.okhttp.Call call = streamMessagesValidateBeforeCall(null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Websocket, return newly created messages. (asynchronously) - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call streamMessagesAsync(final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = streamMessagesValidateBeforeCall(progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } } diff --git a/client/src/main/java/com/github/gotify/client/api/TokenApi.java b/client/src/main/java/com/github/gotify/client/api/TokenApi.java index ed48fc3..144ae51 100644 --- a/client/src/main/java/com/github/gotify/client/api/TokenApi.java +++ b/client/src/main/java/com/github/gotify/client/api/TokenApi.java @@ -1,902 +1,115 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.api; -import com.github.gotify.client.ApiCallback; -import com.github.gotify.client.ApiClient; -import com.github.gotify.client.ApiException; -import com.github.gotify.client.ApiResponse; -import com.github.gotify.client.Configuration; -import com.github.gotify.client.Pair; -import com.github.gotify.client.ProgressRequestBody; -import com.github.gotify.client.ProgressResponseBody; +import com.github.gotify.client.CollectionFormats.*; -import com.google.gson.reflect.TypeToken; - -import java.io.IOException; +import retrofit2.Call; +import retrofit2.http.*; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; import com.github.gotify.client.model.Application; import com.github.gotify.client.model.Client; import com.github.gotify.client.model.Error; import java.io.File; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -public class TokenApi { - private ApiClient apiClient; +public interface TokenApi { + /** + * Create an application. + * + * @param body the application to add (required) + * @return Call<Application> + */ + @Headers({ + "Content-Type:application/json" + }) + @POST("application") + Call createApp( + @retrofit2.http.Body Application body + ); + + /** + * Create a client. + * + * @param body the client to add (required) + * @return Call<Client> + */ + @Headers({ + "Content-Type:application/json" + }) + @POST("client") + Call createClient( + @retrofit2.http.Body Client body + ); + + /** + * Delete an application. + * + * @param id the application id (required) + * @return Call<Void> + */ + @Headers({ + "Content-Type:application/json" + }) + @DELETE("application/{id}") + Call deleteApp( + @retrofit2.http.Path("id") Integer id + ); + + /** + * Delete a client. + * + * @param id the client id (required) + * @return Call<Void> + */ + @Headers({ + "Content-Type:application/json" + }) + @DELETE("client/{id}") + Call deleteClient( + @retrofit2.http.Path("id") Integer id + ); + + /** + * Return all applications. + * + * @return Call<List<Application>> + */ + @Headers({ + "Content-Type:application/json" + }) + @GET("application") + Call> getApps(); + + + /** + * Return all clients. + * + * @return Call<List<Client>> + */ + @Headers({ + "Content-Type:application/json" + }) + @GET("client") + Call> getClients(); + + + /** + * + * Upload an image for an application + * @param file the application image (required) + * @param id the application id (required) + * @return Call<Application> + */ + @retrofit2.http.Multipart + @POST("application/{id}/image") + Call uploadAppImage( + @retrofit2.http.Part("file\"; filename=\"file") RequestBody file, @retrofit2.http.Path("id") Integer id + ); - public TokenApi() { - this(Configuration.getDefaultApiClient()); - } - - public TokenApi(ApiClient apiClient) { - this.apiClient = apiClient; - } - - public ApiClient getApiClient() { - return apiClient; - } - - public void setApiClient(ApiClient apiClient) { - this.apiClient = apiClient; - } - - /** - * Build call for createApp - * @param body the application to add (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call createAppCall(Application body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = body; - - // create path and map variables - String localVarPath = "/application"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call createAppValidateBeforeCall(Application body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException("Missing the required parameter 'body' when calling createApp(Async)"); - } - - - com.squareup.okhttp.Call call = createAppCall(body, progressListener, progressRequestListener); - return call; - - } - - /** - * Create an application. - * - * @param body the application to add (required) - * @return Application - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public Application createApp(Application body) throws ApiException { - ApiResponse resp = createAppWithHttpInfo(body); - return resp.getData(); - } - - /** - * Create an application. - * - * @param body the application to add (required) - * @return ApiResponse<Application> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse createAppWithHttpInfo(Application body) throws ApiException { - com.squareup.okhttp.Call call = createAppValidateBeforeCall(body, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Create an application. (asynchronously) - * - * @param body the application to add (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call createAppAsync(Application body, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = createAppValidateBeforeCall(body, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for createClient - * @param body the client to add (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call createClientCall(Client body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = body; - - // create path and map variables - String localVarPath = "/client"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call createClientValidateBeforeCall(Client body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException("Missing the required parameter 'body' when calling createClient(Async)"); - } - - - com.squareup.okhttp.Call call = createClientCall(body, progressListener, progressRequestListener); - return call; - - } - - /** - * Create a client. - * - * @param body the client to add (required) - * @return Client - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public Client createClient(Client body) throws ApiException { - ApiResponse resp = createClientWithHttpInfo(body); - return resp.getData(); - } - - /** - * Create a client. - * - * @param body the client to add (required) - * @return ApiResponse<Client> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse createClientWithHttpInfo(Client body) throws ApiException { - com.squareup.okhttp.Call call = createClientValidateBeforeCall(body, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Create a client. (asynchronously) - * - * @param body the client to add (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call createClientAsync(Client body, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = createClientValidateBeforeCall(body, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for deleteApp - * @param id the application id (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call deleteAppCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/application/{id}" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call deleteAppValidateBeforeCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'id' is set - if (id == null) { - throw new ApiException("Missing the required parameter 'id' when calling deleteApp(Async)"); - } - - - com.squareup.okhttp.Call call = deleteAppCall(id, progressListener, progressRequestListener); - return call; - - } - - /** - * Delete an application. - * - * @param id the application id (required) - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public void deleteApp(Integer id) throws ApiException { - deleteAppWithHttpInfo(id); - } - - /** - * Delete an application. - * - * @param id the application id (required) - * @return ApiResponse<Void> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse deleteAppWithHttpInfo(Integer id) throws ApiException { - com.squareup.okhttp.Call call = deleteAppValidateBeforeCall(id, null, null); - return apiClient.execute(call); - } - - /** - * Delete an application. (asynchronously) - * - * @param id the application id (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call deleteAppAsync(Integer id, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = deleteAppValidateBeforeCall(id, progressListener, progressRequestListener); - apiClient.executeAsync(call, callback); - return call; - } - /** - * Build call for deleteClient - * @param id the client id (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call deleteClientCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/client/{id}" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call deleteClientValidateBeforeCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'id' is set - if (id == null) { - throw new ApiException("Missing the required parameter 'id' when calling deleteClient(Async)"); - } - - - com.squareup.okhttp.Call call = deleteClientCall(id, progressListener, progressRequestListener); - return call; - - } - - /** - * Delete a client. - * - * @param id the client id (required) - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public void deleteClient(Integer id) throws ApiException { - deleteClientWithHttpInfo(id); - } - - /** - * Delete a client. - * - * @param id the client id (required) - * @return ApiResponse<Void> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse deleteClientWithHttpInfo(Integer id) throws ApiException { - com.squareup.okhttp.Call call = deleteClientValidateBeforeCall(id, null, null); - return apiClient.execute(call); - } - - /** - * Delete a client. (asynchronously) - * - * @param id the client id (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call deleteClientAsync(Integer id, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = deleteClientValidateBeforeCall(id, progressListener, progressRequestListener); - apiClient.executeAsync(call, callback); - return call; - } - /** - * Build call for getApps - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call getAppsCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/application"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call getAppsValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - - com.squareup.okhttp.Call call = getAppsCall(progressListener, progressRequestListener); - return call; - - } - - /** - * Return all applications. - * - * @return List<Application> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public List getApps() throws ApiException { - ApiResponse> resp = getAppsWithHttpInfo(); - return resp.getData(); - } - - /** - * Return all applications. - * - * @return ApiResponse<List<Application>> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse> getAppsWithHttpInfo() throws ApiException { - com.squareup.okhttp.Call call = getAppsValidateBeforeCall(null, null); - Type localVarReturnType = new TypeToken>(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Return all applications. (asynchronously) - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call getAppsAsync(final ApiCallback> callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = getAppsValidateBeforeCall(progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken>(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for getClients - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call getClientsCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/client"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call getClientsValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - - com.squareup.okhttp.Call call = getClientsCall(progressListener, progressRequestListener); - return call; - - } - - /** - * Return all clients. - * - * @return List<Client> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public List getClients() throws ApiException { - ApiResponse> resp = getClientsWithHttpInfo(); - return resp.getData(); - } - - /** - * Return all clients. - * - * @return ApiResponse<List<Client>> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse> getClientsWithHttpInfo() throws ApiException { - com.squareup.okhttp.Call call = getClientsValidateBeforeCall(null, null); - Type localVarReturnType = new TypeToken>(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Return all clients. (asynchronously) - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call getClientsAsync(final ApiCallback> callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = getClientsValidateBeforeCall(progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken>(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for uploadAppImage - * @param file the application image (required) - * @param id the application id (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call uploadAppImageCall(File file, Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/application/{id}/image" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - if (file != null) - localVarFormParams.put("file", file); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "multipart/form-data" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call uploadAppImageValidateBeforeCall(File file, Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'file' is set - if (file == null) { - throw new ApiException("Missing the required parameter 'file' when calling uploadAppImage(Async)"); - } - - // verify the required parameter 'id' is set - if (id == null) { - throw new ApiException("Missing the required parameter 'id' when calling uploadAppImage(Async)"); - } - - - com.squareup.okhttp.Call call = uploadAppImageCall(file, id, progressListener, progressRequestListener); - return call; - - } - - /** - * - * Upload an image for an application - * @param file the application image (required) - * @param id the application id (required) - * @return Application - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public Application uploadAppImage(File file, Integer id) throws ApiException { - ApiResponse resp = uploadAppImageWithHttpInfo(file, id); - return resp.getData(); - } - - /** - * - * Upload an image for an application - * @param file the application image (required) - * @param id the application id (required) - * @return ApiResponse<Application> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse uploadAppImageWithHttpInfo(File file, Integer id) throws ApiException { - com.squareup.okhttp.Call call = uploadAppImageValidateBeforeCall(file, id, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * (asynchronously) - * Upload an image for an application - * @param file the application image (required) - * @param id the application id (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call uploadAppImageAsync(File file, Integer id, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = uploadAppImageValidateBeforeCall(file, id, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } } diff --git a/client/src/main/java/com/github/gotify/client/api/UserApi.java b/client/src/main/java/com/github/gotify/client/api/UserApi.java index 9b2355e..cd598f4 100644 --- a/client/src/main/java/com/github/gotify/client/api/UserApi.java +++ b/client/src/main/java/com/github/gotify/client/api/UserApi.java @@ -1,900 +1,117 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.api; -import com.github.gotify.client.ApiCallback; -import com.github.gotify.client.ApiClient; -import com.github.gotify.client.ApiException; -import com.github.gotify.client.ApiResponse; -import com.github.gotify.client.Configuration; -import com.github.gotify.client.Pair; -import com.github.gotify.client.ProgressRequestBody; -import com.github.gotify.client.ProgressResponseBody; +import com.github.gotify.client.CollectionFormats.*; -import com.google.gson.reflect.TypeToken; - -import java.io.IOException; +import retrofit2.Call; +import retrofit2.http.*; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; import com.github.gotify.client.model.Error; import com.github.gotify.client.model.User; import com.github.gotify.client.model.UserPass; import com.github.gotify.client.model.UserWithPass; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -public class UserApi { - private ApiClient apiClient; +public interface UserApi { + /** + * Create a user. + * + * @param body the user to add (required) + * @return Call<User> + */ + @Headers({ + "Content-Type:application/json" + }) + @POST("user") + Call createUser( + @retrofit2.http.Body UserWithPass body + ); + + /** + * Return the current user. + * + * @return Call<User> + */ + @Headers({ + "Content-Type:application/json" + }) + @GET("current/user") + Call currentUser(); + + + /** + * Deletes a user. + * + * @param id the user id (required) + * @return Call<Void> + */ + @Headers({ + "Content-Type:application/json" + }) + @DELETE("user/{id}") + Call deleteUser( + @retrofit2.http.Path("id") Integer id + ); + + /** + * Get a user. + * + * @param id the user id (required) + * @return Call<User> + */ + @Headers({ + "Content-Type:application/json" + }) + @GET("user/{id}") + Call getUser( + @retrofit2.http.Path("id") Integer id + ); + + /** + * Return all users. + * + * @return Call<List<User>> + */ + @Headers({ + "Content-Type:application/json" + }) + @GET("user") + Call> getUsers(); + + + /** + * Update the password of the current user. + * + * @param body the user (required) + * @return Call<Void> + */ + @Headers({ + "Content-Type:application/json" + }) + @POST("current/user/password") + Call updateCurrentUser( + @retrofit2.http.Body UserPass body + ); + + /** + * Update a user. + * + * @param id the user id (required) + * @param body the updated user (required) + * @return Call<User> + */ + @Headers({ + "Content-Type:application/json" + }) + @POST("user/{id}") + Call updateUser( + @retrofit2.http.Path("id") Integer id, @retrofit2.http.Body UserWithPass body + ); - public UserApi() { - this(Configuration.getDefaultApiClient()); - } - - public UserApi(ApiClient apiClient) { - this.apiClient = apiClient; - } - - public ApiClient getApiClient() { - return apiClient; - } - - public void setApiClient(ApiClient apiClient) { - this.apiClient = apiClient; - } - - /** - * Build call for createUser - * @param body the user to add (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call createUserCall(UserWithPass body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = body; - - // create path and map variables - String localVarPath = "/user"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call createUserValidateBeforeCall(UserWithPass body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException("Missing the required parameter 'body' when calling createUser(Async)"); - } - - - com.squareup.okhttp.Call call = createUserCall(body, progressListener, progressRequestListener); - return call; - - } - - /** - * Create a user. - * - * @param body the user to add (required) - * @return User - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public User createUser(UserWithPass body) throws ApiException { - ApiResponse resp = createUserWithHttpInfo(body); - return resp.getData(); - } - - /** - * Create a user. - * - * @param body the user to add (required) - * @return ApiResponse<User> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse createUserWithHttpInfo(UserWithPass body) throws ApiException { - com.squareup.okhttp.Call call = createUserValidateBeforeCall(body, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Create a user. (asynchronously) - * - * @param body the user to add (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call createUserAsync(UserWithPass body, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = createUserValidateBeforeCall(body, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for currentUser - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call currentUserCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/current/user"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call currentUserValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - - com.squareup.okhttp.Call call = currentUserCall(progressListener, progressRequestListener); - return call; - - } - - /** - * Return the current user. - * - * @return User - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public User currentUser() throws ApiException { - ApiResponse resp = currentUserWithHttpInfo(); - return resp.getData(); - } - - /** - * Return the current user. - * - * @return ApiResponse<User> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse currentUserWithHttpInfo() throws ApiException { - com.squareup.okhttp.Call call = currentUserValidateBeforeCall(null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Return the current user. (asynchronously) - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call currentUserAsync(final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = currentUserValidateBeforeCall(progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for deleteUser - * @param id the user id (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call deleteUserCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/user/{id}" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call deleteUserValidateBeforeCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'id' is set - if (id == null) { - throw new ApiException("Missing the required parameter 'id' when calling deleteUser(Async)"); - } - - - com.squareup.okhttp.Call call = deleteUserCall(id, progressListener, progressRequestListener); - return call; - - } - - /** - * Deletes a user. - * - * @param id the user id (required) - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public void deleteUser(Integer id) throws ApiException { - deleteUserWithHttpInfo(id); - } - - /** - * Deletes a user. - * - * @param id the user id (required) - * @return ApiResponse<Void> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse deleteUserWithHttpInfo(Integer id) throws ApiException { - com.squareup.okhttp.Call call = deleteUserValidateBeforeCall(id, null, null); - return apiClient.execute(call); - } - - /** - * Deletes a user. (asynchronously) - * - * @param id the user id (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call deleteUserAsync(Integer id, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = deleteUserValidateBeforeCall(id, progressListener, progressRequestListener); - apiClient.executeAsync(call, callback); - return call; - } - /** - * Build call for getUser - * @param id the user id (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call getUserCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/user/{id}" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call getUserValidateBeforeCall(Integer id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'id' is set - if (id == null) { - throw new ApiException("Missing the required parameter 'id' when calling getUser(Async)"); - } - - - com.squareup.okhttp.Call call = getUserCall(id, progressListener, progressRequestListener); - return call; - - } - - /** - * Get a user. - * - * @param id the user id (required) - * @return User - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public User getUser(Integer id) throws ApiException { - ApiResponse resp = getUserWithHttpInfo(id); - return resp.getData(); - } - - /** - * Get a user. - * - * @param id the user id (required) - * @return ApiResponse<User> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse getUserWithHttpInfo(Integer id) throws ApiException { - com.squareup.okhttp.Call call = getUserValidateBeforeCall(id, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Get a user. (asynchronously) - * - * @param id the user id (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call getUserAsync(Integer id, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = getUserValidateBeforeCall(id, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for getUsers - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call getUsersCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/user"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call getUsersValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - - com.squareup.okhttp.Call call = getUsersCall(progressListener, progressRequestListener); - return call; - - } - - /** - * Return all users. - * - * @return List<User> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public List getUsers() throws ApiException { - ApiResponse> resp = getUsersWithHttpInfo(); - return resp.getData(); - } - - /** - * Return all users. - * - * @return ApiResponse<List<User>> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse> getUsersWithHttpInfo() throws ApiException { - com.squareup.okhttp.Call call = getUsersValidateBeforeCall(null, null); - Type localVarReturnType = new TypeToken>(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Return all users. (asynchronously) - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call getUsersAsync(final ApiCallback> callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = getUsersValidateBeforeCall(progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken>(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } - /** - * Build call for updateCurrentUser - * @param body the user (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call updateCurrentUserCall(UserPass body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = body; - - // create path and map variables - String localVarPath = "/current/user/password"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call updateCurrentUserValidateBeforeCall(UserPass body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException("Missing the required parameter 'body' when calling updateCurrentUser(Async)"); - } - - - com.squareup.okhttp.Call call = updateCurrentUserCall(body, progressListener, progressRequestListener); - return call; - - } - - /** - * Update the password of the current user. - * - * @param body the user (required) - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public void updateCurrentUser(UserPass body) throws ApiException { - updateCurrentUserWithHttpInfo(body); - } - - /** - * Update the password of the current user. - * - * @param body the user (required) - * @return ApiResponse<Void> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse updateCurrentUserWithHttpInfo(UserPass body) throws ApiException { - com.squareup.okhttp.Call call = updateCurrentUserValidateBeforeCall(body, null, null); - return apiClient.execute(call); - } - - /** - * Update the password of the current user. (asynchronously) - * - * @param body the user (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call updateCurrentUserAsync(UserPass body, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = updateCurrentUserValidateBeforeCall(body, progressListener, progressRequestListener); - apiClient.executeAsync(call, callback); - return call; - } - /** - * Build call for updateUser - * @param id the user id (required) - * @param body the updated user (required) - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call updateUserCall(Integer id, UserWithPass body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = body; - - // create path and map variables - String localVarPath = "/user/{id}" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { "basicAuth", "clientTokenHeader", "clientTokenQuery" }; - return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call updateUserValidateBeforeCall(Integer id, UserWithPass body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - // verify the required parameter 'id' is set - if (id == null) { - throw new ApiException("Missing the required parameter 'id' when calling updateUser(Async)"); - } - - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException("Missing the required parameter 'body' when calling updateUser(Async)"); - } - - - com.squareup.okhttp.Call call = updateUserCall(id, body, progressListener, progressRequestListener); - return call; - - } - - /** - * Update a user. - * - * @param id the user id (required) - * @param body the updated user (required) - * @return User - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public User updateUser(Integer id, UserWithPass body) throws ApiException { - ApiResponse resp = updateUserWithHttpInfo(id, body); - return resp.getData(); - } - - /** - * Update a user. - * - * @param id the user id (required) - * @param body the updated user (required) - * @return ApiResponse<User> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse updateUserWithHttpInfo(Integer id, UserWithPass body) throws ApiException { - com.squareup.okhttp.Call call = updateUserValidateBeforeCall(id, body, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Update a user. (asynchronously) - * - * @param id the user id (required) - * @param body the updated user (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call updateUserAsync(Integer id, UserWithPass body, final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = updateUserValidateBeforeCall(id, body, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } } diff --git a/client/src/main/java/com/github/gotify/client/api/VersionApi.java b/client/src/main/java/com/github/gotify/client/api/VersionApi.java index 22a5424..3c9d63e 100644 --- a/client/src/main/java/com/github/gotify/client/api/VersionApi.java +++ b/client/src/main/java/com/github/gotify/client/api/VersionApi.java @@ -1,170 +1,31 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.api; -import com.github.gotify.client.ApiCallback; -import com.github.gotify.client.ApiClient; -import com.github.gotify.client.ApiException; -import com.github.gotify.client.ApiResponse; -import com.github.gotify.client.Configuration; -import com.github.gotify.client.Pair; -import com.github.gotify.client.ProgressRequestBody; -import com.github.gotify.client.ProgressResponseBody; +import com.github.gotify.client.CollectionFormats.*; -import com.google.gson.reflect.TypeToken; - -import java.io.IOException; +import retrofit2.Call; +import retrofit2.http.*; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; import com.github.gotify.client.model.VersionInfo; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -public class VersionApi { - private ApiClient apiClient; +public interface VersionApi { + /** + * Get version information. + * + * @return Call<VersionInfo> + */ + @Headers({ + "Content-Type:application/json" + }) + @GET("version") + Call getVersion(); + - public VersionApi() { - this(Configuration.getDefaultApiClient()); - } - - public VersionApi(ApiClient apiClient) { - this.apiClient = apiClient; - } - - public ApiClient getApiClient() { - return apiClient; - } - - public void setApiClient(ApiClient apiClient) { - this.apiClient = apiClient; - } - - /** - * Build call for getVersion - * @param progressListener Progress listener - * @param progressRequestListener Progress request listener - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public com.squareup.okhttp.Call getVersionCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - // create path and map variables - String localVarPath = "/version"; - - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - - Map localVarHeaderParams = new HashMap(); - - Map localVarFormParams = new HashMap(); - - final String[] localVarAccepts = { - "application/json" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/json" - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - - if(progressListener != null) { - apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { - @Override - public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { - com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), progressListener)) - .build(); - } - }); - } - - String[] localVarAuthNames = new String[] { }; - return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call getVersionValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - - - com.squareup.okhttp.Call call = getVersionCall(progressListener, progressRequestListener); - return call; - - } - - /** - * Get version information. - * - * @return VersionInfo - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public VersionInfo getVersion() throws ApiException { - ApiResponse resp = getVersionWithHttpInfo(); - return resp.getData(); - } - - /** - * Get version information. - * - * @return ApiResponse<VersionInfo> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse getVersionWithHttpInfo() throws ApiException { - com.squareup.okhttp.Call call = getVersionValidateBeforeCall(null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Get version information. (asynchronously) - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws ApiException If fail to process the API call, e.g. serializing the request body object - */ - public com.squareup.okhttp.Call getVersionAsync(final ApiCallback callback) throws ApiException { - - ProgressResponseBody.ProgressListener progressListener = null; - ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - - if (callback != null) { - progressListener = new ProgressResponseBody.ProgressListener() { - @Override - public void update(long bytesRead, long contentLength, boolean done) { - callback.onDownloadProgress(bytesRead, contentLength, done); - } - }; - - progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { - @Override - public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { - callback.onUploadProgress(bytesWritten, contentLength, done); - } - }; - } - - com.squareup.okhttp.Call call = getVersionValidateBeforeCall(progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } } diff --git a/client/src/main/java/com/github/gotify/client/auth/ApiKeyAuth.java b/client/src/main/java/com/github/gotify/client/auth/ApiKeyAuth.java index 5121aa5..82cbd77 100644 --- a/client/src/main/java/com/github/gotify/client/auth/ApiKeyAuth.java +++ b/client/src/main/java/com/github/gotify/client/auth/ApiKeyAuth.java @@ -1,75 +1,68 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.auth; -import com.github.gotify.client.Pair; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; -import java.util.Map; -import java.util.List; +import okhttp3.Interceptor; +import okhttp3.Request; +import okhttp3.Response; -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") -public class ApiKeyAuth implements Authentication { - private final String location; - private final String paramName; +public class ApiKeyAuth implements Interceptor { + private final String location; + private final String paramName; - private String apiKey; - private String apiKeyPrefix; + private String apiKey; - public ApiKeyAuth(String location, String paramName) { - this.location = location; - this.paramName = paramName; - } - - public String getLocation() { - return location; - } - - public String getParamName() { - return paramName; - } - - public String getApiKey() { - return apiKey; - } - - public void setApiKey(String apiKey) { - this.apiKey = apiKey; - } - - public String getApiKeyPrefix() { - return apiKeyPrefix; - } - - public void setApiKeyPrefix(String apiKeyPrefix) { - this.apiKeyPrefix = apiKeyPrefix; - } - - @Override - public void applyToParams(List queryParams, Map headerParams) { - if (apiKey == null) { - return; + public ApiKeyAuth(String location, String paramName) { + this.location = location; + this.paramName = paramName; } - String value; - if (apiKeyPrefix != null) { - value = apiKeyPrefix + " " + apiKey; - } else { - value = apiKey; + + public String getLocation() { + return location; } - if ("query".equals(location)) { - queryParams.add(new Pair(paramName, value)); - } else if ("header".equals(location)) { - headerParams.put(paramName, value); + + public String getParamName() { + return paramName; + } + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + + @Override + public Response intercept(Chain chain) throws IOException { + String paramValue; + Request request = chain.request(); + + if ("query".equals(location)) { + String newQuery = request.url().uri().getQuery(); + paramValue = paramName + "=" + apiKey; + if (newQuery == null) { + newQuery = paramValue; + } else { + newQuery += "&" + paramValue; + } + + URI newUri; + try { + newUri = new URI(request.url().uri().getScheme(), request.url().uri().getAuthority(), + request.url().uri().getPath(), newQuery, request.url().uri().getFragment()); + } catch (URISyntaxException e) { + throw new IOException(e); + } + + request = request.newBuilder().url(newUri.toURL()).build(); + } else if ("header".equals(location)) { + request = request.newBuilder() + .addHeader(paramName, apiKey) + .build(); + } + return chain.proceed(request); } - } } diff --git a/client/src/main/java/com/github/gotify/client/auth/Authentication.java b/client/src/main/java/com/github/gotify/client/auth/Authentication.java deleted file mode 100644 index d19a8ca..0000000 --- a/client/src/main/java/com/github/gotify/client/auth/Authentication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package com.github.gotify.client.auth; - -import com.github.gotify.client.Pair; - -import java.util.Map; -import java.util.List; - -public interface Authentication { - /** - * Apply authentication settings to header and query params. - * - * @param queryParams List of query parameters - * @param headerParams Map of header parameters - */ - void applyToParams(List queryParams, Map headerParams); -} diff --git a/client/src/main/java/com/github/gotify/client/auth/HttpBasicAuth.java b/client/src/main/java/com/github/gotify/client/auth/HttpBasicAuth.java index 6428f30..8b78edd 100644 --- a/client/src/main/java/com/github/gotify/client/auth/HttpBasicAuth.java +++ b/client/src/main/java/com/github/gotify/client/auth/HttpBasicAuth.java @@ -1,31 +1,18 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.auth; -import com.github.gotify.client.Pair; +import java.io.IOException; -import com.squareup.okhttp.Credentials; +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.Credentials; -import java.util.Map; -import java.util.List; +public class HttpBasicAuth implements Interceptor { -import java.io.UnsupportedEncodingException; - -public class HttpBasicAuth implements Authentication { private String username; private String password; - + public String getUsername() { return username; } @@ -42,13 +29,22 @@ public class HttpBasicAuth implements Authentication { this.password = password; } + public void setCredentials(String username, String password) { + this.username = username; + this.password = password; + } + @Override - public void applyToParams(List queryParams, Map headerParams) { - if (username == null && password == null) { - return; + public Response intercept(Chain chain) throws IOException { + Request request = chain.request(); + + // If the request already have an authorization (eg. Basic auth), do nothing + if (request.header("Authorization") == null) { + String credentials = Credentials.basic(username, password); + request = request.newBuilder() + .addHeader("Authorization", credentials) + .build(); } - headerParams.put("Authorization", Credentials.basic( - username == null ? "" : username, - password == null ? "" : password)); + return chain.proceed(request); } } diff --git a/client/src/main/java/com/github/gotify/client/auth/OAuth.java b/client/src/main/java/com/github/gotify/client/auth/OAuth.java index 22e380c..1b95924 100644 --- a/client/src/main/java/com/github/gotify/client/auth/OAuth.java +++ b/client/src/main/java/com/github/gotify/client/auth/OAuth.java @@ -1,39 +1,179 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.auth; -import com.github.gotify.client.Pair; +import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; +import static java.net.HttpURLConnection.HTTP_FORBIDDEN; +import java.io.IOException; import java.util.Map; -import java.util.List; -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") -public class OAuth implements Authentication { - private String accessToken; +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; +import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.common.token.BasicOAuthToken; - public String getAccessToken() { - return accessToken; - } +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Request.Builder; +import okhttp3.Response; - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } +public class OAuth implements Interceptor { - @Override - public void applyToParams(List queryParams, Map headerParams) { - if (accessToken != null) { - headerParams.put("Authorization", "Bearer " + accessToken); + public interface AccessTokenListener { + public void notify(BasicOAuthToken token); } - } + + private volatile String accessToken; + private OAuthClient oauthClient; + + private TokenRequestBuilder tokenRequestBuilder; + private AuthenticationRequestBuilder authenticationRequestBuilder; + + private AccessTokenListener accessTokenListener; + + public OAuth( OkHttpClient client, TokenRequestBuilder requestBuilder ) { + this.oauthClient = new OAuthClient(new OAuthOkHttpClient(client)); + this.tokenRequestBuilder = requestBuilder; + } + + public OAuth(TokenRequestBuilder requestBuilder ) { + this(new OkHttpClient(), requestBuilder); + } + + public OAuth(OAuthFlow flow, String authorizationUrl, String tokenUrl, String scopes) { + this(OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes)); + setFlow(flow); + authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl); + } + + public void setFlow(OAuthFlow flow) { + switch(flow) { + case accessCode: + case implicit: + tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE); + break; + case password: + tokenRequestBuilder.setGrantType(GrantType.PASSWORD); + break; + case application: + tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS); + break; + default: + break; + } + } + + @Override + public Response intercept(Chain chain) + throws IOException { + + return retryingIntercept(chain, true); + } + + private Response retryingIntercept(Chain chain, boolean updateTokenAndRetryOnAuthorizationFailure) throws IOException { + Request request = chain.request(); + + // If the request already have an authorization (eg. Basic auth), do nothing + if (request.header("Authorization") != null) { + return chain.proceed(request); + } + + // If first time, get the token + OAuthClientRequest oAuthRequest; + if (getAccessToken() == null) { + updateAccessToken(null); + } + + if (getAccessToken() != null) { + // Build the request + Builder rb = request.newBuilder(); + + String requestAccessToken = new String(getAccessToken()); + try { + oAuthRequest = new OAuthBearerClientRequest(request.url().toString()) + .setAccessToken(requestAccessToken) + .buildHeaderMessage(); + } catch (OAuthSystemException e) { + throw new IOException(e); + } + + for ( Map.Entry header : oAuthRequest.getHeaders().entrySet() ) { + rb.addHeader(header.getKey(), header.getValue()); + } + rb.url( oAuthRequest.getLocationUri()); + + //Execute the request + Response response = chain.proceed(rb.build()); + + // 401/403 most likely indicates that access token has expired. Unless it happens two times in a row. + if ( response != null && (response.code() == HTTP_UNAUTHORIZED || response.code() == HTTP_FORBIDDEN) && updateTokenAndRetryOnAuthorizationFailure ) { + if (updateAccessToken(requestAccessToken)) { + return retryingIntercept( chain, false ); + } + } + return response; + } else { + return chain.proceed(chain.request()); + } + } + + /* + * Returns true if the access token has been updated + */ + public synchronized boolean updateAccessToken(String requestAccessToken) throws IOException { + if (getAccessToken() == null || getAccessToken().equals(requestAccessToken)) { + try { + OAuthJSONAccessTokenResponse accessTokenResponse = oauthClient.accessToken(this.tokenRequestBuilder.buildBodyMessage()); + if (accessTokenResponse != null && accessTokenResponse.getAccessToken() != null) { + setAccessToken(accessTokenResponse.getAccessToken()); + if (accessTokenListener != null) { + accessTokenListener.notify((BasicOAuthToken) accessTokenResponse.getOAuthToken()); + } + return !getAccessToken().equals(requestAccessToken); + } else { + return false; + } + } catch (OAuthSystemException e) { + throw new IOException(e); + } catch (OAuthProblemException e) { + throw new IOException(e); + } + } + return true; + } + + public void registerAccessTokenListener(AccessTokenListener accessTokenListener) { + this.accessTokenListener = accessTokenListener; + } + + public synchronized String getAccessToken() { + return accessToken; + } + + public synchronized void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public TokenRequestBuilder getTokenRequestBuilder() { + return tokenRequestBuilder; + } + + public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) { + this.tokenRequestBuilder = tokenRequestBuilder; + } + + public AuthenticationRequestBuilder getAuthenticationRequestBuilder() { + return authenticationRequestBuilder; + } + + public void setAuthenticationRequestBuilder(AuthenticationRequestBuilder authenticationRequestBuilder) { + this.authenticationRequestBuilder = authenticationRequestBuilder; + } + } diff --git a/client/src/main/java/com/github/gotify/client/auth/OAuthOkHttpClient.java b/client/src/main/java/com/github/gotify/client/auth/OAuthOkHttpClient.java new file mode 100644 index 0000000..48c7496 --- /dev/null +++ b/client/src/main/java/com/github/gotify/client/auth/OAuthOkHttpClient.java @@ -0,0 +1,72 @@ +package com.github.gotify.client.auth; + +import java.io.IOException; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.oltu.oauth2.client.HttpClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; + + +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Request.Builder; +import okhttp3.Response; +import okhttp3.MediaType; +import okhttp3.RequestBody; + + +public class OAuthOkHttpClient implements HttpClient { + + private OkHttpClient client; + + public OAuthOkHttpClient() { + this.client = new OkHttpClient(); + } + + public OAuthOkHttpClient(OkHttpClient client) { + this.client = client; + } + + public T execute(OAuthClientRequest request, Map headers, + String requestMethod, Class responseClass) + throws OAuthSystemException, OAuthProblemException { + + MediaType mediaType = MediaType.parse("application/json"); + Request.Builder requestBuilder = new Request.Builder().url(request.getLocationUri()); + + if(headers != null) { + for (Entry entry : headers.entrySet()) { + if (entry.getKey().equalsIgnoreCase("Content-Type")) { + mediaType = MediaType.parse(entry.getValue()); + } else { + requestBuilder.addHeader(entry.getKey(), entry.getValue()); + } + } + } + + RequestBody body = request.getBody() != null ? RequestBody.create(mediaType, request.getBody()) : null; + requestBuilder.method(requestMethod, body); + + try { + Response response = client.newCall(requestBuilder.build()).execute(); + return OAuthClientResponseFactory.createCustomResponse( + response.body().string(), + response.body().contentType().toString(), + response.code(), + responseClass); + } catch (IOException e) { + throw new OAuthSystemException(e); + } + } + + public void shutdown() { + // Nothing to do here + } + +} diff --git a/client/src/main/java/com/github/gotify/client/model/Application.java b/client/src/main/java/com/github/gotify/client/model/Application.java index 02ba785..a52535a 100644 --- a/client/src/main/java/com/github/gotify/client/model/Application.java +++ b/client/src/main/java/com/github/gotify/client/model/Application.java @@ -27,7 +27,7 @@ import java.io.IOException; * The Application holds information about an app which can send notifications. */ @ApiModel(description = "The Application holds information about an app which can send notifications.") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class Application { @SerializedName("description") private String description = null; diff --git a/client/src/main/java/com/github/gotify/client/model/Client.java b/client/src/main/java/com/github/gotify/client/model/Client.java index 5c15149..b4753fc 100644 --- a/client/src/main/java/com/github/gotify/client/model/Client.java +++ b/client/src/main/java/com/github/gotify/client/model/Client.java @@ -27,7 +27,7 @@ import java.io.IOException; * The Client holds information about a device which can receive notifications (and other stuff). */ @ApiModel(description = "The Client holds information about a device which can receive notifications (and other stuff).") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class Client { @SerializedName("id") private Integer id = null; diff --git a/client/src/main/java/com/github/gotify/client/model/Error.java b/client/src/main/java/com/github/gotify/client/model/Error.java index 4a12c1c..28cc7d0 100644 --- a/client/src/main/java/com/github/gotify/client/model/Error.java +++ b/client/src/main/java/com/github/gotify/client/model/Error.java @@ -27,7 +27,7 @@ import java.io.IOException; * The Error contains error relevant information. */ @ApiModel(description = "The Error contains error relevant information.") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class Error { @SerializedName("error") private String error = null; diff --git a/client/src/main/java/com/github/gotify/client/model/Message.java b/client/src/main/java/com/github/gotify/client/model/Message.java index d68380e..576795b 100644 --- a/client/src/main/java/com/github/gotify/client/model/Message.java +++ b/client/src/main/java/com/github/gotify/client/model/Message.java @@ -28,7 +28,7 @@ import org.threeten.bp.OffsetDateTime; * The Message holds information about a message which was sent by an Application. */ @ApiModel(description = "The Message holds information about a message which was sent by an Application.") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class Message { @SerializedName("appid") private Integer appid = null; diff --git a/client/src/main/java/com/github/gotify/client/model/PagedMessages.java b/client/src/main/java/com/github/gotify/client/model/PagedMessages.java index bb176d9..2c3d148 100644 --- a/client/src/main/java/com/github/gotify/client/model/PagedMessages.java +++ b/client/src/main/java/com/github/gotify/client/model/PagedMessages.java @@ -31,7 +31,7 @@ import java.util.List; * Wrapper for the paging and the messages */ @ApiModel(description = "Wrapper for the paging and the messages") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class PagedMessages { @SerializedName("messages") private List messages = new ArrayList(); diff --git a/client/src/main/java/com/github/gotify/client/model/Paging.java b/client/src/main/java/com/github/gotify/client/model/Paging.java index 0bbdbd4..69241f3 100644 --- a/client/src/main/java/com/github/gotify/client/model/Paging.java +++ b/client/src/main/java/com/github/gotify/client/model/Paging.java @@ -27,7 +27,7 @@ import java.io.IOException; * The Paging holds holds information about the limit and making requests to the next page. */ @ApiModel(description = "The Paging holds holds information about the limit and making requests to the next page.") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class Paging { @SerializedName("limit") private Long limit = null; diff --git a/client/src/main/java/com/github/gotify/client/model/User.java b/client/src/main/java/com/github/gotify/client/model/User.java index 751e458..1539e02 100644 --- a/client/src/main/java/com/github/gotify/client/model/User.java +++ b/client/src/main/java/com/github/gotify/client/model/User.java @@ -27,7 +27,7 @@ import java.io.IOException; * The User holds information about permission and other stuff. */ @ApiModel(description = "The User holds information about permission and other stuff.") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class User { @SerializedName("admin") private Boolean admin = null; diff --git a/client/src/main/java/com/github/gotify/client/model/UserPass.java b/client/src/main/java/com/github/gotify/client/model/UserPass.java index 626be0e..278603e 100644 --- a/client/src/main/java/com/github/gotify/client/model/UserPass.java +++ b/client/src/main/java/com/github/gotify/client/model/UserPass.java @@ -27,7 +27,7 @@ import java.io.IOException; * The Password for updating the user. */ @ApiModel(description = "The Password for updating the user.") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class UserPass { @SerializedName("pass") private String pass = null; diff --git a/client/src/main/java/com/github/gotify/client/model/UserWithPass.java b/client/src/main/java/com/github/gotify/client/model/UserWithPass.java index 2b17694..8078a60 100644 --- a/client/src/main/java/com/github/gotify/client/model/UserWithPass.java +++ b/client/src/main/java/com/github/gotify/client/model/UserWithPass.java @@ -27,7 +27,7 @@ import java.io.IOException; * The UserWithPass holds information about the credentials and other stuff. */ @ApiModel(description = "The UserWithPass holds information about the credentials and other stuff.") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class UserWithPass { @SerializedName("admin") private Boolean admin = null; diff --git a/client/src/main/java/com/github/gotify/client/model/VersionInfo.java b/client/src/main/java/com/github/gotify/client/model/VersionInfo.java index c72bed5..043c416 100644 --- a/client/src/main/java/com/github/gotify/client/model/VersionInfo.java +++ b/client/src/main/java/com/github/gotify/client/model/VersionInfo.java @@ -27,7 +27,7 @@ import java.io.IOException; * VersionInfo Model */ @ApiModel(description = "VersionInfo Model") -@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-10-27T16:51:12.097+02:00") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-11-12T21:00:23.670+01:00") public class VersionInfo { @SerializedName("buildDate") private String buildDate = null; diff --git a/client/src/test/java/com/github/gotify/client/api/MessageApiTest.java b/client/src/test/java/com/github/gotify/client/api/MessageApiTest.java index 68e248c..3d05122 100644 --- a/client/src/test/java/com/github/gotify/client/api/MessageApiTest.java +++ b/client/src/test/java/com/github/gotify/client/api/MessageApiTest.java @@ -1,24 +1,11 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.api; -import com.github.gotify.client.ApiException; +import com.github.gotify.client.ApiClient; import com.github.gotify.client.model.Error; import com.github.gotify.client.model.Message; import com.github.gotify.client.model.PagedMessages; +import org.junit.Before; import org.junit.Test; -import org.junit.Ignore; import java.util.ArrayList; import java.util.HashMap; @@ -28,123 +15,98 @@ import java.util.Map; /** * API tests for MessageApi */ -@Ignore public class MessageApiTest { - private final MessageApi api = new MessageApi(); + private MessageApi api; + + @Before + public void setup() { + api = new ApiClient().createService(MessageApi.class); + } - /** * Create a message. * * __NOTE__: This API ONLY accepts an application token as authentication. - * - * @throws ApiException - * if the Api call fails */ @Test - public void createMessageTest() throws ApiException { + public void createMessageTest() { Message body = null; - Message response = api.createMessage(body); + // Message response = api.createMessage(body); // TODO: test validations } - /** * Delete all messages from a specific application. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void deleteAppMessagesTest() throws ApiException { + public void deleteAppMessagesTest() { Integer id = null; - api.deleteAppMessages(id); + // Void response = api.deleteAppMessages(id); // TODO: test validations } - /** * Deletes a message with an id. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void deleteMessageTest() throws ApiException { + public void deleteMessageTest() { Integer id = null; - api.deleteMessage(id); + // Void response = api.deleteMessage(id); // TODO: test validations } - /** * Delete all messages. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void deleteMessagesTest() throws ApiException { - api.deleteMessages(); + public void deleteMessagesTest() { + // Void response = api.deleteMessages(); // TODO: test validations } - /** * Return all messages from a specific application. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void getAppMessagesTest() throws ApiException { + public void getAppMessagesTest() { Integer id = null; Integer limit = null; Integer since = null; - PagedMessages response = api.getAppMessages(id, limit, since); + // PagedMessages response = api.getAppMessages(id, limit, since); // TODO: test validations } - /** * Return all messages. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void getMessagesTest() throws ApiException { + public void getMessagesTest() { Integer limit = null; Integer since = null; - PagedMessages response = api.getMessages(limit, since); + // PagedMessages response = api.getMessages(limit, since); // TODO: test validations } - /** * Websocket, return newly created messages. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void streamMessagesTest() throws ApiException { - Message response = api.streamMessages(); + public void streamMessagesTest() { + // Message response = api.streamMessages(); // TODO: test validations } - } diff --git a/client/src/test/java/com/github/gotify/client/api/TokenApiTest.java b/client/src/test/java/com/github/gotify/client/api/TokenApiTest.java index ca90052..2003247 100644 --- a/client/src/test/java/com/github/gotify/client/api/TokenApiTest.java +++ b/client/src/test/java/com/github/gotify/client/api/TokenApiTest.java @@ -1,25 +1,12 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.api; -import com.github.gotify.client.ApiException; +import com.github.gotify.client.ApiClient; import com.github.gotify.client.model.Application; import com.github.gotify.client.model.Client; import com.github.gotify.client.model.Error; import java.io.File; +import org.junit.Before; import org.junit.Test; -import org.junit.Ignore; import java.util.ArrayList; import java.util.HashMap; @@ -29,121 +16,96 @@ import java.util.Map; /** * API tests for TokenApi */ -@Ignore public class TokenApiTest { - private final TokenApi api = new TokenApi(); + private TokenApi api; + + @Before + public void setup() { + api = new ApiClient().createService(TokenApi.class); + } - /** * Create an application. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void createAppTest() throws ApiException { + public void createAppTest() { Application body = null; - Application response = api.createApp(body); + // Application response = api.createApp(body); // TODO: test validations } - /** * Create a client. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void createClientTest() throws ApiException { + public void createClientTest() { Client body = null; - Client response = api.createClient(body); + // Client response = api.createClient(body); // TODO: test validations } - /** * Delete an application. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void deleteAppTest() throws ApiException { + public void deleteAppTest() { Integer id = null; - api.deleteApp(id); + // Void response = api.deleteApp(id); // TODO: test validations } - /** * Delete a client. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void deleteClientTest() throws ApiException { + public void deleteClientTest() { Integer id = null; - api.deleteClient(id); + // Void response = api.deleteClient(id); // TODO: test validations } - /** * Return all applications. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void getAppsTest() throws ApiException { - List response = api.getApps(); + public void getAppsTest() { + // List response = api.getApps(); // TODO: test validations } - /** * Return all clients. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void getClientsTest() throws ApiException { - List response = api.getClients(); + public void getClientsTest() { + // List response = api.getClients(); // TODO: test validations } - /** * * * Upload an image for an application - * - * @throws ApiException - * if the Api call fails */ @Test - public void uploadAppImageTest() throws ApiException { + public void uploadAppImageTest() { File file = null; Integer id = null; - Application response = api.uploadAppImage(file, id); + // Application response = api.uploadAppImage(file, id); // TODO: test validations } - } diff --git a/client/src/test/java/com/github/gotify/client/api/UserApiTest.java b/client/src/test/java/com/github/gotify/client/api/UserApiTest.java index 5e062c5..c507f96 100644 --- a/client/src/test/java/com/github/gotify/client/api/UserApiTest.java +++ b/client/src/test/java/com/github/gotify/client/api/UserApiTest.java @@ -1,25 +1,12 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.api; -import com.github.gotify.client.ApiException; +import com.github.gotify.client.ApiClient; import com.github.gotify.client.model.Error; import com.github.gotify.client.model.User; import com.github.gotify.client.model.UserPass; import com.github.gotify.client.model.UserWithPass; +import org.junit.Before; import org.junit.Test; -import org.junit.Ignore; import java.util.ArrayList; import java.util.HashMap; @@ -29,121 +16,96 @@ import java.util.Map; /** * API tests for UserApi */ -@Ignore public class UserApiTest { - private final UserApi api = new UserApi(); + private UserApi api; + + @Before + public void setup() { + api = new ApiClient().createService(UserApi.class); + } - /** * Create a user. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void createUserTest() throws ApiException { + public void createUserTest() { UserWithPass body = null; - User response = api.createUser(body); + // User response = api.createUser(body); // TODO: test validations } - /** * Return the current user. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void currentUserTest() throws ApiException { - User response = api.currentUser(); + public void currentUserTest() { + // User response = api.currentUser(); // TODO: test validations } - /** * Deletes a user. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void deleteUserTest() throws ApiException { + public void deleteUserTest() { Integer id = null; - api.deleteUser(id); + // Void response = api.deleteUser(id); // TODO: test validations } - /** * Get a user. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void getUserTest() throws ApiException { + public void getUserTest() { Integer id = null; - User response = api.getUser(id); + // User response = api.getUser(id); // TODO: test validations } - /** * Return all users. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void getUsersTest() throws ApiException { - List response = api.getUsers(); + public void getUsersTest() { + // List response = api.getUsers(); // TODO: test validations } - /** * Update the password of the current user. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void updateCurrentUserTest() throws ApiException { + public void updateCurrentUserTest() { UserPass body = null; - api.updateCurrentUser(body); + // Void response = api.updateCurrentUser(body); // TODO: test validations } - /** * Update a user. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void updateUserTest() throws ApiException { + public void updateUserTest() { Integer id = null; UserWithPass body = null; - User response = api.updateUser(id, body); + // User response = api.updateUser(id, body); // TODO: test validations } - } diff --git a/client/src/test/java/com/github/gotify/client/api/VersionApiTest.java b/client/src/test/java/com/github/gotify/client/api/VersionApiTest.java index 9dcf7aa..b2560dc 100644 --- a/client/src/test/java/com/github/gotify/client/api/VersionApiTest.java +++ b/client/src/test/java/com/github/gotify/client/api/VersionApiTest.java @@ -1,22 +1,9 @@ -/* - * Gotify REST-API. - * This is the documentation of the Gotify REST-API. # Authentication In Gotify there are two token types: __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`. There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. \\--- Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) - * - * OpenAPI spec version: 1.0.4 - * - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - package com.github.gotify.client.api; -import com.github.gotify.client.ApiException; +import com.github.gotify.client.ApiClient; import com.github.gotify.client.model.VersionInfo; +import org.junit.Before; import org.junit.Test; -import org.junit.Ignore; import java.util.ArrayList; import java.util.HashMap; @@ -26,25 +13,24 @@ import java.util.Map; /** * API tests for VersionApi */ -@Ignore public class VersionApiTest { - private final VersionApi api = new VersionApi(); + private VersionApi api; + + @Before + public void setup() { + api = new ApiClient().createService(VersionApi.class); + } - /** * Get version information. * * - * - * @throws ApiException - * if the Api call fails */ @Test - public void getVersionTest() throws ApiException { - VersionInfo response = api.getVersion(); + public void getVersionTest() { + // VersionInfo response = api.getVersion(); // TODO: test validations } - } diff --git a/swagger.config.json b/swagger.config.json index 1a3dd0c..13499e7 100644 --- a/swagger.config.json +++ b/swagger.config.json @@ -1,4 +1,5 @@ { "apiPackage": "com.github.gotify.client.api", - "modelPackage": "com.github.gotify.client.model" + "modelPackage": "com.github.gotify.client.model", + "library": "retrofit2" } \ No newline at end of file