-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a69a425
commit 20f917c
Showing
1 changed file
with
33 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/* | ||
* 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 | | ||
* 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 | | ||
* | ||
* OpenAPI spec version: 3.0.0 | ||
* Contact: [email protected] | ||
|
@@ -28,8 +27,6 @@ | |
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.UnsupportedEncodingException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.lang.reflect.Type; | ||
import java.net.URLConnection; | ||
import java.net.URLEncoder; | ||
|
@@ -58,6 +55,7 @@ public class ApiClient { | |
private boolean debugging = false; | ||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>(); | ||
private String tempFolderPath = null; | ||
private String defaultUserAgent = "sendinblue_clientAPI/v5.3.0/java"; | ||
|
||
private Map<String, Authentication> authentications; | ||
|
||
|
@@ -87,7 +85,7 @@ public ApiClient() { | |
json = new Json(); | ||
|
||
// Set default User-Agent. | ||
setUserAgent("Swagger-Codegen/6.0.0/java"); | ||
setUserAgent(defaultUserAgent); | ||
|
||
// Setup authentications (key: authentication name, value: authentication). | ||
authentications = new HashMap<String, Authentication>(); | ||
|
@@ -349,7 +347,10 @@ public void setAccessToken(String accessToken) { | |
* @return ApiClient | ||
*/ | ||
public ApiClient setUserAgent(String userAgent) { | ||
addDefaultHeader("User-Agent", userAgent); | ||
if (userAgent.toLowerCase().startsWith("sendinblue_")) | ||
addDefaultHeader("User-Agent", userAgent); | ||
else | ||
addDefaultHeader("User-Agent", defaultUserAgent); | ||
return this; | ||
} | ||
|
||
|
@@ -400,8 +401,8 @@ public ApiClient setDebugging(boolean debugging) { | |
* with file response. The default value is <code>null</code>, i.e. using | ||
* the system's default tempopary folder. | ||
* | ||
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a> | ||
* @return Temporary folder path | ||
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a> | ||
*/ | ||
public String getTempFolderPath() { | ||
return tempFolderPath; | ||
|
@@ -599,6 +600,7 @@ public String sanitizeFilename(String filename) { | |
* 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. | ||
*/ | ||
|
@@ -758,8 +760,8 @@ public RequestBody serialize(Object obj, String contentType) throws ApiException | |
* 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 | ||
* @throws ApiException If fail to read file content from response and write to disk | ||
*/ | ||
public File downloadFileFromResponse(Response response) throws ApiException { | ||
try { | ||
|
@@ -777,8 +779,8 @@ public File downloadFileFromResponse(Response response) throws ApiException { | |
* 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 | ||
* @throws IOException If fail to prepare file for download | ||
*/ | ||
public File prepareDownloadFile(Response response) throws IOException { | ||
String filename = null; | ||
|
@@ -811,18 +813,18 @@ public File prepareDownloadFile(Response response) throws IOException { | |
} | ||
|
||
if (tempFolderPath == null) | ||
return Files.createTempFile(prefix, suffix).toFile(); | ||
return File.createTempFile(prefix, suffix); | ||
else | ||
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile(); | ||
return File.createTempFile(prefix, suffix, new File(tempFolderPath)); | ||
} | ||
|
||
/** | ||
* {@link #execute(Call, Type)} | ||
* | ||
* @param <T> Type | ||
* @param call An instance of the Call object | ||
* @throws ApiException If fail to execute the call | ||
* @return ApiResponse<T> | ||
* @throws ApiException If fail to execute the call | ||
*/ | ||
public <T> ApiResponse<T> execute(Call call) throws ApiException { | ||
return execute(call, null); | ||
|
@@ -867,7 +869,8 @@ public <T> void executeAsync(Call call, ApiCallback<T> callback) { | |
* @param <T> Type | ||
* @param call The callback to be executed when the API call finishes | ||
* @param returnType Return type | ||
* @param callback ApiCallback | ||
* @param callback ApiCallback | ||
* @see #execute(Call, Type) | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public <T> void executeAsync(Call call, final Type returnType, final ApiCallback<T> callback) { | ||
|
@@ -897,9 +900,9 @@ public void onResponse(Response response) throws IOException { | |
* @param <T> 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 | ||
* @throws ApiException If the response has a unsuccessful status code or | ||
* fail to deserialize the response body | ||
*/ | ||
public <T> T handleResponse(Response response, Type returnType) throws ApiException { | ||
if (response.isSuccessful()) { | ||
|
@@ -963,7 +966,7 @@ public Call buildCall(String path, String method, List<Pair> queryParams, List<P | |
* @param formParams The form parameters | ||
* @param authNames The authentications to apply | ||
* @param progressRequestListener Progress request listener | ||
* @return The HTTP request | ||
* @return The HTTP request | ||
* @throws ApiException If fail to serialize the request body object | ||
*/ | ||
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() { | |
if (!verifyingSsl) { | ||
TrustManager trustAll = new X509TrustManager() { | ||
@Override | ||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {} | ||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { | ||
} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {} | ||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { | ||
} | ||
|
||
@Override | ||
public X509Certificate[] getAcceptedIssuers() { return null; } | ||
public X509Certificate[] getAcceptedIssuers() { | ||
return null; | ||
} | ||
}; | ||
SSLContext sslContext = SSLContext.getInstance("TLS"); | ||
trustManagers = new TrustManager[]{ trustAll }; | ||
trustManagers = new TrustManager[]{trustAll}; | ||
hostnameVerifier = new HostnameVerifier() { | ||
@Override | ||
public boolean verify(String hostname, SSLSession session) { return true; } | ||
public boolean verify(String hostname, SSLSession session) { | ||
return true; | ||
} | ||
}; | ||
} else if (sslCaCert != null) { | ||
char[] password = null; // Any password will work. | ||
|
@@ -1206,4 +1217,4 @@ private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityExcepti | |
throw new AssertionError(e); | ||
} | ||
} | ||
} | ||
} |