Skip to content

kaiwa/clsi-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLSI Client Library

For sending LaTeX files to a compile server using the "Common LaTeX Service Interface"-API.

This library creates psr7-compatible http requests, so you can use any psr7-compatible http client for sending the created requests. You may take a look here for finding an http client.

For a CLSI server implementation see https://github.com/sharelatex/clsi-sharelatex

Usage

Guzzle client example

For the guzzle http client there is the GuzzleCompileRequestSender class included. It takes care of transforming the CompileRequest into an http request and also transforming the http response back into a CompileResponse.

You will need to require the suggested guzzlehttp/guzzle composer package.

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

use Kaiwa\Clsi as Clsi;

$compileRequest = new Clsi\Request\CompileRequest(
    'http://myclsiserver.com:3013',
    'myprojectId',
    new Clsi\Request\Resource\TextFileResource(__DIR__.'/test.tex')
);

// Optional: Add more resources
// $compileRequest->addResources(
//      new Clsi\Request\Resource\UrlResource('logo.png', 'http://myserver.com/logo.png')
// );

$sender = new Clsi\Bridge\Guzzle\GuzzleCompileRequestSender();
$compileResponse = $sender->send($compileRequest);

$compiledPdfUrl = $compileResponse->getOutputFile('pdf');

Any other psr7-compatible http client example

If you want to use any other psr7-compatible http client (or a particular Guzzle instance) you have to transform the CompileRequest into an http request and the http response into a CompileResponse manually.

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

use Kaiwa\Clsi as Clsi;

$compileRequest = new Clsi\Request\CompileRequest(
    'http://myclsiserver.com:3013',
    'myprojectId',
    new Clsi\Request\Resource\TextFileResource(__DIR__.'/test.tex')
);

// Optional: Add more resources
// $compileRequest->addResources(
//      new Clsi\Request\Resource\UrlResource('logo.png', 'http://myserver.com/logo.png')
// );

$compileRequestFactory  = new Clsi\Psr\PsrCompileRequestFactory();
$compileResponseFactory = new Clsi\Psr\PsrCompileResponseFactory();

// initiate your http client
$httpClient = new HttpClient();

// Transform the CompileRequest into an http request
$httpRequest = $compileRequestFactory->makePsrRequest($compileRequest);

// Send the http request with your client and get the response
$httpResponse    = $httpClient->send($httpRequest);

// Transform the http response into a CompileResponse
$compileResponse = $compileResponseFactory->makeCompileResponse($httpResponse);

// Work with the CompileResponse
$compiledPdfUrl = $compileResponse->getOutputFile('pdf');

About

Client library for sending LaTeX files to a CLSI server for compiling

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages