1
1
/*
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 |
4
3
*
5
4
* OpenAPI spec version: 3.0.0
6
5
28
27
import java .io .IOException ;
29
28
import java .io .InputStream ;
30
29
import java .io .UnsupportedEncodingException ;
31
- import java .nio .file .Files ;
32
- import java .nio .file .Paths ;
33
30
import java .lang .reflect .Type ;
34
31
import java .net .URLConnection ;
35
32
import java .net .URLEncoder ;
@@ -58,6 +55,7 @@ public class ApiClient {
58
55
private boolean debugging = false ;
59
56
private Map <String , String > defaultHeaderMap = new HashMap <String , String >();
60
57
private String tempFolderPath = null ;
58
+ private String defaultUserAgent = "sendinblue_clientAPI/v5.3.0/java" ;
61
59
62
60
private Map <String , Authentication > authentications ;
63
61
@@ -87,7 +85,7 @@ public ApiClient() {
87
85
json = new Json ();
88
86
89
87
// Set default User-Agent.
90
- setUserAgent ("Swagger-Codegen/6.0.0/java" );
88
+ setUserAgent (defaultUserAgent );
91
89
92
90
// Setup authentications (key: authentication name, value: authentication).
93
91
authentications = new HashMap <String , Authentication >();
@@ -349,7 +347,10 @@ public void setAccessToken(String accessToken) {
349
347
* @return ApiClient
350
348
*/
351
349
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 );
353
354
return this ;
354
355
}
355
356
@@ -400,8 +401,8 @@ public ApiClient setDebugging(boolean debugging) {
400
401
* with file response. The default value is <code>null</code>, i.e. using
401
402
* the system's default tempopary folder.
402
403
*
403
- * @see <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a>
404
404
* @return Temporary folder path
405
+ * @see <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a>
405
406
*/
406
407
public String getTempFolderPath () {
407
408
return tempFolderPath ;
@@ -599,6 +600,7 @@ public String sanitizeFilename(String filename) {
599
600
* APPLICATION/JSON
600
601
* application/vnd.company+json
601
602
* "* / *" is also default to JSON
603
+ *
602
604
* @param mime MIME (Multipurpose Internet Mail Extensions)
603
605
* @return True if the given MIME is JSON, false otherwise.
604
606
*/
@@ -758,8 +760,8 @@ public RequestBody serialize(Object obj, String contentType) throws ApiException
758
760
* Download file from the given response.
759
761
*
760
762
* @param response An instance of the Response object
761
- * @throws ApiException If fail to read file content from response and write to disk
762
763
* @return Downloaded file
764
+ * @throws ApiException If fail to read file content from response and write to disk
763
765
*/
764
766
public File downloadFileFromResponse (Response response ) throws ApiException {
765
767
try {
@@ -777,8 +779,8 @@ public File downloadFileFromResponse(Response response) throws ApiException {
777
779
* Prepare file for download
778
780
*
779
781
* @param response An instance of the Response object
780
- * @throws IOException If fail to prepare file for download
781
782
* @return Prepared file for the download
783
+ * @throws IOException If fail to prepare file for download
782
784
*/
783
785
public File prepareDownloadFile (Response response ) throws IOException {
784
786
String filename = null ;
@@ -811,18 +813,18 @@ public File prepareDownloadFile(Response response) throws IOException {
811
813
}
812
814
813
815
if (tempFolderPath == null )
814
- return Files .createTempFile (prefix , suffix ). toFile ( );
816
+ return File .createTempFile (prefix , suffix );
815
817
else
816
- return Files .createTempFile (Paths . get ( tempFolderPath ), prefix , suffix ). toFile ( );
818
+ return File .createTempFile (prefix , suffix , new File ( tempFolderPath ) );
817
819
}
818
820
819
821
/**
820
822
* {@link #execute(Call, Type)}
821
823
*
822
824
* @param <T> Type
823
825
* @param call An instance of the Call object
824
- * @throws ApiException If fail to execute the call
825
826
* @return ApiResponse<T>
827
+ * @throws ApiException If fail to execute the call
826
828
*/
827
829
public <T > ApiResponse <T > execute (Call call ) throws ApiException {
828
830
return execute (call , null );
@@ -867,7 +869,8 @@ public <T> void executeAsync(Call call, ApiCallback<T> callback) {
867
869
* @param <T> Type
868
870
* @param call The callback to be executed when the API call finishes
869
871
* @param returnType Return type
870
- * @param callback ApiCallback
872
+ * @param callback ApiCallback
873
+ * @see #execute(Call, Type)
871
874
*/
872
875
@ SuppressWarnings ("unchecked" )
873
876
public <T > void executeAsync (Call call , final Type returnType , final ApiCallback <T > callback ) {
@@ -897,9 +900,9 @@ public void onResponse(Response response) throws IOException {
897
900
* @param <T> Type
898
901
* @param response Response
899
902
* @param returnType Return type
900
- * @throws ApiException If the response has a unsuccessful status code or
901
- * fail to deserialize the response body
902
903
* @return Type
904
+ * @throws ApiException If the response has a unsuccessful status code or
905
+ * fail to deserialize the response body
903
906
*/
904
907
public <T > T handleResponse (Response response , Type returnType ) throws ApiException {
905
908
if (response .isSuccessful ()) {
@@ -963,7 +966,7 @@ public Call buildCall(String path, String method, List<Pair> queryParams, List<P
963
966
* @param formParams The form parameters
964
967
* @param authNames The authentications to apply
965
968
* @param progressRequestListener Progress request listener
966
- * @return The HTTP request
969
+ * @return The HTTP request
967
970
* @throws ApiException If fail to serialize the request body object
968
971
*/
969
972
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() {
1154
1157
if (!verifyingSsl ) {
1155
1158
TrustManager trustAll = new X509TrustManager () {
1156
1159
@ Override
1157
- public void checkClientTrusted (X509Certificate [] chain , String authType ) throws CertificateException {}
1160
+ public void checkClientTrusted (X509Certificate [] chain , String authType ) throws CertificateException {
1161
+ }
1162
+
1158
1163
@ Override
1159
- public void checkServerTrusted (X509Certificate [] chain , String authType ) throws CertificateException {}
1164
+ public void checkServerTrusted (X509Certificate [] chain , String authType ) throws CertificateException {
1165
+ }
1166
+
1160
1167
@ Override
1161
- public X509Certificate [] getAcceptedIssuers () { return null ; }
1168
+ public X509Certificate [] getAcceptedIssuers () {
1169
+ return null ;
1170
+ }
1162
1171
};
1163
1172
SSLContext sslContext = SSLContext .getInstance ("TLS" );
1164
- trustManagers = new TrustManager []{ trustAll };
1173
+ trustManagers = new TrustManager []{trustAll };
1165
1174
hostnameVerifier = new HostnameVerifier () {
1166
1175
@ Override
1167
- public boolean verify (String hostname , SSLSession session ) { return true ; }
1176
+ public boolean verify (String hostname , SSLSession session ) {
1177
+ return true ;
1178
+ }
1168
1179
};
1169
1180
} else if (sslCaCert != null ) {
1170
1181
char [] password = null ; // Any password will work.
@@ -1206,4 +1217,4 @@ private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityExcepti
1206
1217
throw new AssertionError (e );
1207
1218
}
1208
1219
}
1209
- }
1220
+ }
0 commit comments