Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Merge pull request #11 from Wizofgoz/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Wizofgoz authored Jan 7, 2017
2 parents f3e0d44 + 03beb98 commit 40182b4
Show file tree
Hide file tree
Showing 28 changed files with 269 additions and 643 deletions.
6 changes: 0 additions & 6 deletions _notes/dwsync.xml

This file was deleted.

4 changes: 0 additions & 4 deletions examples/_notes/dwsync.xml

This file was deleted.

23 changes: 23 additions & 0 deletions src/Cache/Cache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
<?php
/*
* MIT License
*
* Copyright (c) 2016 Wizofgoz
*
* 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.
*/
namespace Crester\Cache;
class Cache
{
Expand Down
23 changes: 23 additions & 0 deletions src/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
<?php
/*
* MIT License
*
* Copyright (c) 2016 Wizofgoz
*
* 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.
*/
namespace Crester\Cache;

interface CacheInterface
Expand Down
23 changes: 23 additions & 0 deletions src/Cache/DBHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
<?php
/*
* MIT License
*
* Copyright (c) 2016 Wizofgoz
*
* 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.
*/
namespace Crester\Cache;
use \Crester\Cache\CacheInterface;
class DBHandler implements CacheInterface
Expand Down
19 changes: 15 additions & 4 deletions src/Cache/SQL/tables.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
CREATE TABLE `CREST_Cache` (

CREATE TABLE IF NOT EXISTS `CREST_Cache` (
`id` INT (10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`Route` TEXT,
`Args` TEXT,
`Response` TEXT,
`CacheUntil` DATETIME
);

CREATE TABLE `Cache` (

CREATE TABLE IF NOT EXISTS `Cache` (
`id` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`KeyID` VARCHAR(100),
`VCode` VARCHAR(100),
`Scope` VARCHAR(100),
`EndPoint` VARCHAR(100),
`Args` TEXT,
`Data` TEXT,
`CachedUntil` DATETIME
);
6 changes: 0 additions & 6 deletions src/Cache/_notes/dwsync.xml

This file was deleted.

5 changes: 0 additions & 5 deletions src/Config/_notes/dwsync.xml

This file was deleted.

59 changes: 47 additions & 12 deletions src/Core/CREST.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
<?php
/*
* MIT License
*
* Copyright (c) 2016 Wizofgoz
*
* 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.
*/
namespace Crester\Core;
use \Crester\Core\CRESTBase;
use \Crester\Cache\Cache;
use \Crester\Exceptions\CRESTAPIException;
use \Crester\Exceptions\APIResponseException;
use \Crester\Exceptions\APIAuthException;
use \Crester\Exceptions\ParseException;
use \Crester\Exceptions\ResponseSearchException;
class CREST extends CRESTBase implements \SplSubject
{
/*
Expand Down Expand Up @@ -307,15 +334,17 @@ public function delete($authorize = null)
*/
protected function determineAuth($authorize)
{
$authorize = $authorize === null ? $this->authorize : $authorize;

// if global is true, only reason to switch is if $authorize is false
if($this->authorize === true && $authorize === false)
return self::AUTHORIZATION_NONE;

// if global is false and $authorize is not true, switch
if($this->authorize === false && $authorize !== true)
if($this->authorize === false && $authorize === false)
return self::AUTHORIZATION_NONE;

return self::AUTHORIZATION_BEARER;;
return self::AUTHORIZATION_BEARER;
}

/*
Expand All @@ -328,15 +357,15 @@ protected function determineAuth($authorize)
public function verifyCode()
{
try{
$Result = $this->callAPI(self::CREST_LOGIN, "POST", self::AUTHORIZATION_BASIC, array("grant_type" => 'authorization_code', 'code' => $this->Authorization_Code)))
$Result = $this->callAPI(self::CREST_LOGIN, "POST", self::AUTHORIZATION_BASIC, array("grant_type" => 'authorization_code', 'code' => $this->Authorization_Code));
$Result = \json_decode($Result, true);
$this->Access_Token = $Result['access_token'];
$this->Verified_Code = true;
$this->RefreshToken = $Result['refresh_token'];
//Access Tokens are valid for 20mins and must be refreshed after that
$this->RefreshTime = \time()+(60*20);
}catch(APIResponseException $e){
throw new APIAuthException($e->message);
throw new APIAuthException($e->getMessage());
}
}

Expand Down Expand Up @@ -413,7 +442,7 @@ protected function checkRefresh()
protected function refresh()
{
try{
$Result = $this->callAPI(self::CREST_LOGIN, "POST", self::AUTHORIZATION_BASIC, array("grant_type" => 'refresh_token', 'refresh_token' => $this->RefreshToken)))
$Result = $this->callAPI(self::CREST_LOGIN, "POST", self::AUTHORIZATION_BASIC, array("grant_type" => 'refresh_token', 'refresh_token' => $this->RefreshToken));
$Result = \json_decode($Result, true);
$this->Access_Token = $Result['access_token'];
$this->RefreshToken = $Result['refresh_token'];
Expand All @@ -422,14 +451,15 @@ protected function refresh()
$this->notify();
return true;
}catch(APIResponseException $e){
throw new APIAuthException($e->message);
throw new APIAuthException($e->getMessage());
}
}

/*
* Takes in path (SplQueue) and start recursive calls
*
* @param string $Method
* @param integer $Authorize
* @param array $Data
*
* @return string|false
Expand All @@ -440,7 +470,7 @@ protected function makeCall($Method, $Authorize, array $Data = [])
if($this->APIRoute->count() > 0)
{
$this->UsedRoute = self::CREST_AUTH_ROOT;
$LeafURL = $this->recursiveCall(self::CREST_AUTH_ROOT);
$LeafURL = $this->recursiveCall(self::CREST_AUTH_ROOT, $Authorize);
// check cache
if($Result = $this->Cache->crestCheck($LeafURL, $this->APIRoute->bottom()->Key.' '.$this->APIRoute->bottom()->Value))
{
Expand All @@ -449,7 +479,7 @@ protected function makeCall($Method, $Authorize, array $Data = [])
// if nothing in cache, call API
else
{
$Result = $this->callAPI($LeafURL, $Method, self::AUTHORIZATION_BEARER, $Data))
$Result = $this->callAPI($LeafURL, $Method, $Authorize, $Data));
$this->Cache->crestUpdate($this->UsedRoute, $this->APIRoute->bottom()->Key.' '.$this->APIRoute->bottom()->Value, $Result);
return $Result;
}
Expand All @@ -464,12 +494,13 @@ protected function makeCall($Method, $Authorize, array $Data = [])
* Runs recursive calls down the route
*
* @param string $URL
* @param integer $Authorize
*
* @return string|NULL
*
* @throws \Crester\Exceptions\ResponseSearchException
*/
protected function recursiveCall($URL)
protected function recursiveCall($URL, $Authorize)
{
// check cache
if($Result = $this->Cache->crestCheck($this->UsedRoute, $this->APIRoute->bottom()->Key.' '.$this->APIRoute->bottom()->Value))
Expand All @@ -480,7 +511,7 @@ protected function recursiveCall($URL)
// if nothing in cache, call API
else
{
$Result = $this->callAPI($URL, "GET", self::AUTHORIZATION_BEARER, array()))
$Result = $this->callAPI($URL, "GET", $Authorize, array());
$this->Cache->crestUpdate($this->UsedRoute, $this->APIRoute->bottom()->Key.' '.$this->APIRoute->bottom()->Value, $Result);
$NewURL = $this->search(\json_decode($Result, true), $this->APIRoute->bottom());
}
Expand All @@ -496,7 +527,7 @@ protected function recursiveCall($URL)
// else, get next page
else
{
return $this->recursiveCall($NextPage[0]['href']);
return $this->recursiveCall($NextPage[0]['href'], $Authorize);
}
}
else
Expand All @@ -511,7 +542,7 @@ protected function recursiveCall($URL)
{
// remove last part of route
$this->UsedRoute .= "|".$this->APIRoute->dequeue()->Key."|";
return $this->recursiveCall($NewURL[0]['href']);
return $this->recursiveCall($NewURL[0]['href'], $Authorize);
}
}
}
Expand Down Expand Up @@ -665,6 +696,8 @@ protected function kvsearch_r(array $array, $key, $value, &$results)
}

foreach ($array as $subarray) {
if(!is_array($subarray))
continue;
$this->kvsearch_r($subarray, $key, $value, $results);
}
}
Expand Down Expand Up @@ -697,6 +730,8 @@ protected function ksearch_r(array $array, $key, &$results){
}

foreach ($array as $subarray) {
if(!is_array($subarray))
continue;
$this->ksearch_r($subarray, $key, $results);
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/Core/CRESTBase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
<?php
/*
* MIT License
*
* Copyright (c) 2016 Wizofgoz
*
* 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.
*/
namespace Crester\Core;

abstract class CRESTBase
Expand Down
23 changes: 23 additions & 0 deletions src/Core/RateLimiter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
<?php
/*
* MIT License
*
* Copyright (c) 2016 Wizofgoz
*
* 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.
*/
namespace Crester\Core;
class RateLimiter
{
Expand Down
23 changes: 23 additions & 0 deletions src/Core/RouteNode.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
<?php
/*
* MIT License
*
* Copyright (c) 2016 Wizofgoz
*
* 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.
*/
namespace Crester\Core;
/*
* Class for simplifying the creation of each node of a route
Expand Down
Loading

0 comments on commit 40182b4

Please sign in to comment.