Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved source to /src + added more example data #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor
composer.lock
/.idea
.DS_Store
Thumbs.db
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
97 changes: 92 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
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.
28 changes: 20 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"role": "Developer"
}
{
"name": "Tijs Verkoyen",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "Jeroen Desloovere",
"email": "[email protected]",
"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/"
}
}
}
15 changes: 15 additions & 0 deletions examples/credentials.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

// define credentials for the fork cms based website you try to connect to
$url = ''; // required, example: http://www.mydomainname.tld/api/v1/
$email = ''; // required

// calls with authentication (we use the $password to trade it in for an $apiKey)
$password = ''; // we only need to set a password if we try to call functions which require authentication
// or
$apiKey = ''; // if you know your personal apiKey, fill it in, otherwise you need to fill in the password

// url and email are required
if (empty($url) || empty($email)) {
echo 'Please define your url and email in ' . __DIR__ . '/credentials.php';
}
56 changes: 56 additions & 0 deletions examples/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

//require
require_once '../../../autoload.php';
require_once __DIR__ . '/credentials.php';

use \ForkCms\Api\ForkCms;


// Getting API KEY for function calls which require an Api key.
// Note: save the received Api key for later use.

// init fork cms
$api = new ForkCms(
$url,
$email
);

try {
// we get the api key for this user
$response = $api->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);
16 changes: 16 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="vendor/autoload.php"
colors="true"
verbose="true">
<testsuites>
<testsuite name="JeroenDesloovere Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
1 change: 1 addition & 0 deletions Exception.php → src/Exception.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace ForkCms\Api;

/**
Expand Down
51 changes: 25 additions & 26 deletions Api.php → src/ForkCms.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace ForkCms\Api;

/**
* @author Tijs Verkoyen <[email protected]>
* @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 <[email protected]>
*/
class Api
class ForkCms
{
// current version
const VERSION = '1.0.1';
Expand Down Expand Up @@ -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/<version> <your-user-agent>"
* 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/<version> <your-user-agent>"
*
* @return string
*/
public function getUrl()
public function getUserAgent()
{
return $this->url;
return 'PHP ForkAPI/'. self::VERSION .' '. $this->userAgent;
}

/**
Expand Down Expand Up @@ -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/<version> <your-user-agent>"
*
* @return void
* @param string $userAgent Your user-agent, it should look like <app-name>/<app-version>.
*/
public function setUserAgent($userAgent)
{
$this->userAgent = (string) $userAgent;
}

/**
* Set the URL to work on
*
Expand All @@ -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/<version> <your-user-agent>"
*
* @return void
* @param string $userAgent Your user-agent, it should look like <app-name>/<app-version>.
*/
public function setUserAgent($userAgent)
{
$this->userAgent = (string) $userAgent;
}

/**
* Get the API key for a user
*
Expand Down
16 changes: 10 additions & 6 deletions tests/ApiTest.php → tests/ForkCmsTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?php

require_once '../../../autoload.php';
require_once 'config.php';
require_once 'PHPUnit/Framework/TestCase.php';
namespace ForkCMS\Api\tests;

use \ForkCms\Api\Api;
require_once '../vendor/autoload.php';
require_once __DIR__ . '/src/credentials.php';

use \ForkCms\Api\ForkCms;

/**
* Api test case.
* Tests for the Wrapper class for any Fork CMS API.
*
* @author Tijs Verkoyen <[email protected]>
* @author Jeroen Desloovere <[email protected]>
*/
class ApiTest extends PHPUnit_Framework_TestCase
class ForkCmsTest extends PHPUnit_Framework_TestCase
{
/**
* @var Api
Expand Down
Loading