Go to file
Bruno Fontes c88478f7d8
Includes file extension on bilingual download
It is important to choose the file extension, so including it on the
filename would be the easier way for us, as we already have the
extension when using it.
2021-02-11 18:25:32 -03:00
src Includes file extension on bilingual download 2021-02-11 18:25:32 -03:00
tests Includes file extension on bilingual download 2021-02-11 18:25:32 -03:00
.gitignore Avoiding composer.lock to be commited 2019-06-28 00:58:33 -03:00
composer.json Improving Makefile and PHPUNIT dependency on composer.json 2019-06-28 02:21:55 -03:00
LICENSE Trying to make composer.json to be used directly from GitHub 2019-06-24 21:33:30 -03:00
Makefile Improving Makefile and PHPUNIT dependency on composer.json 2019-06-28 02:21:55 -03:00
pre-push.sh Improving Makefile and PHPUNIT dependency on composer.json 2019-06-28 02:21:55 -03:00
README.md Fixing README command with wrong function name 2019-06-25 20:35:31 -03: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.

Installing

Install it with Composer:

  1. Create a composer.json file with the following content:
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/brunofontes/Memsource-API"
        }
    ],
    "require": {
        "brunofontes/memsource-api": "*"
    }
}
  1. Run php composer.phar install
  2. Add the following line on your .php file:
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:

$myObject = json_decode($response);
$myArray = json_decode($response, true);

Create an instance

$memsource = new \BrunoFontes\Memsource();
  • If you have already an access token, just include it:
$memsource = new \BrunoFontes\Memsource($token);

Getting an Access Token

To be able to use the Memsource API, you need an access token. In order to get it, just follow the instructions below.

Register as a developer on Memsource website

So you will receive your:

  • client id
  • client secret

Get an Authorization Code

$memsourceUrl = $memsource->oauth()->getAuthorizationCodeUrl($cliend_id, $callback_uri);

Redirect your browser to this returned $url so the user can login via oauth.

The $callback_uri will be called by Memsource with a $_GET['code'] that contains your Authorization Code, which you can use to...

Get an Access Token

$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.

Project

Project list

To list all projects:

$projectList = $memsource->project()->list;

To use filters, add the API filter as parameter:

$projectList = $memsource->project()->list(['name' => 'Project X']);

Get Project

$projectList = $memsource->project()->get($projectUid);

Jobs

List Jobs

Only projectUid is essencial:

$jobs = $memsource->jobs()->list($projectUid, ['count' => true, 'filename' => 'my_file.html']);

Bilingual Files

Download Bilingual File

$memsource->BilingualFile()->download($projectUid, ['JobUid1', 'jobUid2'], 'download.mxliff');

Upload Bilingual File

$parameters = ['format' => 'MXLF', 'saveToTransMemory' => 'None', 'setCompleted' => 'false'];
$result = $api->bilingualFile()->upload('upload.mxliff', $parameters);