11/*
2- * SendinBlue API
3- * SendinBlue provide a RESTFul API that can be used with any languages. With this API, you will be able to : - Manage your campaigns and get the statistics - Manage your contacts - Send transactional Emails and SMS - and much more... You can download our wrappers at https://github.com/orgs/sendinblue **Possible responses** | Code | Message | | :-------------: | ------------- | | 200 | OK. Successful Request | | 201 | OK. Successful Creation | | 202 | OK. Request accepted | | 204 | OK. Successful Update/Deletion | | 400 | Error. Bad Request | | 401 | Error. Authentication Needed | | 402 | Error. Not enough credit, plan upgrade needed | | 403 | Error. Permission denied | | 404 | Error. Object does not exist | | 405 | Error. Method not allowed | | 406 | Error. Not Acceptable |
2+ * SendinBlue API * SendinBlue provide a RESTFul API that can be used with any languages. With this API, you will be able to : - Manage your campaigns and get the statistics - Manage your contacts - Send transactional Emails and SMS - and much more... You can download our wrappers at https://github.com/orgs/sendinblue **Possible responses** | Code | Message | | :-------------: | ------------- | | 200 | OK. Successful Request | | 201 | OK. Successful Creation | | 202 | OK. Request accepted | | 204 | OK. Successful Update/Deletion | | 400 | Error. Bad Request | | 401 | Error. Authentication Needed | | 402 | Error. Not enough credit, plan upgrade needed | | 403 | Error. Permission denied | | 404 | Error. Object does not exist | | 405 | Error. Method not allowed | | 406 | Error. Not Acceptable |
43 *
54 * OpenAPI spec version: 3.0.0
652827import java .io .IOException ;
2928import java .io .InputStream ;
3029import java .io .UnsupportedEncodingException ;
31- import java .nio .file .Files ;
32- import java .nio .file .Paths ;
3330import java .lang .reflect .Type ;
3431import java .net .URLConnection ;
3532import java .net .URLEncoder ;
@@ -58,6 +55,7 @@ public class ApiClient {
5855 private boolean debugging = false ;
5956 private Map <String , String > defaultHeaderMap = new HashMap <String , String >();
6057 private String tempFolderPath = null ;
58+ private String defaultUserAgent = "sendinblue_clientAPI/v5.3.0/java" ;
6159
6260 private Map <String , Authentication > authentications ;
6361
@@ -87,7 +85,7 @@ public ApiClient() {
8785 json = new Json ();
8886
8987 // Set default User-Agent.
90- setUserAgent ("Swagger-Codegen/6.0.0/java" );
88+ setUserAgent (defaultUserAgent );
9189
9290 // Setup authentications (key: authentication name, value: authentication).
9391 authentications = new HashMap <String , Authentication >();
@@ -349,7 +347,10 @@ public void setAccessToken(String accessToken) {
349347 * @return ApiClient
350348 */
351349 public ApiClient setUserAgent (String userAgent ) {
352- addDefaultHeader ("User-Agent" , userAgent );
350+ if (userAgent .toLowerCase ().startsWith ("sendinblue_" ))
351+ addDefaultHeader ("User-Agent" , userAgent );
352+ else
353+ addDefaultHeader ("User-Agent" , defaultUserAgent );
353354 return this ;
354355 }
355356
@@ -400,8 +401,8 @@ public ApiClient setDebugging(boolean debugging) {
400401 * with file response. The default value is <code>null</code>, i.e. using
401402 * the system's default tempopary folder.
402403 *
403- * @see <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a>
404404 * @return Temporary folder path
405+ * @see <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a>
405406 */
406407 public String getTempFolderPath () {
407408 return tempFolderPath ;
@@ -599,6 +600,7 @@ public String sanitizeFilename(String filename) {
599600 * APPLICATION/JSON
600601 * application/vnd.company+json
601602 * "* / *" is also default to JSON
603+ *
602604 * @param mime MIME (Multipurpose Internet Mail Extensions)
603605 * @return True if the given MIME is JSON, false otherwise.
604606 */
@@ -758,8 +760,8 @@ public RequestBody serialize(Object obj, String contentType) throws ApiException
758760 * Download file from the given response.
759761 *
760762 * @param response An instance of the Response object
761- * @throws ApiException If fail to read file content from response and write to disk
762763 * @return Downloaded file
764+ * @throws ApiException If fail to read file content from response and write to disk
763765 */
764766 public File downloadFileFromResponse (Response response ) throws ApiException {
765767 try {
@@ -777,8 +779,8 @@ public File downloadFileFromResponse(Response response) throws ApiException {
777779 * Prepare file for download
778780 *
779781 * @param response An instance of the Response object
780- * @throws IOException If fail to prepare file for download
781782 * @return Prepared file for the download
783+ * @throws IOException If fail to prepare file for download
782784 */
783785 public File prepareDownloadFile (Response response ) throws IOException {
784786 String filename = null ;
@@ -811,18 +813,18 @@ public File prepareDownloadFile(Response response) throws IOException {
811813 }
812814
813815 if (tempFolderPath == null )
814- return Files .createTempFile (prefix , suffix ). toFile ( );
816+ return File .createTempFile (prefix , suffix );
815817 else
816- return Files .createTempFile (Paths . get ( tempFolderPath ), prefix , suffix ). toFile ( );
818+ return File .createTempFile (prefix , suffix , new File ( tempFolderPath ) );
817819 }
818820
819821 /**
820822 * {@link #execute(Call, Type)}
821823 *
822824 * @param <T> Type
823825 * @param call An instance of the Call object
824- * @throws ApiException If fail to execute the call
825826 * @return ApiResponse<T>
827+ * @throws ApiException If fail to execute the call
826828 */
827829 public <T > ApiResponse <T > execute (Call call ) throws ApiException {
828830 return execute (call , null );
@@ -867,7 +869,8 @@ public <T> void executeAsync(Call call, ApiCallback<T> callback) {
867869 * @param <T> Type
868870 * @param call The callback to be executed when the API call finishes
869871 * @param returnType Return type
870- * @param callback ApiCallback
872+ * @param callback ApiCallback
873+ * @see #execute(Call, Type)
871874 */
872875 @ SuppressWarnings ("unchecked" )
873876 public <T > void executeAsync (Call call , final Type returnType , final ApiCallback <T > callback ) {
@@ -897,9 +900,9 @@ public void onResponse(Response response) throws IOException {
897900 * @param <T> Type
898901 * @param response Response
899902 * @param returnType Return type
900- * @throws ApiException If the response has a unsuccessful status code or
901- * fail to deserialize the response body
902903 * @return Type
904+ * @throws ApiException If the response has a unsuccessful status code or
905+ * fail to deserialize the response body
903906 */
904907 public <T > T handleResponse (Response response , Type returnType ) throws ApiException {
905908 if (response .isSuccessful ()) {
@@ -963,7 +966,7 @@ public Call buildCall(String path, String method, List<Pair> queryParams, List<P
963966 * @param formParams The form parameters
964967 * @param authNames The authentications to apply
965968 * @param progressRequestListener Progress request listener
966- * @return The HTTP request
969+ * @return The HTTP request
967970 * @throws ApiException If fail to serialize the request body object
968971 */
969972 public Request buildRequest (String path , String method , List <Pair > queryParams , List <Pair > collectionQueryParams , Object body , Map <String , String > headerParams , Map <String , Object > formParams , String [] authNames , ProgressRequestBody .ProgressRequestListener progressRequestListener ) throws ApiException {
@@ -1154,17 +1157,25 @@ private void applySslSettings() {
11541157 if (!verifyingSsl ) {
11551158 TrustManager trustAll = new X509TrustManager () {
11561159 @ Override
1157- public void checkClientTrusted (X509Certificate [] chain , String authType ) throws CertificateException {}
1160+ public void checkClientTrusted (X509Certificate [] chain , String authType ) throws CertificateException {
1161+ }
1162+
11581163 @ Override
1159- public void checkServerTrusted (X509Certificate [] chain , String authType ) throws CertificateException {}
1164+ public void checkServerTrusted (X509Certificate [] chain , String authType ) throws CertificateException {
1165+ }
1166+
11601167 @ Override
1161- public X509Certificate [] getAcceptedIssuers () { return null ; }
1168+ public X509Certificate [] getAcceptedIssuers () {
1169+ return null ;
1170+ }
11621171 };
11631172 SSLContext sslContext = SSLContext .getInstance ("TLS" );
1164- trustManagers = new TrustManager []{ trustAll };
1173+ trustManagers = new TrustManager []{trustAll };
11651174 hostnameVerifier = new HostnameVerifier () {
11661175 @ Override
1167- public boolean verify (String hostname , SSLSession session ) { return true ; }
1176+ public boolean verify (String hostname , SSLSession session ) {
1177+ return true ;
1178+ }
11681179 };
11691180 } else if (sslCaCert != null ) {
11701181 char [] password = null ; // Any password will work.
@@ -1206,4 +1217,4 @@ private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityExcepti
12061217 throw new AssertionError (e );
12071218 }
12081219 }
1209- }
1220+ }
0 commit comments