Skip to content

Commit

Permalink
add support php version 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mafikes committed Feb 17, 2022
1 parent 3619261 commit 78d25f6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 40 deletions.
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"description": "API client for CDN77.com",
"type": "library",
"require": {
"php": ">=7.0",
"php": ">=5.4.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.3"
"guzzlehttp/guzzle": "^5.3"
},
"license": "MIT",
"authors": [
Expand All @@ -18,7 +18,5 @@
"psr-4": {
"Mafikes\\Cdn77Api\\": "src/"
}
},
"require-dev": {
}
}
24 changes: 9 additions & 15 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ class Client
const API_URL = 'https://api.cdn77.com/v3/';
private $token; // Generated Api Key

private $client; // Registered Guzzle client
/**
* @var GuzzleHttp\Client
*/
private $client;

/** @var Resources\CdnResource */
public $cdnResource;
Expand Down Expand Up @@ -55,8 +58,7 @@ public function __construct($token, $jsonResponse = false)
}

$this->client = new GuzzleHttp\Client([
'base_uri' => self::API_URL,
'timeout' => 2.0,
'base_url' => self::API_URL,
]);

$this->jsonResponse = $jsonResponse;
Expand Down Expand Up @@ -95,18 +97,18 @@ public function createHeader($bodyData = array())
* @param array $bodyData
* @param null $jsonResponse
* @return mixed|string
* @throws GuzzleHttp\Exception\GuzzleException
*/
public function askServer($method, $uri, $parameters = array(), $bodyData = array(), $jsonResponse = null)
{
// Add params if exist
if(!is_null($parameters)) {
$uri = $uri . '?' . http_build_query($parameters);
}
}

// Create request
try {
$response = $this->client->request($method, $uri, $this->createHeader($bodyData));
$request = $this->client->createRequest($method, $uri, $this->createHeader($bodyData));
$response = $this->client->send($request);
} catch (GuzzleHttp\Exception\RequestException $e) {
throw new \Exception($e->getResponse()->getBody());
}
Expand All @@ -116,7 +118,7 @@ public function askServer($method, $uri, $parameters = array(), $bodyData = arra
throw new \Exception('Exception: Request Error. Status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody());
}

$result = $response->getBody()->getContents();
$result = $response->getBody();

if (!$this->jsonResponse || !is_null($jsonResponse) && $jsonResponse === false) {
$result = json_decode($result);
Expand All @@ -125,14 +127,6 @@ public function askServer($method, $uri, $parameters = array(), $bodyData = arra
return $result;
}

/**
* @return string
*/
public function getLogin()
{
return $this->login;
}

/**
* @return string
*/
Expand Down
19 changes: 10 additions & 9 deletions src/Resources/CdnResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(Client $client)
* Create a HTTP CDN resource.
* @param array $data
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function create($data = array())
{
Expand All @@ -35,7 +35,7 @@ public function create($data = array())
* @param $cdnResourceId
* @param $data
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function createCname($cdnResourceId, $data = array())
{
Expand All @@ -47,7 +47,7 @@ public function createCname($cdnResourceId, $data = array())
* @param $cdnResourceId
* @param $data
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function enableDatacenters($cdnResourceId, $data)
{
Expand All @@ -58,7 +58,7 @@ public function enableDatacenters($cdnResourceId, $data)
* Get your http CDN resource details.
* @param $cdnResourceId
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function getDetail($cdnResourceId)
{
Expand All @@ -70,7 +70,7 @@ public function getDetail($cdnResourceId)
* @param $cdnResourceId
* @param array $data
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function edit($cdnResourceId, $data = array())
{
Expand All @@ -81,7 +81,7 @@ public function edit($cdnResourceId, $data = array())
* Delete your CDN resource.
* @param $cdnResourceId
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function delete($cdnResourceId)
{
Expand All @@ -90,7 +90,8 @@ public function delete($cdnResourceId)

/**
* List your CDN resource details.
* @throws \GuzzleHttp\Exception\GuzzleException
* @return mixed|string
* @throws \Exception
*/
public function getList()
{
Expand All @@ -101,7 +102,7 @@ public function getList()
* List of CNAMEs
* @param $cdnResourceId
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function getListCnames($cdnResourceId)
{
Expand All @@ -112,7 +113,7 @@ public function getListCnames($cdnResourceId)
* List of Datacenters
* @param $cdnResourceId
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function getListDatacenter($cdnResourceId)
{
Expand Down
11 changes: 5 additions & 6 deletions src/Resources/JobResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ public function __construct(Client $client)
$this->client = $client;
}


/**
* Returns a filtered list of jobs for a given CDN Resource and type.
* @param $id
* @param $type
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function getList($id, $type)
{
Expand All @@ -40,7 +39,7 @@ public function getList($id, $type)
* @param $id
* @param $jobId
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function getDetail($id, $jobId)
{
Expand All @@ -52,7 +51,7 @@ public function getDetail($id, $jobId)
* @param $id
* @param $data
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function prefetch($id, $data)
{
Expand All @@ -64,7 +63,7 @@ public function prefetch($id, $data)
* @param $id
* @param $data
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function purge($id, $data)
{
Expand All @@ -75,7 +74,7 @@ public function purge($id, $data)
* Allows you to instantly remove all cached content from all datacenters.
* @param $id
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function purgeAll($id)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Resources/OriginResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(Client $client)
/**
* List of Origins
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function getList()
{
Expand All @@ -33,7 +33,7 @@ public function getList()
* Create Your Origin
* @param $data
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function create($data)
{
Expand All @@ -45,7 +45,7 @@ public function create($data)
* Detail of Your Origin
* @param $id
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function getDetail($id)
{
Expand All @@ -57,7 +57,7 @@ public function getDetail($id)
* @param $id
* @param $data
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function edit($id, $data)
{
Expand All @@ -69,7 +69,7 @@ public function edit($id, $data)
* Delete Origin
* @param $id
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function delete($id)
{
Expand All @@ -80,7 +80,7 @@ public function delete($id)
* Create AWS Origin
* @param $data
* @return mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
public function createAwsOrigin($data)
{
Expand Down

0 comments on commit 78d25f6

Please sign in to comment.