PHP code example of onesky / api-library-php5

1. Go to this page and download the library: Download onesky/api-library-php5 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

onesky / api-library-php5 example snippets


use Onesky\Api\Client;

$client = new Client();

$client->setApiKey('<api-key>')->setSecret('<api-secret>');

// resource   => name of resource in camelcase with 's' tailing such as 'projectTypes', 'quotations', 'importTasks'
// action     => action to take such as 'list', 'show', 'upload', 'export'
// parameters => parameters passed in the request including URL param such as 'project_id', 'files', 'locale'
$client->{resource}('{action}', array({parameters}));
5
// list project groups
$response = $client->projectTypes('list');
$response = json_decode($response, true);

// show a project
$response = $client->projects('show', array('project_id' => 999));
$response = json_decode($response, true);

// upload file
$response = $client->files('upload', array(
    'project_id'  => 999,
    'file'        => 'path/to/string.yml',
    'file_format' => 'YAML',
    'locale'      => 'fr'
));
$response = json_decode($response, true);

// export translation
$response = $client->translations('export', array(
    'project_id' => 999,
    'locale'     => 'ja',
    'source_file_name' => 'string.yml'
));
file_put_contents('path/to/file', $response);

// create order
$response = $client->orders('create', array(
    'project_id' => 999,
    'files'      => 'string.yml',
    'to_locale'  => 'de'
));
$response = json_decode($response, true);