Include job download source and target files

This commit is contained in:
Bruno F. Fontes 2021-02-12 19:02:25 -03:00
parent abda9e4ee8
commit b739763448
Signed by: brunofontes
GPG Key ID: EE3447CE80048495
2 changed files with 53 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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')
);
}
}