This repository has been archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Mykhailo Shchukin
committed
Nov 19, 2015
1 parent
a39e181
commit 4347abe
Showing
69 changed files
with
2,289 additions
and
2,538 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.idea | ||
/api-sdk/.idea | ||
/api-sdk/*.iml |
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.smartling.api.sdk; | ||
|
||
/** | ||
* @author Hustred | ||
*/ | ||
public class ApiManager | ||
{ | ||
} |
80 changes: 80 additions & 0 deletions
80
api-sdk/src/main/java/com/smartling/api/sdk/BaseApiClient.java
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.smartling.api.sdk; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.reflect.TypeToken; | ||
import com.smartling.api.sdk.dto.ApiResponse; | ||
import com.smartling.api.sdk.dto.ApiResponseWrapper; | ||
import com.smartling.api.sdk.dto.Data; | ||
import com.smartling.api.sdk.exceptions.ApiException; | ||
import com.smartling.api.sdk.util.DateTypeAdapter; | ||
import com.smartling.api.sdk.util.HttpUtils; | ||
import com.smartling.api.sdk.file.response.ApiV2ResponseWrapper; | ||
import com.smartling.api.sdk.file.response.Response; | ||
import com.smartling.web.api.v2.ResponseData; | ||
import org.apache.commons.lang3.CharEncoding; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.entity.StringEntity; | ||
import org.codehaus.jackson.map.ObjectMapper; | ||
|
||
import java.io.IOException; | ||
import java.util.Date; | ||
|
||
public abstract class BaseApiClient | ||
{ | ||
private static final String APPLICATION_JSON_TYPE = "application/json"; | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
protected HttpUtils httpUtils; | ||
|
||
public HttpUtils getHttpUtils() | ||
{ | ||
return httpUtils; | ||
} | ||
|
||
protected static <T extends Data> ApiResponse<T> getApiResponse(final String response, final TypeToken<ApiResponseWrapper<T>> responseType) | ||
{ | ||
String fixedResponse = response.replaceAll("\"data\"\\:\"\"", "\"data\":null"); | ||
|
||
final GsonBuilder builder = new GsonBuilder(); | ||
builder.registerTypeAdapter(Date.class, new DateTypeAdapter()); | ||
|
||
final Gson gson = builder.create(); | ||
final ApiResponseWrapper<T> responseWrapper = gson.fromJson(fixedResponse, responseType.getType()); | ||
|
||
return responseWrapper.getResponse(); | ||
} | ||
|
||
protected static <T extends ResponseData> Response<T> getApiV2Response(final String response, final TypeToken<ApiV2ResponseWrapper<T>> responseType) | ||
{ | ||
String fixedResponse = response.replaceAll("\"data\"\\:\"\"", "\"data\":null"); | ||
|
||
final GsonBuilder builder = new GsonBuilder(); | ||
builder.registerTypeAdapter(Date.class, new DateTypeAdapter()); | ||
|
||
final Gson gson = builder.create(); | ||
final ApiV2ResponseWrapper<T> responseWrapper = gson.fromJson(fixedResponse, responseType.getType()); | ||
|
||
return responseWrapper.getResponse(); | ||
} | ||
|
||
protected HttpPost createJsonPostRequest(final String url, final Object command) throws ApiException | ||
{ | ||
final HttpPost httpPost = new HttpPost(url); | ||
final StringEntity stringEntity; | ||
try | ||
{ | ||
stringEntity = new StringEntity(objectMapper.writeValueAsString(command)); | ||
stringEntity.setContentType(APPLICATION_JSON_TYPE); | ||
stringEntity.setContentEncoding(CharEncoding.UTF_8); | ||
httpPost.setEntity(stringEntity); | ||
} | ||
catch (IOException e) | ||
{ | ||
throw new ApiException(e); | ||
} | ||
|
||
return httpPost; | ||
} | ||
} |
215 changes: 0 additions & 215 deletions
215
api-sdk/src/main/java/com/smartling/api/sdk/BaseApiClientAdapter.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
api-sdk/src/main/java/com/smartling/api/sdk/ConnectionConfig.java
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.smartling.api.sdk; | ||
|
||
public class ConnectionConfig | ||
{ | ||
private final ProxyConfiguration proxyConfiguration; | ||
private final String baseFileApiUrl; | ||
private final String projectId; | ||
|
||
public ConnectionConfig(final ProxyConfiguration proxyConfiguration, final String baseFileApiUrl, final String projectId) | ||
{ | ||
this.proxyConfiguration = proxyConfiguration; | ||
this.baseFileApiUrl = baseFileApiUrl; | ||
this.projectId = projectId; | ||
} | ||
|
||
public ProxyConfiguration getProxyConfiguration() | ||
{ | ||
return proxyConfiguration; | ||
} | ||
|
||
public String getBaseFileApiUrl() | ||
{ | ||
return baseFileApiUrl; | ||
} | ||
|
||
public String getProjectId() | ||
{ | ||
return projectId; | ||
} | ||
} |
Oops, something went wrong.