-
Notifications
You must be signed in to change notification settings - Fork 21
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
0 parents
commit a88c8ee
Showing
19 changed files
with
1,191 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,2 @@ | ||
composer.phar | ||
vendor |
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,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013 MaxCDN, LLC. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,64 @@ | ||
# MaxCDN REST API PHP Client | ||
|
||
## Requirements | ||
- PHP 5.3 or above | ||
- PHP Curl Extension | ||
|
||
## Installation with Composer | ||
Composer is the recommended way to utilize the MaxCDN RWS SDK PHP library. For more information on how to use Composer, see http://www.getcomposer.org . | ||
|
||
1. Add "MaxCDN/rws-sdk-php" as a dependency in your composer.json project file. | ||
|
||
```json | ||
{ | ||
"require": { | ||
"MaxCDN/rws-sdk-php": "2.*" | ||
} | ||
} | ||
``` | ||
|
||
2. Download and install Composer (if not already installed). | ||
|
||
```bash | ||
curl -sS https://getcomposer.org/installer | php | ||
``` | ||
|
||
3. Install your package dependencies. | ||
|
||
```bash | ||
php composer.phar install -o | ||
``` | ||
|
||
This will download the MaxCDN library and configure composer to use it. Composer will also build an autoloader for your use in the next step. | ||
|
||
4. Use Composer's autoloader. | ||
|
||
Composer prepares an autoload file which autoloads the RWS library for you on demand. To use it, provide the following at the top of your PHP source files: | ||
|
||
```php | ||
require_once '/path/to/vendor/autoload.php'; | ||
``` | ||
|
||
It is advised that you understand how to optimze Composer's usage in Production environments. For more information about Composer, visit http://getcomposer.org | ||
|
||
The libraries are located in the src/ directory. The classes are organized in a PSR-0 hierarchy. You can use any PSR-0 compliant autoloader for this library. Composer is the recommended method (see above). | ||
|
||
## Usage | ||
```php | ||
<?php | ||
|
||
$api = new MaxCDN("my_alias","consumer_key","consumer_secret"); | ||
|
||
// get account information | ||
echo $api->get('/account.json'); | ||
|
||
// delete a file from the cache | ||
$params = array('file' => '/robots.txt'); | ||
echo $api->delete('/zones/pull.json/6055/cache', $params); | ||
|
||
?> | ||
``` | ||
|
||
## Methods | ||
|
||
It has support for `GET`, `POST`, `PUT` and `DELETE` OAuth signed requests. |
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": "maxcdn/php-maxcdn", | ||
"description": "PHP Wrapper for MaxCDN Remote Web Services", | ||
"type": "library", | ||
"license": "MIT", | ||
"homepage": "http://docs.maxcdn.com", | ||
"support": { | ||
"email": "[email protected]", | ||
"source": "http://www.github.com/MaxCDN/php-maxcdn" | ||
}, | ||
"require": { | ||
"php": ">=5.3.0", | ||
"ext-curl": "*" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"MaxCDN\\": "src/", | ||
"": "src/" | ||
} | ||
} | ||
|
||
} |
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,116 @@ | ||
<?php | ||
/** | ||
* MaxCDN REST Client Library | ||
* | ||
* @copyright 2012 | ||
* @author Karlo Espiritu | ||
* @version 1.0 2012-09-21 | ||
*/ | ||
class MaxCDN { | ||
|
||
public $alias; | ||
|
||
public $key; | ||
|
||
public $secret; | ||
|
||
public $MaxCDNrws_url = 'https://rws.maxcdn.com'; | ||
|
||
private $consumer; | ||
|
||
public function __construct($alias, $key, $secret, $options=null) { | ||
$this->alias = $alias; | ||
$this->key = $key; | ||
$this->secret = $secret; | ||
$this->consumer = new \MaxCDN\OAuth\OAuthConsumer($key, $secret, NULL); | ||
|
||
} | ||
|
||
private function execute($selected_call, $method_type, $params) { | ||
// the endpoint for your request | ||
$endpoint = "$this->MaxCDNrws_url/$this->alias$selected_call"; | ||
|
||
//parse endpoint before creating OAuth request | ||
$parsed = parse_url($endpoint); | ||
if (array_key_exists("parsed", $parsed)) | ||
{ | ||
parse_str($parsed['query'], $params); | ||
} | ||
|
||
//generate a request from your consumer | ||
$req_req = \MaxCDN\OAuth\OAuthRequest::from_consumer_and_token($this->consumer, NULL, $method_type, $endpoint, $params); | ||
|
||
//sign your OAuth request using hmac_sha1 | ||
$sig_method = new \MaxCDN\OAuth\OAuthSignatureMethod_HMAC_SHA1(); | ||
$req_req->sign_request($sig_method, $this->consumer, NULL); | ||
|
||
// create curl resource | ||
$ch = curl_init(); | ||
|
||
// set url | ||
curl_setopt($ch, CURLOPT_URL, $req_req); | ||
|
||
//return the transfer as a string | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , FALSE); | ||
|
||
// set curl timeout | ||
curl_setopt($ch, CURLOPT_TIMEOUT, 60); | ||
|
||
// set curl custom request type if not standard | ||
if ($method_type != "GET" && $method_type != "POST") { | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method_type); | ||
} | ||
|
||
|
||
if ($method_type == "POST" || $method_type == "PUT" || $method_type == "DELETE") { | ||
$query_str = \MaxCDN\OAuth\OAuthUtil::build_http_query($params); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:', 'Content-Length: ' . strlen($query_str))); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_str); | ||
} | ||
|
||
// retrieve headers | ||
curl_setopt($ch, CURLOPT_HEADER, 1); | ||
curl_setopt($ch, CURLINFO_HEADER_OUT, 1); | ||
|
||
//set user agent | ||
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP MaxCDN API Client'); | ||
|
||
// make call | ||
$result = curl_exec($ch); | ||
$headers = curl_getinfo($ch); | ||
$curl_error = curl_error($ch); | ||
|
||
// close curl resource to free up system resources | ||
curl_close($ch); | ||
|
||
// $json_output contains the output string | ||
$json_output = substr($result, $headers['header_size']); | ||
|
||
// catch errors | ||
if(!empty($curl_error) || empty($json_output)) { | ||
throw new \MaxCDN\RWSException("CURL ERROR: $curl_error, Output: $json_output", $headers['http_code'], null, $headers); | ||
} | ||
|
||
return $json_output; | ||
} | ||
|
||
public function get($selected_call, $params = array()){ | ||
|
||
return $this->execute($selected_call, 'GET', $params); | ||
} | ||
|
||
public function post($selected_call, $params = array()){ | ||
return $this->execute($selected_call, 'POST', $params); | ||
} | ||
|
||
public function put($selected_call, $params = array()){ | ||
return $this->execute($selected_call, 'PUT', $params); | ||
} | ||
|
||
public function delete($selected_call, $params = array()){ | ||
return $this->execute($selected_call, 'DELETE', $params); | ||
} | ||
|
||
|
||
} |
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,21 @@ | ||
<?php | ||
/** | ||
* OAuth Consumer representation. | ||
*/ | ||
namespace MaxCDN\OAuth; | ||
|
||
class OAuthConsumer { | ||
public $key; | ||
public $secret; | ||
|
||
function __construct($key, $secret, $callback_url=NULL) { | ||
$this->key = $key; | ||
$this->secret = $secret; | ||
$this->callback_url = $callback_url; | ||
} | ||
|
||
function __toString() { | ||
return "\\MaxCDN\\OAuth\\OAuthConsumer[key=$this->key,secret=$this->secret]"; | ||
} | ||
} | ||
|
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,29 @@ | ||
<?php | ||
namespace MaxCDN\OAuth; | ||
|
||
class OAuthDataStore { | ||
function lookup_consumer($consumer_key) { | ||
// implement me | ||
} | ||
|
||
function lookup_token($consumer, $token_type, $token) { | ||
// implement me | ||
} | ||
|
||
function lookup_nonce($consumer, $token, $nonce, $timestamp) { | ||
// implement me | ||
} | ||
|
||
function new_request_token($consumer, $callback = null) { | ||
// return a new token attached to this consumer | ||
} | ||
|
||
function new_access_token($token, $consumer, $verifier = null) { | ||
// return a new access token attached to this consumer | ||
// for the user associated with this token if the request token | ||
// is authorized | ||
// should also invalidate the request token | ||
} | ||
|
||
} | ||
|
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,10 @@ | ||
<?php | ||
/** | ||
* Exception class for OAuth failures. | ||
*/ | ||
namespace MaxCDN\OAuth; | ||
|
||
class OAuthException extends Exception { | ||
// pass | ||
} | ||
|
Oops, something went wrong.