Memsource-API/README.md

132 lines
3.0 KiB
Markdown
Raw Normal View History

2019-06-22 00:15:48 +00:00
# PHP Memsource API
I am creating this Memsource API as a way to learn how to deal with one and to use with my next projects. I will not create the fully functional API here, but feel free to send a pull request if it were interesting for you.
There are other Memsource API repositories on GibHub that appears to be fully functional if you need it.
2019-06-25 01:06:43 +00:00
## Installing
Install it with [Composer](https://getcomposer.org/):
1. Create a `composer.json` file with the following content:
```json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/brunofontes/Memsource-API"
}
],
"require": {
"brunofontes/memsource-api": "*"
}
}
```
2. Run `php composer.phar install`
3. Add the following line on your .php file:
2019-06-25 01:06:43 +00:00
```php
require_once __DIR__ . '/vendor/autoload.php';
```
## Using
This repository returns a JSON string for almost any command.
If you are not sure how to use it, just convert it to an object or an array as follows:
2019-06-25 01:06:43 +00:00
```php
$myObject = json_decode($response);
$myArray = json_decode($response, true);
```
### Create an instance
```php
$memsource = new \BrunoFontes\Memsource();
```
- If you have already an access token, just include it:
```php
$memsource = new \BrunoFontes\Memsource($token);
```
### Getting an Access Token
2019-06-22 00:15:48 +00:00
To be able to use the Memsource API, you need an **access token**. In order to get it, just follow the instructions below.
2019-06-22 00:15:48 +00:00
2019-06-25 01:06:43 +00:00
#### Register as a developer on Memsource website
2019-06-22 00:15:48 +00:00
So you will receive your:
- *client id*
- *client secret*
2019-06-22 00:15:48 +00:00
2019-06-25 01:06:43 +00:00
#### Get an Authorization Code
2019-06-22 00:15:48 +00:00
```php
$memsourceUrl = $memsource->oauth()->getAuthorizationCodeUrl($cliend_id, $callback_uri);
2019-06-22 00:15:48 +00:00
```
Redirect your browser to this returned `$url` so the user can login via *oauth*.
2019-06-22 00:15:48 +00:00
The `$callback_uri` will be called by *Memsource* with a `$_GET['code']` that contains your Authorization Code, which you can use to...
2019-06-22 00:15:48 +00:00
2019-06-25 01:06:43 +00:00
#### Get an Access Token
2019-06-22 00:15:48 +00:00
```php
$authCode = $_GET['code'];
$token = $memsource->oauth()->getAccessToken($authCode, $client_id, $client_secret, $callback_uri);
```
Safely store this `$token` with the related user data and use it to instantiate the class whenever it were necessary.
2019-06-22 00:15:48 +00:00
2019-06-25 01:06:43 +00:00
### Project
2019-06-25 01:06:43 +00:00
#### Project list
To list all projects:
```php
$projectList = $memsource->project()->listProjects;
```
To use filters, add the API filter as parameter:
```php
$projectList = $memsource->project()->listProjects(['name' => 'Project X']);
```
#### Get Project
```php
$projectList = $memsource->project()->getProject($projectUid);
```
### Jobs
2019-06-25 01:06:43 +00:00
#### List Jobs
2019-06-25 01:06:43 +00:00
Only projectUid is essencial:
2019-06-25 01:06:43 +00:00
```php
$jobs = $memsource->jobs()->listJobs($projectUid, ['count' => true, 'filename' => 'my_file.html']);
2019-06-25 01:06:43 +00:00
```
### Bilingual Files
2019-06-22 00:15:48 +00:00
#### Download Bilingual File
```php
$memsource->BilingualFile()->downloadBilingualFile($projectUid, ['JobUid1', 'jobUid2'], 'download.mxliff');
```
#### Upload Bilingual File
```php
$parameters = ['format' => 'MXLF', 'saveToTransMemory' => 'None', 'setCompleted' => 'false'];
$result = $api->bilingualFile()->uploadBilingualFile('upload.mxliff', $parameters);
```