diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85d346a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor +.DS_Store diff --git a/README.md b/README.md index 34f8a3c..7fca8a0 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,14 @@ -# PHP client library for encoding videos with Coconut +# Coconut PHP Library -## Install +The Coconut PHP library provides access to the Coconut API for encoding videos, packaging media files into HLS and MPEG-Dash, generating thumbnails and GIF animation. + +This library is only compatible with the Coconut API v2. + +## Documentation + +See the [full documentation](https://docs.coconut.co). + +## Installation To install the Coconut PHP library, you need [composer](http://getcomposer.org) first: @@ -13,7 +21,7 @@ Edit `composer.json`: ```javascript { "require": { - "opencoconut/coconut": "2.*" + "opencoconut/coconut": "3.*" } } ``` @@ -24,101 +32,71 @@ Install the depencies by executing `composer`: php composer.phar install ``` -## Submitting the job - -Use the [API Request Builder](https://app.coconut.co/job/new) to generate a config file that match your specific workflow. - -Example of `coconut.conf`: +## Usage -```ini -var s3 = s3://accesskey:secretkey@mybucket - -set webhook = http://mysite.com/webhook/coconut?videoID=$vid - --> mp4 = $s3/videos/video_$vid.mp4 --> webm = $s3/videos/video_$vid.webm --> jpg:300x = $s3/previews/thumbs_#num#.jpg, number=3 -``` - -Here is the PHP code to submit the config file: +The library needs you to set your API key which can be found in your [dashboard](https://app.coconut.co/api). Webhook URL and storage settings are optional but are very convenient because you set them only once. ```php 'k-api-key', - 'conf' => 'coconut.conf', - 'source' => 'http://yoursite.com/media/video.mp4', - 'vars' => array('vid' => 1234) -)); - -if($job->{'status'} == 'processing') { - echo $job->{'id'}; -} else { - echo $job->{'error_code'}; - echo $job->{'error_message'}; +$coconut = new Coconut\Client('k-api-key'); + +$coconut.notification = [ + 'type' => 'http', + 'url' => 'https://yoursite/api/coconut/webhook' +]; + +$coconut.storage = [ + 'service' => 's3', + 'bucket' => 'my-bucket', + 'region' => 'us-east-1', + 'credentials' => { + 'access_key_id' => 'access-key', + 'secret_access_key' => 'secret-key' + } } ?> ``` -You can also create a job without a config file. To do that you will need to give every settings in the method parameters. Here is the exact same job but without a config file: +## Creating a job ```php 'k-api-key', - 'source' => 'http://yoursite.com/media/video.mp4', - 'webhook' => 'http://mysite.com/webhook/coconut?videoId=' . $vid, - 'outputs' => array( - 'mp4' => $s3 . '/videos/video_' . $vid . '.mp4', - 'webm' => $s3 . '/videos/video_' . $vid . '.webm', - 'jpg:300x' => $s3 . '/previews/thumbs_#num#.jpg, number=3' - ) -)); +try { + $job = $coconut->job->create([ + 'input' => [ 'url' => 'https://mysite/path/file.mp4' ], + 'outputs' => [ + 'jpg:300x' => [ 'path' => '/image.jpg' ], + 'mp4:1080p' => [ 'path' => '/1080p.mp4' ], + 'httpstream' => [ + 'hls' => [ 'path' => 'hls/' ] + ] + ] + ]); + + print_r($job); + +} cacth(Exception $e) { + echo $e->getMessage(); +} ?> ``` -Other example usage: +## Getting information about a job ```php - +$job = $coconut->job->retrieve('OolQXaiU86NFki'); ``` -Note that you can use the environment variable `COCONUT_API_KEY` to set your API key. +## Retrieving metadata -## Contributing - -1. Fork it -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Added some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request - - -*Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).* - ---- +```php +$metadata = $coconut->metadata->retrieve('OolQXaiU86NFki'); +``` -* Coconut website: http://coconut.co -* API documentation: http://coconut.co/docs -* Contact: [support@coconut.co](mailto:support@coconut.co) -* Twitter: [@OpenCoconut](http://twitter.com/opencoconut) +*Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).* \ No newline at end of file diff --git a/composer.json b/composer.json index 7dc5064..729385b 100755 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { "name": "opencoconut/coconut", "type": "library", - "version": "2.8.0", + "version": "3.0.0", "description": "Coconut is a Cloud Video Encoding Service built for developers", "keywords": ["video", "encoding", "transcoding", "web service", "h264", "cloud"], - "homepage": "http://coconut.co", + "homepage": "https://coconut.co", "license": "MIT", "authors": [ { diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..a82b572 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1536 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "d97ebb29efb3013e1430e63e5c5619fd", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "a2c590166b2133a4633738648b6b064edae0814a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2019-03-17T17:37:11+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.9.3", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2019-08-09T12:45:53+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/2df402786ab5368a0169091f61a7c1e0eb6852d0", + "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^1.0.1", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "role": "Developer", + "email": "arne@blankerts.de" + }, + { + "name": "Sebastian Heuer", + "role": "Developer", + "email": "sebastian@phpeople.de" + }, + { + "name": "Sebastian Bergmann", + "role": "Developer", + "email": "sebastian@phpunit.de" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2017-03-05T18:14:27+00:00" + }, + { + "name": "phar-io/version", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2017-03-05T17:38:23+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2017-09-11T18:02:19+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "4.3.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "shasum": "" + }, + "require": { + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2019-04-30T17:48:53+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "shasum": "" + }, + "require": { + "php": "^5.5 || ^7.0", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2017-07-14T14:27:02+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Prophecy\\": "src/Prophecy" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2019-06-13T12:50:23+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "6.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "4cab20a326d14de7575a8e235c70d879b569a57a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4cab20a326d14de7575a8e235c70d879b569a57a", + "reference": "4cab20a326d14de7575a8e235c70d879b569a57a", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^7.1", + "phpunit/php-file-iterator": "^1.4.2", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^3.0", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^3.1", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "suggest": { + "ext-xdebug": "^2.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2018-05-28T11:49:20+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2017-11-27T13:52:08+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "2.1.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2019-06-07T04:22:29+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e899757bb3df5ff6e95089132f32cd59aac2220a", + "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2019-07-25T05:29:42+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "7.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "9b3373439fdf2f3e9d1578f5e408a3a0d161c3bc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9b3373439fdf2f3e9d1578f5e408a3a0d161c3bc", + "reference": "9b3373439fdf2f3e9d1578f5e408a3a0d161c3bc", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "^1.6.1", + "phar-io/manifest": "^1.0.1", + "phar-io/version": "^1.0", + "php": "^7.1", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^6.0", + "phpunit/php-file-iterator": "^1.4.3", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^2.0", + "phpunit/phpunit-mock-objects": "^6.0", + "sebastian/comparator": "^2.1", + "sebastian/diff": "^3.0", + "sebastian/environment": "^3.1", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^2.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^1.0", + "sebastian/version": "^2.0.1" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "^2.0" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2018-02-02T05:04:08+00:00" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "6.1.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "f9756fd4f43f014cb2dca98deeaaa8ce5500a36e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/f9756fd4f43f014cb2dca98deeaaa8ce5500a36e", + "reference": "f9756fd4f43f014cb2dca98deeaaa8ce5500a36e", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.5", + "php": "^7.1", + "phpunit/php-text-template": "^1.2.1", + "sebastian/exporter": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "abandoned": true, + "time": "2018-05-29T13:54:20+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, + { + "name": "sebastian/comparator", + "version": "2.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/diff": "^2.0 || ^3.0", + "sebastian/exporter": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2018-02-01T13:46:46+00:00" + }, + { + "name": "sebastian/diff", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.5 || ^8.0", + "symfony/process": "^2 || ^3.3 || ^4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "time": "2019-02-04T06:01:07+00:00" + }, + { + "name": "sebastian/environment", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2017-07-01T08:51:00+00:00" + }, + { + "name": "sebastian/exporter", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "06a9a5947f47b3029d76118eb5c22802e5869687" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/06a9a5947f47b3029d76118eb5c22802e5869687", + "reference": "06a9a5947f47b3029d76118eb5c22802e5869687", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2019-08-11T12:43:14+00:00" + }, + { + "name": "sebastian/global-state", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2017-04-27T15:39:26+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-08-03T12:35:26+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29T09:07:27+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2017-03-03T06:23:57+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28T20:34:47+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.12.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.12-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2019-08-06T08:03:45+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "role": "Developer", + "email": "arne@blankerts.de" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2019-06-13T22:48:21+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.36 || ^7.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2019-08-24T08:43:50+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/composer.phar b/composer.phar new file mode 100755 index 0000000..389bf5a Binary files /dev/null and b/composer.phar differ diff --git a/make_tests b/make_tests new file mode 100755 index 0000000..edfe1d9 --- /dev/null +++ b/make_tests @@ -0,0 +1,3 @@ +#!/bin/bash + +vendor/bin/phpunit --bootstrap vendor/autoload.php tests/CoconutTest diff --git a/src/API.php b/src/API.php new file mode 100644 index 0000000..72fde35 --- /dev/null +++ b/src/API.php @@ -0,0 +1,50 @@ +cli = $cli; + } + + function request($method, $path, $data=array()) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->cli->getEndpoint() . $path); + curl_setopt($ch, CURLOPT_USERPWD, $this->cli->api_key . ":"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_USERAGENT, self::USER_AGENT); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json', + 'Accept: application/json' + ]); + + if($method == "POST") { + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + } + + $result = curl_exec($ch); + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $curl_err = curl_errno($ch); + + curl_close($ch); + + if (!$curl_err) { + if($http_code > 399) { + if($http_code == 400 || $http_code == 401) { + $err = json_decode($result); + throw new Error($err->{"message"} . " (" . $err->{"error_code"} . ")"); + } else { + throw new Error("Server returned HTTP status ". $http_code . " (server_error)"); + } + } + } else { + throw new Error("A Curl Error occured (request_error)"); + } + return json_decode($result); + } +} + +?> \ No newline at end of file diff --git a/src/Client.php b/src/Client.php new file mode 100644 index 0000000..a0522ce --- /dev/null +++ b/src/Client.php @@ -0,0 +1,47 @@ +api_key = $api_key; + + if($config["region"]) { + $this->region = $config["region"]; + } + + if($config["endpoint"]) { + $this->endpoint = $config["endpoint"]; + } + + if($config["storage"]) { + $this->storage = $config["storage"]; + } + + if($config["notification"]) { + $this->notification = $config["notification"]; + } + + $this->api = new API($this); + + $this->job = new Job($this); + $this->metadata = new Metadata($this); + } + + function getEndpoint() { + if ($this->endpoint != null) { + return $this->endpoint; + } + + if($this->region != null) { + return "https://api-" . $this->region . ".coconut.co/v2"; + } + + return self::ENDPOINT; + } +} + +?> \ No newline at end of file diff --git a/src/Coconut.php b/src/Coconut.php index 7a21856..24ac06b 100755 --- a/src/Coconut.php +++ b/src/Coconut.php @@ -4,142 +4,8 @@ class Coconut { - const COCONUT_URL = "https://api.coconut.co"; - const USER_AGENT = "Coconut/2.6.0 (PHP)"; + const VERSION = '3.0.0'; - public static function submit($config_content, $api_key=null) { - $coconut_url = self::COCONUT_URL; +} - if(!$api_key) { - $api_key = getenv("COCONUT_API_KEY"); - } - - if($url = getenv("COCONUT_URL")) - $coconut_url = $url; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $coconut_url . "/v1/job"); - curl_setopt($ch, CURLOPT_USERPWD, $api_key . ":"); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $config_content); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, self::USER_AGENT); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Length: ' . strlen($config_content), - 'Content-Type: text/plain', - 'Accept: application/json') - ); - - $result = curl_exec($ch); - curl_close($ch); - return json_decode($result); - } - - public static function get($path, $api_key=null) { - $coconut_url = self::COCONUT_URL; - - if(!$api_key) { - $api_key = getenv("COCONUT_API_KEY"); - } - - if($url = getenv("COCONUT_URL")) - $coconut_url = $url; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $coconut_url . $path); - curl_setopt($ch, CURLOPT_USERPWD, $api_key . ":"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, self::USER_AGENT); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: text/plain', - 'Accept: application/json') - ); - - $result = curl_exec($ch); - $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - - if($http_status != 200) { - return null; - } - - return json_decode($result); - } - - public static function config($options=array()) { - $conf = array(); - if(isset($options['conf'])) { - $conf_file = $options['conf']; - if($conf_file != null) { - $conf = explode("\n", trim(file_get_contents($conf_file))); - } - } - - if(isset($options['vars'])) { - $vars = $options['vars']; - if($vars != null) { - foreach ($vars as $name => $value) { - $conf[] = 'var ' . $name . ' = ' . $value; - } - } - } - - if(isset($options['source'])) { - $source = $options['source']; - if($source != null) { - $conf[] = 'set source = ' . $source; - } - } - - if(isset($options['webhook'])) { - $webhook = $options['webhook']; - if($webhook != null) { - $conf[] = 'set webhook = ' . $webhook; - } - } - - if(isset($options['api_version'])) { - $api_version = $options['api_version']; - if($api_version != null) { - $conf[] = 'set api_version = ' . $api_version; - } - } - - if(isset($options['outputs'])) { - $outputs = $options['outputs']; - if($outputs != null) { - foreach ($outputs as $format => $cdn) { - $conf[] = '-> ' . $format . ' = ' . $cdn; - } - } - } - - // Reformatting the generated config - $new_conf = array(); - - $vars_arr = array_filter($conf, function($l) { - return (0 === strpos($l, 'var')); - }); - - sort($vars_arr); - $new_conf = array_merge($new_conf, $vars_arr); - $new_conf[] = ''; - - $set_arr = array_filter($conf, function($l) { - return (0 === strpos($l, 'set')); - }); - - sort($set_arr); - $new_conf = array_merge($new_conf, $set_arr); - $new_conf[] = ''; - - $out_arr = array_filter($conf, function($l) { - return (0 === strpos($l, '->')); - }); - - sort($out_arr); - $new_conf = array_merge($new_conf, $out_arr); - - return join("\n", $new_conf); - } -} \ No newline at end of file +?> \ No newline at end of file diff --git a/src/Error.php b/src/Error.php new file mode 100644 index 0000000..61f7f3e --- /dev/null +++ b/src/Error.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/src/Job.php b/src/Job.php index 17286c3..d3e2c09 100644 --- a/src/Job.php +++ b/src/Job.php @@ -3,36 +3,26 @@ namespace Coconut; class Job { - public static function create($options=array()) { - $api_key = self::getApiKey($options); - - return Coconut::submit(Coconut::config($options), $api_key); - } - - public static function get($jid, $options=array()) { - $api_key = self::getApiKey($options); - - return Coconut::get('/v1/jobs/' . $jid, $api_key); - } - - public static function getAllMetadata($jid, $options=array()) { - $api_key = self::getApiKey($options); - - return Coconut::get('/v1/metadata/jobs/' . $jid, $api_key); + function __construct($cli) { + $this->cli = $cli; + $this->api = $cli->api; + } + + function create($data=array()) { + if($this->cli->storage) { + $data["storage"] = $this->cli->storage; } - public static function getMetadataFor($jid, $source_or_output, $options=array()) { - $api_key = self::getApiKey($options); - - return Coconut::get('/v1/metadata/jobs/' . $jid . '/' . $source_or_output, $api_key); + if($this->cli->notification) { + $data["notification"] = $this->cli->notification; } + return $this->api->request("POST", "/jobs", $data); + } - private static function getApiKey($options=array()) { - $api_key = null; - if(isset($options['api_key'])) { - $api_key = $options['api_key']; - } - return $api_key; - } + function retrieve($jid) { + return $this->api->request("GET", "/jobs/" . $jid); + } } + +?> \ No newline at end of file diff --git a/src/Metadata.php b/src/Metadata.php new file mode 100644 index 0000000..d8dedb4 --- /dev/null +++ b/src/Metadata.php @@ -0,0 +1,15 @@ +api = $cli->api; + } + + function retrieve($jid) { + return $this->api->request("GET", "/metadata/jobs/" . $jid); + } +} + +?> \ No newline at end of file diff --git a/tests/CoconutTest.php b/tests/CoconutTest.php index 63dee44..536f0e0 100755 --- a/tests/CoconutTest.php +++ b/tests/CoconutTest.php @@ -4,194 +4,70 @@ class CoconutTest extends TestCase { - /* - To run these tests, you need to set your API key with the - environment variable `COCONUT_API_KEY` - */ + const INPUT_URL = "https://s3-eu-west-1.amazonaws.com/files.coconut.co/bbb_800k.mp4"; - public function testSubmitJob() { - $config = Coconut\Coconut::config(array( - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'webhook' => 'http://mysite.com/webhook', - 'outputs' => array('mp4' => 's3://a:s@bucket/video.mp4') - )); + public function testCoconutClient() { + $api_key = getenv("COCONUT_API_KEY"); - $job = Coconut\Coconut::submit($config); - $this->assertEquals('processing', $job->{'status'}); - $this->assertTrue($job->{'id'} > 0); + $coconut = new Coconut\Client($api_key); + $this->assertEquals($api_key, $coconut->api_key); + $this->assertEquals("https://api.coconut.co/v2", $coconut->getEndpoint()); } - public function testSubmitBadConfig() { - $config = Coconut\Coconut::config(array( - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4' - )); - - $job = Coconut\Coconut::submit($config); - $this->assertEquals('error', $job->{'status'}); - $this->assertEquals('config_not_valid', $job->{'error_code'}); - } - - public function testSubmitConfigWithAPIKey() { - $config = Coconut\Coconut::config(array( - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4' - )); - - $job = Coconut\Coconut::submit($config, 'k-4d204a7fd1fc67fc00e87d3c326d9b75'); - $this->assertEquals('error', $job->{'status'}); - $this->assertEquals('authentication_failed', $job->{'error_code'}); - } - - public function testGenerateFullConfigWithNoFile() { - $config = Coconut\Coconut::config(array( - 'vars' => array( - 'vid' => 1234, - 'user' => 5098, - 's3' => 's3://a:s@bucket' - ), - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'webhook' => 'http://mysite.com/webhook?vid=$vid&user=$user', - 'outputs' => array( - 'mp4' => '$s3/vid.mp4', - 'jpg_200x' => '$s3/thumb.jpg', - 'webm' => '$s3/vid.webm' - ) - )); - - $generated = join("\n", array( - 'var s3 = s3://a:s@bucket', - 'var user = 5098', - 'var vid = 1234', - '', - 'set source = https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'set webhook = http://mysite.com/webhook?vid=$vid&user=$user', - '', - '-> jpg_200x = $s3/thumb.jpg', - '-> mp4 = $s3/vid.mp4', - '-> webm = $s3/vid.webm' - )); - - $this->assertEquals($generated, $config); - } - - public function testGenerateConfigWithFile() { - $file = fopen('coconut.conf', 'w'); - fwrite($file, 'var s3 = s3://a:s@bucket/video' . "\n" . 'set webhook = http://mysite.com/webhook?vid=$vid&user=$user' . "\n" . '-> mp4 = $s3/$vid.mp4'); - fclose($file); - - $config = Coconut\Coconut::config(array( - 'conf' => 'coconut.conf', - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'vars' => array('vid' => 1234, 'user' => 5098) - )); - - $generated = join("\n", array( - 'var s3 = s3://a:s@bucket/video', - 'var user = 5098', - 'var vid = 1234', - '', - 'set source = https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'set webhook = http://mysite.com/webhook?vid=$vid&user=$user', - '', - '-> mp4 = $s3/$vid.mp4' - )); - - $this->assertEquals($generated, $config); - - unlink('coconut.conf'); - } - - public function testSubmitFile() { - $file = fopen('coconut.conf', 'w'); - fwrite($file, 'var s3 = s3://a:s@bucket/video' . "\n" . 'set webhook = http://mysite.com/webhook?vid=$vid&user=$user' . "\n" . '-> mp4 = $s3/$vid.mp4'); - fclose($file); - - $job = Coconut\Job::create(array( - 'conf' => 'coconut.conf', - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'vars' => array('vid' => 1234, 'user' => 5098) - )); - - $this->assertEquals('processing', $job->{'status'}); - $this->assertTrue($job->{'id'} > 0); - - unlink('coconut.conf'); + public function testCoconutClientWithRegion() { + $coconut = new Coconut\Client(getenv("COCONUT_API_KEY"), ["region" => "us-west-2"]); + $this->assertEquals("https://api-us-west-2.coconut.co/v2", $coconut->getEndpoint()); } - public function testSetApiKeyInJobOptions() { - $job = Coconut\Job::create(array( - 'api_key' => 'k-4d204a7fd1fc67fc00e87d3c326d9b75', - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4' - )); - - $this->assertEquals('error', $job->{'status'}); - $this->assertEquals('authentication_failed', $job->{'error_code'}); + public function testCoconutClientWithEndpoint() { + $coconut = new Coconut\Client(getenv("COCONUT_API_KEY"), ["endpoint" => "http://localhost:3001/v2"]); + $this->assertEquals("http://localhost:3001/v2", $coconut->getEndpoint()); } - public function testGetJobInfo() { - $config = Coconut\Coconut::config(array( - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'webhook' => 'http://mysite.com/webhook', - 'outputs' => array('mp4' => 's3://a:s@bucket/video.mp4') - )); - - $job = Coconut\Coconut::submit($config); - $info = Coconut\Job::get($job->{"id"}); - - $this->assertEquals($info->{"id"}, $job->{"id"}); + public function testJobCreation() { + $coconut = new Coconut\Client(getenv("COCONUT_API_KEY")); + + $coconut->storage = [ + "service" => "s3", + "bucket" => getenv("AWS_BUCKET"), + "region" => getenv("AWS_REGION"), + "path" => "/coconutphp/tests/", + "credentials" => [ + "access_key_id" => getenv("AWS_ACCESS_KEY_ID"), + "secret_access_key" => getenv("AWS_SECRET_ACCESS_KEY") + ] + ]; + + $coconut->notification = [ + "type" => "http", + "url" => getenv("COCONUT_WEBHOOK_URL") + ]; + + $job = $coconut->job->create([ + "input" => ["url" => CoconutTest::INPUT_URL], + "outputs" => [ + "mp4" => [ + "path" => "video.mp4" + ] + ] + ]); + + $this->assertEquals("job.starting", $job->{"status"}); } - public function testGetNotFoundJobReturnsNull() { - $info = Coconut\Job::get(1000); - $this->assertNull($info); - } - - public function testGetAllMetadata() { - $config = Coconut\Coconut::config(array( - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'webhook' => 'http://mysite.com/webhook', - 'outputs' => array('mp4' => 's3://a:s@bucket/video.mp4') - )); - - $job = Coconut\Coconut::submit($config); - sleep(4); - - $metadata = Coconut\Job::getAllMetadata($job->{"id"}); - $this->assertNotNull($metadata); - } - - public function testGetMetadataForSource() { - $config = Coconut\Coconut::config(array( - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'webhook' => 'http://mysite.com/webhook', - 'outputs' => array('mp4' => 's3://a:s@bucket/video.mp4') - )); - - $job = Coconut\Coconut::submit($config); - sleep(4); - - $metadata = Coconut\Job::getMetadataFor($job->{"id"}, 'source'); - $this->assertNotNull($metadata); - } - - public function testSetAPIVersion() { - $config = Coconut\Coconut::config(array( - 'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'webhook' => 'http://mysite.com/webhook?vid=$vid&user=$user', - 'api_version' => 'beta', - 'outputs' => array( - 'mp4' => '$s3/vid.mp4', - ) - )); - - $generated = join("\n", array( - '', - 'set api_version = beta', - 'set source = https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4', - 'set webhook = http://mysite.com/webhook?vid=$vid&user=$user', - '', - '-> mp4 = $s3/vid.mp4' - )); - - $this->assertEquals($generated, $config); + public function testJobError() { + $coconut = new Coconut\Client(getenv("COCONUT_API_KEY")); + + try { + $job = $coconut->job->create([ + "outputs" => [ + "mp4" => [ + "path" => "video.mp4" + ] + ] + ]); + } catch(Exception $e) { + $this->assertEquals("The job 'input' is not a valid object. (input_not_valid)", $e->getMessage()); + } } } \ No newline at end of file