This repository was archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSmartlingApiExample.java
More file actions
69 lines (59 loc) · 2.98 KB
/
Copy pathSmartlingApiExample.java
File metadata and controls
69 lines (59 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright 2012 Smartling, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this work except in compliance with the License.
* You may obtain a copy of the License in the LICENSE file, or at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.smartling.api.sdk.file.*;
import com.smartling.api.sdk.file.response.*;
import java.io.File;
import org.apache.commons.io.FilenameUtils;
public class SmartlingApiExample
{
private static final String API_KEY = "YOUR-API-KEY";
private static final String PROJECT_ID = "YOUR-PROJECT-ID";
private static final String LOCALE = "YOUR-LOCALE";
private static final String PATH_TO_FILE = "resources/test.properties";
private static final String FILE_ENCODING = "UTF-8";
private static final FileType FILE_TYPE = FileType.JAVA_PROPERTIES;
private static final String CALLBACK_URL = null;
public static void main(String args[]) throws FileApiException
{
FileApiClientAdapter smartlingFAPI = new FileApiClientAdapterImpl(true, API_KEY, PROJECT_ID);
// upload the file
File file = new File(FilenameUtils.separatorsToSystem(PATH_TO_FILE));
ApiResponse<UploadData> uploadFileResponse = smartlingFAPI.uploadFile(FILE_TYPE, getFileUri(file), file, false, FILE_ENCODING, CALLBACK_URL);
System.out.println(uploadFileResponse);
// rename the file
final String fileIdentifier = "myTestFileIdentifier";
ApiResponse<EmptyResponse> renameFileResponse = smartlingFAPI.renameFile(getFileUri(file), fileIdentifier);
System.out.println(renameFileResponse);
// run a search for files
FileListSearchParams fileListSearchParams = new FileListSearchParams();
fileListSearchParams.setUriMask(fileIdentifier);
ApiResponse<FileList> filesListResponse = smartlingFAPI.getFilesList(fileListSearchParams);
System.out.println(filesListResponse);
// check the file status
ApiResponse<FileStatus> fileStatusResponse = smartlingFAPI.getFileStatus(fileIdentifier, LOCALE);
System.out.println(fileStatusResponse);
// get the file back, including any translations that have been published.
StringResponse translatedContent = smartlingFAPI.getFile(fileIdentifier, LOCALE, RetrievalType.PUBLISHED);
System.out.println(translatedContent.getContents());
// delete the file
ApiResponse<EmptyResponse> deleteFileResponse = smartlingFAPI.deleteFile(fileIdentifier);
System.out.println(deleteFileResponse);
}
private static String getFileUri(File file)
{
return file.getName();
}
}