2017 © Pedro Peláez
 

library box-view-api

PHP SDK for the Box View API.

image

donutdan4114/box-view-api

PHP SDK for the Box View API.

  • Tuesday, December 1, 2015
  • by donutdan4114
  • Repository
  • 4 Watchers
  • 14 Stars
  • 3,371 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 13 Forks
  • 6 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

Box View PHP SDK

NOTE: No longer supported. Check out the official Box View PHP SDK., (*1)

Created by Daniel Pepin @ CommonPlaces, Inc
Sponsored by LawJacked, (*2)


Documentation

For general API documentaion, please review the Box View API Documentation., (*3)

To get started, Include the required classes:, (*4)

require 'lib/box-view-api.php';
require 'lib/box-view-document.php';

Intializing the API class:, (*5)

$api_key = 'YOUR_API_KEY';
$box = new Box_View_API($api_key);

Creating a document to upload:, (*6)

$doc = new Box_View_Document();
$doc->name = 'My Awesome Document';
$doc->file_url = 'http://my-public-url';
$doc->thumbnails = '128×128,256×256'; // Comma-separated list of thumbnail dimensions of the format {width}x{height} e.g. 128×128,256×256
$doc->non_svg = false; // boolean (default=false)

Uploading a document to the API:, (*7)

$box->upload($doc);

You can also upload local files through the API:, (*8)

$doc = new Box_View_Document(array(
  'name' => 'My Local File',
  'file_path' => '/path/to/file/CV_Template1.doc',
));
$box->upload($doc);

Uploading an array of documents to the API:, (*9)

// Create array of Box_View_Document objects.
$docs[] = new Box_View_Document(array('file_url' => 'http://foo.bar/why-cats-purrrr.pdf'));
$docs[] = new Box_View_Document(array('file_url' => 'http://foo.bar/10-ways-to-love-your-cat.docx'));
$docs[] = new Box_View_Document(array('file_url' => 'http://foo.bar/funny-cat-links.xlsx'));

// Wrap API calls in try/catch.
try
{
  $box->uploadMultiple($docs);
}
catch(Exception $e)
{
  log('error', $e->getMessage());
}

After some time, the document will be processed and can be viewed:, (*10)

$box->view($doc);
echo $doc->session->url; // Links to the HTML5 document.

Embed the document in an iframe., (*11)

<iframe src="<?= $doc->session->url ?>"></iframe>

Retrieve a thumbnail image of the first page of a document. Thumbnails can have a width between 16 and 1024 pixels and a height between 16 and 768 pixels., (*12)

$img = $box->getThumbnail($doc, $width, $height);
<img src="data:image/png;base64,<?= base64_encode($img) ?>"/>

Showing a PDF version of the file., (*13)

$box->getPDF($doc);
header('Content-Type: application/pdf');
print $doc->content->pdf;

Getting a Zip folder containing the HTML5 files for the document:, (*14)

$box->getZip($doc);
file_put_contents($doc->name . '.zip', $doc->content->zip);
// Unzip the file.

Deleting the document:, (*15)

$box->delete($doc);

Handling Exceptions

API calls will throw an instance of Box_View_Exception when an error is encountered.
You should wrap your API calls with a try/catch., (*16)

try
{
  $box->upload($doc);
}
catch(Exception $e)
{
  log('error', $e->getMessage(), $http_code = $e->getCode());
}

The Versions

01/12 2015

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/donutdan4114/box-view-api

PHP SDK for the Box View API.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • lib-curl *

 

03/12 2013

v1.0-beta1

1.0.0.0-beta1 https://github.com/donutdan4114/box-view-api

PHP SDK for the Box View API.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • lib-curl *