mirror of
https://github.com/brunofontes/Memsource-API.git
synced 2025-04-18 18:07:12 +00:00
Refactoring function names as no one is using it yet
This commit is contained in:
parent
6f19522c52
commit
13fadfe9ae
10
README.md
10
README.md
@ -96,13 +96,13 @@ $projectList = $memsource->project()->listProjects;
|
|||||||
To use filters, add the API filter as parameter:
|
To use filters, add the API filter as parameter:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$projectList = $memsource->project()->listProjects(['name' => 'Project X']);
|
$projectList = $memsource->project()->list(['name' => 'Project X']);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Get Project
|
#### Get Project
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$projectList = $memsource->project()->getProject($projectUid);
|
$projectList = $memsource->project()->get($projectUid);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Jobs
|
### Jobs
|
||||||
@ -112,7 +112,7 @@ $projectList = $memsource->project()->getProject($projectUid);
|
|||||||
Only projectUid is essencial:
|
Only projectUid is essencial:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$jobs = $memsource->jobs()->listJobs($projectUid, ['count' => true, 'filename' => 'my_file.html']);
|
$jobs = $memsource->jobs()->list($projectUid, ['count' => true, 'filename' => 'my_file.html']);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Bilingual Files
|
### Bilingual Files
|
||||||
@ -120,12 +120,12 @@ $jobs = $memsource->jobs()->listJobs($projectUid, ['count' => true, 'filename' =
|
|||||||
#### Download Bilingual File
|
#### Download Bilingual File
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$memsource->BilingualFile()->downloadBilingualFile($projectUid, ['JobUid1', 'jobUid2'], 'download.mxliff');
|
$memsource->BilingualFile()->download($projectUid, ['JobUid1', 'jobUid2'], 'download.mxliff');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Upload Bilingual File
|
#### Upload Bilingual File
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$parameters = ['format' => 'MXLF', 'saveToTransMemory' => 'None', 'setCompleted' => 'false'];
|
$parameters = ['format' => 'MXLF', 'saveToTransMemory' => 'None', 'setCompleted' => 'false'];
|
||||||
$result = $api->bilingualFile()->uploadBilingualFile('upload.mxliff', $parameters);
|
$result = $api->bilingualFile()->upload('upload.mxliff', $parameters);
|
||||||
```
|
```
|
||||||
|
@ -1,40 +1,41 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* A very compact and simple Memsource API library
|
* A very compact and simple Memsource API library
|
||||||
*
|
*
|
||||||
* @author Bruno Fontes <developer@brunofontes.net>
|
* @author Bruno Fontes <developer@brunofontes.net>
|
||||||
* @link https://github.com/brunofontes
|
* @link https://github.com/brunofontes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace BrunoFontes\Memsource;
|
namespace BrunoFontes\Memsource;
|
||||||
|
|
||||||
class BilingualFile extends \BrunoFontes\Memsource\BaseApi
|
class BilingualFile extends \BrunoFontes\Memsource\BaseApi
|
||||||
{
|
{
|
||||||
private $_url = '/api2/v1/bilingualFiles';
|
private $_url = '/api2/v1/bilingualFiles';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download one or more bilingual files
|
* Download one or more bilingual files
|
||||||
*
|
*
|
||||||
* As Memsource limits downloading files into 100 jobs per time, this script
|
* As Memsource limits downloading files into 100 jobs per time, this script
|
||||||
* will prevent that by making all the necessary fetchs and saving each on
|
* will prevent that by making all the necessary fetchs and saving each on
|
||||||
* a different file.
|
* a different file.
|
||||||
*
|
*
|
||||||
* An array with all the files used will be returned.
|
* An array with all the files used will be returned.
|
||||||
*
|
*
|
||||||
* @param string $projectUid The project uid which contain the jobs
|
* @param string $projectUid The project uid which contain the jobs
|
||||||
* @param array $jobUids A simple array of Job uids: ['job_uid1', 'job_uid2']
|
* @param array $jobUids A simple array of Job uids: ['job_uid1', 'job_uid2']
|
||||||
* @param string $filename File that will be created on server to store the
|
* @param string $filename File that will be created on server to store the
|
||||||
* downloaded jobs
|
* downloaded jobs
|
||||||
*
|
*
|
||||||
* @return array A list of the downloaded files
|
* @return array A list of the downloaded files
|
||||||
*/
|
*/
|
||||||
public function downloadBilingualFile(string $projectUid, array $jobUids, string $filename): array
|
public function download(string $projectUid, array $jobUids, string $filename): array
|
||||||
{
|
{
|
||||||
$url = "/api2/v1/projects/{$projectUid}/jobs/bilingualFile";
|
$url = "/api2/v1/projects/{$projectUid}/jobs/bilingualFile";
|
||||||
|
|
||||||
$groupedJobUids = array_chunk($jobUids, 100);
|
$groupedJobUids = array_chunk($jobUids, 100);
|
||||||
for ($i = 0; $i < count($groupedJobUids); $i++) {
|
for ($i = 0; $i < count($groupedJobUids); $i++) {
|
||||||
$apiReadyArray = $this->_convertUidArrayToApiRequest($groupedJobUids[$i]);
|
$apiReadyArray = $this->_convertUidArrayToApiRequest($groupedJobUids[$i]);
|
||||||
$filenames[$i] = count($groupedJobUids) > 1?"{$i}_{$filename}":$filename;
|
$filenames[$i] = count($groupedJobUids) > 1 ? "{$i}_{$filename}" : $filename;
|
||||||
$filecontent = $this->fetchApi->fetch('jsonPost', $url, $apiReadyArray);
|
$filecontent = $this->fetchApi->fetch('jsonPost', $url, $apiReadyArray);
|
||||||
$this->_saveIntoFile($filenames[$i], $filecontent);
|
$this->_saveIntoFile($filenames[$i], $filecontent);
|
||||||
}
|
}
|
||||||
@ -42,11 +43,11 @@ class BilingualFile extends \BrunoFontes\Memsource\BaseApi
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a simple Array of uids provided by the user into the array
|
* Convert a simple Array of uids provided by the user into the array
|
||||||
* format required by Memsource API
|
* format required by Memsource API
|
||||||
*
|
*
|
||||||
* @param array $uids A simple array of UIDs
|
* @param array $uids A simple array of UIDs
|
||||||
*
|
*
|
||||||
* @return array The API ready array
|
* @return array The API ready array
|
||||||
*/
|
*/
|
||||||
private function _convertUidArrayToApiRequest(array $uids): array
|
private function _convertUidArrayToApiRequest(array $uids): array
|
||||||
@ -73,10 +74,10 @@ class BilingualFile extends \BrunoFontes\Memsource\BaseApi
|
|||||||
*
|
*
|
||||||
* @param string $filename The filename to be uploaded
|
* @param string $filename The filename to be uploaded
|
||||||
* @param array $params Any API (HTTP GET) parameters as ['key' => 'value'] format
|
* @param array $params Any API (HTTP GET) parameters as ['key' => 'value'] format
|
||||||
*
|
*
|
||||||
* @return string The http request responde from API in json format
|
* @return string The http request responde from API in json format
|
||||||
*/
|
*/
|
||||||
public function uploadBilingualFile(string $filename, array $params): string
|
public function upload(string $filename, array $params): string
|
||||||
{
|
{
|
||||||
$urlParams = http_build_query($params);
|
$urlParams = http_build_query($params);
|
||||||
$fileContent = file_get_contents($filename);
|
$fileContent = file_get_contents($filename);
|
||||||
|
@ -10,7 +10,6 @@ namespace BrunoFontes\Memsource;
|
|||||||
|
|
||||||
class Jobs extends \BrunoFontes\Memsource\BaseApi
|
class Jobs extends \BrunoFontes\Memsource\BaseApi
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List jobs of a project
|
* List jobs of a project
|
||||||
* The API request returns a MAX of 50 Jobs.
|
* The API request returns a MAX of 50 Jobs.
|
||||||
@ -21,7 +20,7 @@ class Jobs extends \BrunoFontes\Memsource\BaseApi
|
|||||||
*
|
*
|
||||||
* @return string The JSON answer from Memsource
|
* @return string The JSON answer from Memsource
|
||||||
*/
|
*/
|
||||||
public function listJobs(string $projectUid, array $parameters = []): string
|
public function list(string $projectUid, array $parameters = []): string
|
||||||
{
|
{
|
||||||
$url = "/api2/v2/projects/{$projectUid}/jobs";
|
$url = "/api2/v2/projects/{$projectUid}/jobs";
|
||||||
return $this->fetchApi->fetch('get', $url, $parameters);
|
return $this->fetchApi->fetch('get', $url, $parameters);
|
||||||
|
@ -19,7 +19,7 @@ class Project extends \BrunoFontes\Memsource\BaseApi
|
|||||||
*
|
*
|
||||||
* @return string The JSON answer from Memsource
|
* @return string The JSON answer from Memsource
|
||||||
*/
|
*/
|
||||||
public function listProjects(array $queryParams = []): string
|
public function list(array $queryParams = []): string
|
||||||
{
|
{
|
||||||
return $this->fetchApi->fetch('get', $this->_url, $queryParams);
|
return $this->fetchApi->fetch('get', $this->_url, $queryParams);
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ class Project extends \BrunoFontes\Memsource\BaseApi
|
|||||||
*
|
*
|
||||||
* @return string A json string with all project info
|
* @return string A json string with all project info
|
||||||
*/
|
*/
|
||||||
public function getProject(string $projectUid): string
|
public function get(string $projectUid): string
|
||||||
{
|
{
|
||||||
return $this->fetchApi->fetch('get', "{$this->_url}/{$projectUid}");
|
return $this->fetchApi->fetch('get', "{$this->_url}/{$projectUid}");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user