Skip to content

Commit ced0fee

Browse files
committed
Fixed API requests
1 parent c113e17 commit ced0fee

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/Task/PoeditorTask.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace JG\Task;
44

5-
use Guzzle\Http\Client;;
5+
use Guzzle\Http\Client;
66
use \Task;
77

88
/**
@@ -14,7 +14,7 @@
1414
*/
1515
class PoeditorTask extends Task
1616
{
17-
const API_ENDPOINT = 'https://poeditor.com/api';
17+
const API_ENDPOINT = 'https://poeditor.com/api/';
1818

1919
const DEFAULT_TYPE = 'po';
2020

@@ -36,7 +36,7 @@ class PoeditorTask extends Task
3636
*
3737
* @var string
3838
*/
39-
protected $id;
39+
protected $project;
4040

4141
/**
4242
* Language code
@@ -141,20 +141,20 @@ public function setToken($token)
141141
*
142142
* @return string
143143
*/
144-
public function getId()
144+
public function getProject()
145145
{
146-
return $this->id;
146+
return $this->project;
147147
}
148148

149149
/**
150150
* Set the id
151151
*
152-
* @param string $id
152+
* @param string $project
153153
* @return PoeditorTask
154154
*/
155-
public function setId($id)
155+
public function setProject($project)
156156
{
157-
$this->id = $id;
157+
$this->project = $project;
158158
return $this;
159159
}
160160

@@ -259,15 +259,18 @@ public function setExportPath($exportPath)
259259
public function main()
260260
{
261261
$client = new Client();
262-
$response = $client->post(self::API_ENDPOINT, null, $this->getPostParams())->send();
262+
$request = $client->post(self::API_ENDPOINT, null, $this->getPostParams());
263+
$response = $request->send();
263264
if ($response->getStatusCode() != 200) {
264-
265+
throw new \BuildException('Unable to retrieve translation file');
265266
}
266267
$json = $response->json();
267268

268269
$item = $json['item'];
269270

270-
$this->apiClient->get($item, null, ['sink' => $this->retrieveFileName()])->send();
271+
$handle = fopen($this->retrieveFileName(), 'w');
272+
$client->get($item, null, [Client::CURL_OPTIONS => ['CURLOPT_FILE' => $handle]])->send();
273+
fclose($handle);
271274
}
272275

273276
protected function retrieveFileName()
@@ -283,7 +286,7 @@ protected function getPostParams()
283286
return [
284287
'api_token' => $this->getToken(),
285288
'action' => 'export',
286-
'id' => $this->getId(),
289+
'id' => $this->getProject(),
287290
'type' => $this->getType() ?: self::DEFAULT_TYPE,
288291
'language' => $this->getLanguage(),
289292
];

tasks.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<project>
22
<taskdef name="sass" classname="JG\Task\SassTask" />
3-
<taskdef name="poeditor" classname="JG\Task\Poeditor" />
3+
<taskdef name="poeditor" classname="JG\Task\PoeditorTask" />
44
</project>

0 commit comments

Comments
 (0)