Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Commit

Permalink
APIv2 initials
Browse files Browse the repository at this point in the history
  • Loading branch information
Mykhailo Shchukin committed Nov 19, 2015
1 parent a39e181 commit 4347abe
Show file tree
Hide file tree
Showing 69 changed files with 2,289 additions and 2,538 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea
/api-sdk/.idea
/api-sdk/*.iml
17 changes: 17 additions & 0 deletions api-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,22 @@
<version>1.6.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.smartling</groupId>
<artifactId>public-api-commons</artifactId>
<version>1.2.0-RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>

</dependencies>
</project>
8 changes: 8 additions & 0 deletions api-sdk/src/main/java/com/smartling/api/sdk/ApiManager.java
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 api-sdk/src/main/java/com/smartling/api/sdk/BaseApiClient.java
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 api-sdk/src/main/java/com/smartling/api/sdk/BaseApiClientAdapter.java

This file was deleted.

30 changes: 30 additions & 0 deletions api-sdk/src/main/java/com/smartling/api/sdk/ConnectionConfig.java
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;
}
}
Loading

0 comments on commit 4347abe

Please sign in to comment.