2017 © Pedro Peláez
 

library algorithmia-php-sdk

This is a php sdk for the algorithmia.com API

image

wimkumpen/algorithmia-php-sdk

This is a php sdk for the algorithmia.com API

  • Monday, June 4, 2018
  • by wimkumpen
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP SDK FOR ALGORITHMIA API

This is a php sdk for the algorithmia.com API. It only supports curl at this moment and give response back as an array., (*1)

Setup:

Add a composer.json file to your project:, (*2)

{
  "require": {
      "wimkumpen/algorithmia-php-sdk": "dev-master"
  }
}

Then provided you have composer installed, you can run the following command:, (*3)

$ composer.phar install

Or install by:, (*4)

composer.phar require wimkumpen/algorithmia-php-sdk:dev-master

That will fetch the library and its dependencies inside your vendor folder. Then you can add the following to your .php files in order to use the library, (*5)

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

Then you need to use the relevant classes, for example:, (*6)

use Algorithmia\Algo;     // for calls to algorithmes
use Algorithmia\Connector // for the data connections

Basic usage Algo:

http://docs.algorithmia.com/?shell#api-specification, (*7)

$app = new \Algorithmia\Algo(array(
    'default_access_token' => 'YOUR_API_KEY',
    'version' => 'v1',
    false
));

Make your alogirthm calls, this will return Algorithmia\Http\DataResponse object, (*8)

try {
    // basic algorithm 1
    $algorithmia = $app->algo("demo/Hello", ['yourname']);
    $response = $algorithmia->call();

    // basic algorithm 2
    $algorithmia = $app->algo("WebPredict/ListAnagrams/0.1", ["transformer", "terraforms", "retransform"]);
    $response = $algorithmia->call();

    // call algorithm with file
    $curlFile = new \CurlFile("/path/to/file/test.jpg");

    $algorithmia = $app->algo("opencv/SmartThumbnail/0.1", $curlFile, ["Content-Type" => "application/octet-stream"]);
    $response = $algorithmia->call();

} catch(\Algorithmia\Exceptions\ResponseException $e) {
    var_dump($e->getMessage());die;
} Catch(\Algorithmia\Exceptions\AuthorizationException $e) {
    var_dump($e->getMessage());die;
}

Basic usage Connector:

http://docs.algorithmia.com/?shell#data-api-specification, (*9)

$app = new \Algorithmia\Connector(array(
    'default_access_token' => 'YOUR_API_KEY',
    'version' => 'v1',
    false
));

Api folder request, returning a \Algorithmia\Http\DirectoryResponse instance, (*10)

try {
    $response = $app->getDir("data" ,".my", "", false);
    $response = $app->createDir("data" ,".my", ['name' => 'elvis', 'acl' => ['read' => []]]);
    $response = $app->updateDir("data" ,".my/elvis", ['acl' => ['read' => []]]);
    $response = $app->deleteDir("data" ,".my/elvis", true);
} catch(\Algorithmia\Exceptions\ResponseException $e) {
    var_dump($e->getMessage());die;
} Catch(\Algorithmia\Exceptions\AuthorizationException $e) {
    var_dump($e->getMessage());die;
}

Api file request, returning a \Algorithmia\Http\FileResponse instance, (*11)

try {
    $response = $app->uploadFile("data" ,".my/elvis/testfile.txt", array("file content"));
    $response = $app->deleteFile("data" ,".my/elvis/testfile.txt");
    $response = $app->fileExist("data" ,".my/elvis/testfile.txt");
    $response = $app->getFile("data" ,".my/elvis/testfile.txt");

    $file = new CURLFile("/path/to/file/newfile.txt");
    $response = $app->uploadFile("data" ,".my/elvis/newfile.txt", [$file], ["Content-Type" => "application/x-www-form-urlencoded"]);
} catch(\Algorithmia\Exceptions\ResponseException $e) {
    var_dump($e->getMessage());die;
} Catch(\Algorithmia\Exceptions\AuthorizationException $e) {
    var_dump($e->getMessage());die;
}

Todo:

  • [ ] Clean some code out;
  • [ ] Create examples
  • [ ] Exceptions;
  • [ ] Automated tested;
  • [ ] Implement other Http Clients;
  • [ ] Define requirements;

The Versions

04/06 2018

dev-master

9999999-dev https://github.com/wimkumpen/algorithmia-php-sdk

This is a php sdk for the algorithmia.com API

  Sources   Download

MIT

The Requires

 

api php ai algorithmia.com algorithmia