-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
PGBI
committed
Apr 19, 2016
0 parents
commit 2785c81
Showing
12 changed files
with
961 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/.idea | ||
*.DS_Store | ||
/vendor | ||
composer.lock | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
|
||
install: | ||
- composer self-update | ||
- composer install | ||
|
||
script: | ||
- vendor/bin/phpunit --coverage-clover=coverage.xml | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Classy PHP SDK [![Build Status](https://travis-ci.org/classy-org/classy-php-sdk.png?branch=master)](https://travis-ci.org/classy-org/classy-php-sdk) [![codecov.io](https://codecov.io/github/classy-org/classy-php-sdk/coverage.svg?branch=master)](https://codecov.io/github/classy-org/classy-php-sdk?branch=master) | ||
|
||
This repository contains a php HTTP client library to let your php App interact with Classy's API. | ||
|
||
## Installation | ||
|
||
The Classy PHP SDK can be installed with [Composer](https://getcomposer.org/): | ||
|
||
```sh | ||
composer require classy-org/classy-php-sdk | ||
``` | ||
|
||
Be sure you included composer autoloader in your app: | ||
|
||
```php | ||
require_once '/path/to/your/project/vendor/autoload.php'; | ||
``` | ||
|
||
## Usage | ||
|
||
### Basic example | ||
|
||
```php | ||
$client = new \Classy\Client([ | ||
'client_id' => 'your_client_id', | ||
'client_secret' => 'your_client_secret', | ||
'version' => '2.0' // version of the API to be used | ||
]); | ||
|
||
$session = $client->newAppSession(); | ||
|
||
// Get information regarding the campaign #1234 | ||
$campaign = $client->get('/campaigns/1234', $session); | ||
|
||
// Access the campaign goal: $campaign->goal | ||
|
||
// Unpublish the campaign | ||
$client->post('/campaign/1234/deactivate', $session); | ||
``` | ||
|
||
### Sessions handling | ||
|
||
Sessions have an expiration date. It is possible to refresh a session: | ||
|
||
```php | ||
if ($session->expired()) { | ||
$client->refresh($session) | ||
} | ||
|
||
// $session->expired() is now false. | ||
``` | ||
|
||
Sessions are serializable, they can be saved an reused to reduce the amount of API calls: | ||
|
||
```php | ||
$client = new \Classy\Client([ | ||
'client_id' => 'your_client_id', | ||
'client_secret' => 'your_client_secret', | ||
'version' => '2.0' // version of the API to be used | ||
]); | ||
|
||
// Retrieve the session from a file | ||
$session = unserialize(file_get_contents("path/to/a/cache/file")); | ||
|
||
// ... work with the API... | ||
|
||
// Save the session for later | ||
file_put_contents("path/to/a/cache/file", serialize($session)); | ||
``` | ||
|
||
### Errors handling | ||
|
||
This client can throw two types of Exceptions: | ||
|
||
* Classy\Exceptions\SDKException when the SDK is misused | ||
* Classy\Exceptions\APIResponseException when the API is not returning an OK response | ||
|
||
```php | ||
try { | ||
$response = $client->get('/endpoint', $session); | ||
} catch (\Classy\Exceptions\APIResponseException $e) { | ||
// Get the HTTP response code | ||
$code = $e->getCode(); | ||
// Get the response content | ||
$content = $e->getResponseData(); | ||
// Get the response headers | ||
$headers = $e->getResponseHeaders(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "classy-org/classy-php-sdk", | ||
"type": "library", | ||
"description": "Php HTTP client library for Classy API", | ||
"require": { | ||
"guzzlehttp/guzzle": "^6.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.0", | ||
"mockery/mockery": "^0.9.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Classy\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Classy\\Tests\\": "tests" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit colors="true"> | ||
<testsuites> | ||
<testsuite name="Application Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist addUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Oops, something went wrong.