From b739763448edb903dc5ad8a0907e57c9a6790177 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Fri, 12 Feb 2021 19:02:25 -0300 Subject: [PATCH] Include job download source and target files --- src/Jobs.php | 35 +++++++++++++++++++++++++++++++++++ tests/jobsTest.php | 18 ++++++++++++++++++ 2 files changed, 53 insertions(+) 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') + ); + } }