diff --git a/src/Jobs.php b/src/Jobs.php index 3c3cda2..594d831 100644 --- a/src/Jobs.php +++ b/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); + } + } diff --git a/tests/jobsTest.php b/tests/jobsTest.php index ced42d1..f8b5689 100644 --- a/tests/jobsTest.php +++ b/tests/jobsTest.php @@ -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') + ); + } }