22
33namespace JG \Task ;
44
5- use Guzzle \Http \Client ;;
5+ use Guzzle \Http \Client ;
66use \Task ;
77
88/**
1414 */
1515class 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 ];
0 commit comments