diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..7fb2bd8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/vendor +composer.lock +/.idea +.DS_Store +Thumbs.db diff --git a/.travis.yml b/.travis.yml new file mode 100755 index 0000000..f64abe9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,21 @@ +language: php + +php: + - 5.4 + - 5.5 + - 5.6 + - hhvm + +sudo: false + +before_script: + - composer self-update + - composer install --prefer-source --no-interaction --dev + +script: + - phpunit --coverage-text + +matrix: + allow_failures: + - php: hhvm + fast_finish: true \ No newline at end of file diff --git a/README.md b/README.md index 6ad883a..ef3d2c6 100755 --- a/README.md +++ b/README.md @@ -1,10 +1,97 @@ -# ForkCMS Api class +# Fork CMS PHP API class +[![Latest Stable Version](http://img.shields.io/packagist/v/forkcms/api-wrapper-class.svg)](https://packagist.org/packages/forkcms/api-wrapper-class) +[![License](http://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/forkcms/api-wrapper-class/blob/master/LICENSE) +[![Build Status](http://img.shields.io/travis/forkcms/api-wrapper-class.svg)](https://travis-ci.org/forkcms/api-wrapper-class) -## About +This Fork CMS PHP class can communicate with the API from a Fork CMS website. -A (wrapper)class to communicate with the your Fork CMS install. +## Usage + +### Installation + +``` json +{ + "require": { + "forkcms/api-wrapper-class": "1.0.*" + } +} +``` +> Adding this code in your `composer.json` file will get the [latest fork-cms-php-api Packagist package](https://packagist.org/packages/forkcms/api-wrapper-class) using [Composer](https://getcomposer.org). + +### Example + +``` php +use ForkCms\Api\ForkCms; +``` + +**Function calls which do not require authentication** + +```php +$api = new ForkCms( + $url, + $email +); + +$response = $api->coreGetAPIKey($email, $password); + +$apiKey = $response['api_key']; + +``` + +**Function calls which require authentication** +```php +$api = new ForkCms( + $url, + $email, + $apiKey +); + +$response = $api->coreAppleAddDevice(APPLE_DEVICE_TOKEN); +$response = $api->coreAppleRemoveDevice(APPLE_DEVICE_TOKEN); +$response = $api->blogCommentsGet(); +// ... +``` +> [View all examples](/examples/example.php) or check [the Fork CMS API Wrapper Class](/src/). + +### Tests + +``` bash +phpunit +``` ## Documentation -The class is well documented inline. If you use a decent IDE you'll see that -each method is documented with PHPDoc. \ No newline at end of file +The class is well documented inline. If you use a decent IDE you'll see that each method is documented with PHPDoc. + + +## Contributing + +Contributions are **welcome** and will be fully **credited**. + +### Pull Requests + +> To add or update code + +- **Coding Syntax** - Please keep the code syntax consistent with the rest of the package. +- **Add unit tests!** - Your patch won't be accepted if it doesn't have tests. +- **Document any change in behavior** - Make sure the README and any other relevant documentation are kept up-to-date. +- **Consider our release cycle** - We try to follow [semver](http://semver.org/). Randomly breaking public APIs is not an option. +- **Create topic branches** - Don't ask us to pull from your master branch. +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. + +### Issues + +> For bug reporting or code discussions. + +More info on how to work with GitHub on help.github.com. + +## Credits + +- [Tijs Verkoyen](https://github.com/tijsverkoyen) +- [Jeroen Desloovere](https://github.com/jeroendesloovere) +- [All Contributors](https://github.com/forkcms/api-wrapper-class/contributors) + +## License + +The module is licensed under [MIT](./LICENSE.md). In short, this license allows you to do everything as long as the copyright statement stays present. \ No newline at end of file diff --git a/composer.json b/composer.json index 8bfa6bb..1ab58c0 100644 --- a/composer.json +++ b/composer.json @@ -1,21 +1,33 @@ { - "name": "forkcms/api-wrapper", + "name": "forkcms/api-wrapper-class", "type": "library", - "description": "Wrapper class to communicate with your Fork install", + "description": "This Fork CMS PHP class can communicate with a Fork CMS websites API.", + "keywords": ["Fork CMS", "CMS", "PHP", "API"], "homepage": "https://github.com/forkcms/api-wrapper-class", "license": "MIT", "authors": [ - { - "name": "Tijs Verkoyen", - "email": "tijs@sumocoders.be", - "role": "Developer" - } + { + "name": "Tijs Verkoyen", + "email": "tijs@sumocoders.be", + "role": "Developer" + }, + { + "name": "Jeroen Desloovere", + "email": "info@jeroendesloovere.be", + "homepage": "http://jeroendesloovere.be", + "role": "Developer" + } ], "require": { "php": ">=5.3.0", "ext-curl": "*" }, + "require-dev": { + "mockery/mockery": "dev-master@dev" + }, "autoload": { - "classmap": [""] + "psr-4": { + "ForkCms\\Api\\": "src/" + } } } \ No newline at end of file diff --git a/examples/credentials.php b/examples/credentials.php new file mode 100644 index 0000000..9425c20 --- /dev/null +++ b/examples/credentials.php @@ -0,0 +1,15 @@ +coreGetAPIKey($email, $password); +// $response = $api->coreGetInfo(); + + // we need to save the api key in our database + $apiKey = $response['api_key']; + + // we can set the api key or create a new Fork CMS Api instead. + $api->setApiKey($apiKey); +} catch (Exception $e) { + var_dump($e); +} + +// output +var_dump($response); + +// we can now create a new Fork CMS API where we fill in the $apiKey +$api = new ForkCms( + $url, + $email, + $apiKey +); + +try { +// authorisation required for the following functions +// $response = $api->coreAppleAddDevice(APPLE_DEVICE_TOKEN); +// $response = $api->coreAppleRemoveDevice(APPLE_DEVICE_TOKEN); +// $response = $api->blogCommentsGet(); +// $response = $api->blogCommentsGetById(40); +// $response = $api->blogCommentsUpdate(40, null, 'FooBar'); +// $response = $api->blogCommentsUpdateStatus(array(39, 40), 'published'); +} catch (Exception $e) { + var_dump($e); +} + +// output +var_dump($response); diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100755 index 0000000..31de95c --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,16 @@ + + + + + tests + + + + + src + + + diff --git a/Exception.php b/src/Exception.php similarity index 99% rename from Exception.php rename to src/Exception.php index c183778..64d708a 100644 --- a/Exception.php +++ b/src/Exception.php @@ -1,4 +1,5 @@ - * @version 1.0.1 - * @copyright Copyright (c) 2008, Tijs Verkoyen. All rights reserved. - * @license BSD License + * Wrapper class for any Fork CMS API. + * + * @author Tijs Verkoyen */ -class Api +class ForkCms { // current version const VERSION = '1.0.1'; @@ -194,25 +193,25 @@ private function getSecret($nonce) } /** - * Get the useragent that will be used. Our version will be prepended to - * yours. - * It will look like: "PHP ForkAPI/ " + * Get the URL of the website we are working on * * @return string */ - public function getUserAgent() + public function getUrl() { - return 'PHP ForkAPI/'. self::VERSION .' '. $this->userAgent; + return $this->url; } /** - * Get the URL of the website we are working on + * Get the useragent that will be used. Our version will be prepended to + * yours. + * It will look like: "PHP ForkAPI/ " * * @return string */ - public function getUrl() + public function getUserAgent() { - return $this->url; + return 'PHP ForkAPI/'. self::VERSION .' '. $this->userAgent; } /** @@ -247,19 +246,6 @@ public function setTimeOut($seconds) $this->timeOut = (int) $seconds; } - /** - * Set the user-agent for you application - * It will be appended to ours, the result will look like: - * "PHP ForkAPI/ " - * - * @return void - * @param string $userAgent Your user-agent, it should look like /. - */ - public function setUserAgent($userAgent) - { - $this->userAgent = (string) $userAgent; - } - /** * Set the URL to work on * @@ -273,6 +259,19 @@ protected function setUrl($url) $this->url = (string) $url; } + /** + * Set the user-agent for you application + * It will be appended to ours, the result will look like: + * "PHP ForkAPI/ " + * + * @return void + * @param string $userAgent Your user-agent, it should look like /. + */ + public function setUserAgent($userAgent) + { + $this->userAgent = (string) $userAgent; + } + /** * Get the API key for a user * diff --git a/tests/ApiTest.php b/tests/ForkCmsTest.php similarity index 94% rename from tests/ApiTest.php rename to tests/ForkCmsTest.php index c955582..e50674e 100644 --- a/tests/ApiTest.php +++ b/tests/ForkCmsTest.php @@ -1,15 +1,19 @@ + * @author Jeroen Desloovere */ -class ApiTest extends PHPUnit_Framework_TestCase +class ForkCmsTest extends PHPUnit_Framework_TestCase { /** * @var Api diff --git a/tests/index.php b/tests/index.php deleted file mode 100644 index aa09d05..0000000 --- a/tests/index.php +++ /dev/null @@ -1,26 +0,0 @@ -coreGetAPIKey(EMAIL, PASSWORD); -// $response = $api->coreGetInfo(); -// $response = $api->coreAppleAddDevice(APPLE_DEVICE_TOKEN); -// $response = $api->coreAppleRemoveDevice(APPLE_DEVICE_TOKEN); -// $response = $api->blogCommentsGet(); -// $response = $api->blogCommentsGetById(40); -// $response = $api->blogCommentsUpdate(40, null, 'FooBar'); -// $response = $api->blogCommentsUpdateStatus(array(39, 40), 'published'); -} catch (Exception $e) { - var_dump($e); -} - -// output -var_dump($response);