2017 © Pedro Peláez
 

library onlineconvert-api-sdk

Sdk for using the Online Convert Api version 2

image

qaamgo/onlineconvert-api-sdk

Sdk for using the Online Convert Api version 2

  • Wednesday, July 18, 2018
  • by onlineconvert
  • Repository
  • 6 Watchers
  • 12 Stars
  • 8,476 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 10 Forks
  • 0 Open issues
  • 29 Versions
  • 6 % Grown

The README.md

Online Convert API version 2 PHP SDK v 3

This SDK provides a code base to interact with the API version 2 of Online-Convert.com, (*1)

Tests, (*2)

Installation

The recommended way to install is through Composer., (*3)

composer require qaamgo/onlineconvert-api-sdk

Getting started

Configuration

require 'vendor/autoload.php';

$config = new \OnlineConvert\Configuration();
$config->setApiKey('main', 'HERE YOUR API KEY');
$client = new \OnlineConvert\Client\OnlineConvertClient($config, 'main');
$syncApi = new \OnlineConvert\Api($client);
$asyncApi = new \OnlineConvert\Api($client, true);

Sending a full job

$syncJob = [
    'input' => [
        [
        'type' => \OnlineConvert\Endpoint\InputEndpoint::INPUT_TYPE_UPLOAD,
        'source' => '~/example.png'
        ],
        [
        'type' => \OnlineConvert\Endpoint\InputEndpoint::INPUT_TYPE_REMOTE,
        'source' => 'http://cdn.online-convert.com/images/logo-top.png'
        ]
    ],
    'conversion' => [
        [
        'target' => 'png'
        ],
        [
        'target' => 'mp4'
        ]
    ]
];

$asyncJob = [
    'input' => [
        [
        'type' => \OnlineConvert\Endpoint\InputEndpoint::INPUT_TYPE_UPLOAD,
        'source' => '~/example.png'             ],
        [
        'type' => \OnlineConvert\Endpoint\InputEndpoint::INPUT_TYPE_REMOTE,
        'source' => 'http://cdn.online-convert.com/images/logo-top.png'
        ]
    ],
    'conversion' => [
        [
        'target' => 'png'
        ],
        [
        'target' => 'mp4'
        ]
    ],
    'callback' => 'http://alert.me/when/job/is/finished'
];

$syncJob = $syncApi->postFullJob($syncJob)->getJobCreated();
$asyncJob = $asyncApi->postFullJob($asyncJob)->getJobCreated();

var_dump($syncJob, $asyncJob);

Sending a job with a gdrive_picker input

What is google drive picker

Google drive picker allows you to access files stored in your google drive account., (*4)

You can find information about it in the official page, (*5)

Meaning of each field: * type * Specifies that we want to use the google drive picker input * source * This must contain the FILE ID given back by the google drive picker * credentials * This must be an array containing the credentials for the selected file * At the moment you only need to pass the "token" field inside it * The "token" field is returned by the google drive picker when a file is selected * content_type * This field is mandatory when you select a Google Document * You can leave this field empty if you are selecting any other kind of file * EG: pdf, png, zip... * filename * This is the file name of the google drive picker file * If this field is not sent the file will be downloaded with the name output.<extension>, (*6)

$job = [
    'input' => [
        [
            'type' => \OnlineConvert\Endpoint\InputEndpoint::INPUT_TYPE_GDRIVE_PICKER,
            'source' => '<put google drive picker file id here>',
            'credentials' => [
                'token' => '<put google drive picker token for the selected file here>'
            ],
            'content_type' => '<if this is a specific google document>',
            'filename' => '<name of the input file>'
        ]
    ],
    'conversion' => [
        [
            'target' => 'png'
        ]
    ]
];

After this just follow the previous examples on how to effectively send the job to the API., (*7)

Sending a job using Cloud storage providers

The following is an example to send a job where we want to convert a file that we have stored in our Amazon S3 storage., (*8)

If you want to know more please check our cloud storage API documentation, (*9)

$job = [
    'input' => [
        [
            'type' => \OnlineConvert\Endpoint\InputEndpoint::INPUT_TYPE_CLOUD,
            'source' => 'amazons3',
            'parameters' => [
                'bucket' => 'your.bucket.name',
                'file' => 'the complete path to the file',
            ],
            'credentials' => [
                'accesskeyid' => 'your access key id',
                'secretaccesskey' => 'your secret access key',
            ]
        ]
    ],
    'conversion' => [
        [
            'target' => 'png'
        ]
    ]
];

After this just follow the previous examples on how to effectively send the job to the API., (*10)

Downloading the Converted Files

You can download the converted files using the following code snippet:, (*11)

require_once __DIR__ . '/vendor/autoload.php';

$config = new \OnlineConvert\Configuration();
$config->setApiKey('main', 'PUT YOUR API KEY HERE');

// Remember to specify your own downloads folder.
$config->downloadFolder = __DIR__ . '/downloads';

$client = new \OnlineConvert\Client\OnlineConvertClient($config, 'main');
$syncApi = new \OnlineConvert\Api($client);
$outputEndpoint = $syncApi->getOutputEndpoint();

$syncJob = [
    'input' => [
        [
            'type' => \OnlineConvert\Endpoint\InputEndpoint::INPUT_TYPE_REMOTE,
            'source' => 'PUT URL HERE'
        ]
    ],
    'conversion' => [
        [
            'target' => 'jpg'
        ]
    ]
];

$job = $syncApi->postFullJob($syncJob)->getJobCreated();

// You will find the file/s in the downloads folder
$outputEndpoint->downloadOutputs($job);

Advanced usage

The class \OnlineConvert\Api::class has some shortcut methods that links it to the endpoints classes (EG: \OnlineConvert\Api::postFullJob()), but from the class you can call the real endpoint and their methods., (*12)

Also, you can create endpoint classes one by one if you like. For this, check \OnlineConvert\Endpoint\Abstracted::_construct(), (*13)

IMPORTANT: The class \OnlineConvert\Endpoint\JobsEndpoint can be used to send both synchronous and asynchronuos jobs; check \OnlineConvert\Endpoint\JobsEndpoint::setAsync(), (*14)

You can also set up different headers into the client, and do some process using the token of a job., (*15)

    $config = new \OnlineConvert\Configuration();
    $client = new \OnlineConvert\Client\OnlineConvertClient($config);
    $syncApi = new \OnlineConvert\Api($client);

    $ep = $syncApi->getJobsEndpoint();

    //Option 1
    $ep->getClient()->setHeader(\OnlineConvert\Client\Interfaced::HEADER_OC_API_KEY, 'YOUR API KEY');

    //Option 2
    //$client->setHeader(\OnlineConvert\Client\Interfaced::HEADER_OC_API_KEY, 'YOUR API KEY');
    //$ep->setClient($client);

    $job = $ep->postJob([]);

    $ip = $syncApi->getInputEndpoint();

    //WORK WITH TOKENS
    //OPTION 1
    $input = $ip->setUserToken($a['token'])->postJobInputRemote('http://www.online-convert.com/', $a['id']);

    //Option 2 (Apply also the previous options to set a header)
    //$ip->getClient()->setHeader(\OnlineConvert\Client\Interfaced::HEADER_OC_JOB_TOKEN, $a['token']);
    //$b = $ip->postJobInputRemote('http://www.online-convert.com/', $a['id']);

    var_dump($job, $input);

Manage exceptions

If you catch \OnlineConvert\Exception\OnlineConvertSdkException::class, you automatically catch all exception in this SDK, (*16)

Getting url to upload file

  • Send a job request
  • Take the following keys from a job: server and id. You can use \OnlineConvert\Api or \OnlineConvert\Endpoint\JobsEndpoint to get the job information. You will get something like:
    [
        [id] => 00000000-0000-0000-0000-000000000000
        [token] => some_token_here
            ...
        [server] => http://www9.online-convert.com/dl
        ...
    ]
  • Now with this information you can make this call:
\OnlineConvert\Client\OnlineConvertClient->generateUrl(\OnlineConvert\Endpoint\Resources::URL_POST_FILE, ['server' => $server, 'job_id' => $jobId])
  • Also these token can be useful for some operations that you might want to share with your users

Uploading files directly to the Online-Convert.com servers via AJAX

Real life case: I want to send our user files directly to the API, because sending them to my app first and then to the API costs too much time., (*17)

Considerations: Normally, this will save us process time, space on the hard drive and improve user experience, but it's advised to have a fallback alternative that works without using JS., (*18)

The following example is using JQuery., (*19)

IMPORTANT: The upload MUST be done one by one. Thus, you need one form per file., (*20)

HTML CODE

<form id="postFile" enctype="multipart/form-data" method="post" action="javascript:;" accept-charset="utf-8">
        <input name="file" type="file" id="file"/> <input type="submit" id="upload-btn"/>
</form>

JS

$(document).ready(function () {
        $('#postFile').submit(function (event) {
            event.preventDefault();

            var formData = new FormData($(this)[0]);

            $.ajax({
                url: 'URL_GENERATED_TO_UPLOAD_FILE',
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                processData: false,
                contentType: false,
                mimeType: 'multipart/form-data',
                headers: {
                    'x-oc-token': 'JOB_TOKEN_HERE',
                    'cache-control': 'no-cache'
                },
                success: function () {
                    window.alert('Success');
                },
                error: function () {
                    window.alert('Error');
                }
            });
        });
    });

The Versions

18/07 2018

dev-master

9999999-dev

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache-2.0 Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

18/07 2018

2.8.1

2.8.1.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

17/07 2018

2.8.0

2.8.0.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

11/05 2018

2.7.9

2.7.9.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

27/03 2018

2.7.8

2.7.8.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

12/02 2018

2.7.7

2.7.7.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

09/01 2018

2.7.6

2.7.6.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

12/12 2017

2.7.5

2.7.5.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

28/11 2017

2.7.4

2.7.4.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

02/11 2017

2.7.3

2.7.3.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

25/07 2017

2.7.2

2.7.2.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

07/07 2017

2.7.1

2.7.1.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

17/05 2017

2.7.0

2.7.0.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

05/04 2017

2.6.2

2.6.2.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

05/04 2017

2.6.1

2.6.1.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

22/02 2017

2.6.0

2.6.0.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

01/02 2017

2.5.1

2.5.1.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

27/01 2017

2.5.0

2.5.0.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

20/01 2017

2.4.1

2.4.1.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

19/01 2017

2.4

2.4.0.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

12/01 2017

2.3

2.3.0.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

14/11 2016

2.2

2.2.0.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

08/11 2016

2.1

2.1.0.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

26/08 2016

2.0

2.0.0.0

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

 

The Development Requires

api php rest files sdk convert qaamgo online-convert

05/10 2015

1.3

1.3.0.0 https://github.com/onlineconvert/onlineconvert-api-sdk-php

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

  • php >=5.3.3
  • ext-curl *
  • ext-json *
  • ext-mbstring *

 

The Development Requires

api php rest swagger sdk qaamgo

10/08 2015

dev-develop

dev-develop https://github.com/onlineconvert/onlineconvert-api-sdk-php

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

  • php >=5.3.3
  • ext-curl *
  • ext-json *
  • ext-mbstring *

 

The Development Requires

api php rest swagger sdk qaamgo

15/07 2015

1.2

1.2.0.0 https://github.com/onlineconvert/onlineconvert-api-sdk-php

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

  • php >=5.3.3
  • ext-curl *
  • ext-json *
  • ext-mbstring *

 

The Development Requires

api php rest swagger sdk qaamgo

10/07 2015

1.1

1.1.0.0 https://github.com/onlineconvert/onlineconvert-api-sdk-php

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

  • php >=5.3.3
  • ext-curl *
  • ext-json *
  • ext-mbstring *

 

The Development Requires

api php rest swagger sdk qaamgo

09/07 2015

1.0

1.0.0.0 https://github.com/onlineconvert/onlineconvert-api-sdk-php

Sdk for using the Online Convert Api version 2

  Sources   Download

Apache V2

The Requires

  • php >=5.3.3
  • ext-curl *
  • ext-json *
  • ext-mbstring *

 

The Development Requires

api php rest swagger sdk qaamgo