-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsmartlingAPI.class.php
More file actions
74 lines (63 loc) · 2.13 KB
/
smartlingAPI.class.php
File metadata and controls
74 lines (63 loc) · 2.13 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
70
71
72
73
74
<?php
class SmartlingAPI
{
private $baseUrl = "https://api.smartling.com/v1/file";
private $apiKey;
private $projectId;
public function __construct($apiKey, $projectId) {
$this->apiKey = $apiKey;
$this->projectId = $projectId;
}
public function uploadFile($path, $fileType, $fileUri, $approved, $charset = 'UTF-8') {
return $this->sendRequest('upload', array(
'file' => '@' . $path . ';type=text/plain charset=' . $charset,
'fileType' => $fileType,
'fileUri' => $fileUri,
'approved' => $approved
));
}
public function downloadFile($fileUri, $retrievalType, $locale, $fh) {
$params = array(
'fileUri' => $fileUri,
'retrievalType' => $retrievalType,
'locale' => $locale
);
return $this->sendRequest('get', $params, $fh);
}
public function getStatus($fileUri, $locale) {
return $this->sendRequest('status', array(
'fileUri' => $fileUri,
'locale' => $locale
));
}
public function getList($locale, $params = array()) {
return $this->sendRequest('list', array_merge_recursive(array(
'locale' => $locale
), $params));
}
private function sendRequest($type, $params, $fh = NULL) {
$handler = curl_init();
curl_setopt_array($handler, array(
CURLOPT_URL => $this->baseUrl . "/" . $type,
CURLOPT_PORT => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => array_merge_recursive(array(
'apiKey' => $this->apiKey,
'projectId' => $this->projectId
),
$params
)
));
if(!is_null($fh)){
curl_setopt($handler, CURLOPT_FILE, $fh);
}
$response = curl_exec($handler);
if($response) {
$result = json_decode($response, true);
return $result ? $result : $response;
} else {
echo curl_error($handler);
return false;
}
}
}