mirror of
https://github.com/brunofontes/Memsource-API.git
synced 2024-11-23 19:00:50 +00:00
Include job download source and target files
This commit is contained in:
parent
abda9e4ee8
commit
b739763448
35
src/Jobs.php
35
src/Jobs.php
@ -29,4 +29,39 @@ class Jobs extends \BrunoFontes\Memsource\BaseApi
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a target file
|
||||
*
|
||||
* @param string $projectUid The project uid which contain the jobs
|
||||
* @param string $jobUid Job uid to be download
|
||||
* @param string $filename Filename of the saved file
|
||||
* @param string $format File format: ORIGINAL or PDF
|
||||
*/
|
||||
public function downloadTargetFile(string $projectUid, string $jobUid, string $filename, string $format = "ORIGINAL")
|
||||
{
|
||||
$url = "/api2/v1/projects/{$projectUid}/jobs/{$jobUid}/targetFile";
|
||||
$filecontent = $this->fetchApi->fetch('get', $url);
|
||||
|
||||
$f = fopen($filename, 'w+');
|
||||
fwrite($f, $filecontent);
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a source file
|
||||
*
|
||||
* @param string $projectUid The project uid which contain the jobs
|
||||
* @param string $jobUid Job uid to be download
|
||||
*/
|
||||
public function downloadOriginalFile(string $projectUid, string $jobUid, string $filename)
|
||||
{
|
||||
$url = "/api2/v1/projects/{$projectUid}/jobs/{$jobUid}/original";
|
||||
$filecontent = $this->fetchApi->fetch('get', $url);
|
||||
|
||||
$f = fopen($filename, 'w+');
|
||||
fwrite($f, $filecontent);
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,4 +12,22 @@ final class JobsTest extends TestCase
|
||||
$this->expectException(\Exception::class);
|
||||
$api->jobs()->list('invalidProjectUid', []);
|
||||
}
|
||||
|
||||
public function testDownloadTargetFileReturnsNull()
|
||||
{
|
||||
$api = new Memsource('fakeToken');
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$api->jobs()->downloadTargetFile('projUid', 'jobUid', 'filename.xliff')
|
||||
);
|
||||
}
|
||||
|
||||
public function testDownloadOriginalFileReturnsNull()
|
||||
{
|
||||
$api = new Memsource('fakeToken');
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$api->jobs()->downloadOriginalFile('projUid', 'jobUid', 'filename.xliff')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user