-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
10 changed files
with
127 additions
and
14 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,60 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
class EvidencioAPI | ||
{ | ||
/* | ||
* @return API response converted into a PHP variable. | ||
* @throws JsonDecodeException if JSON response could not be decoded. | ||
* Other possible exceptions are listed in Guzzle's documentation | ||
*/ | ||
private static function fetch($path, $params = []) | ||
{ | ||
$client = new \GuzzleHttp\Client(['base_uri' => 'https://www.evidencio.com/api/']); | ||
$res = $client->post($path, | ||
[ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => config('app.evidencio_key') | ||
], | ||
'form_params' => $params | ||
]); | ||
$json = json_decode($res->getBody()); | ||
if(is_null($json)) | ||
{ | ||
throw new Exceptions\JsonDecodeException("Could not decode API response to JSON: '".$res->getBody()."'."); | ||
} | ||
return $json; | ||
} | ||
|
||
public static function overview() | ||
{ | ||
return self::fetch("overview"); | ||
} | ||
|
||
public static function search($query) | ||
{ | ||
return self::fetch("search",["query" => $query]); | ||
} | ||
|
||
public static function models() | ||
{ | ||
return self::fetch("models"); | ||
} | ||
|
||
public static function getModel($id) | ||
{ | ||
return self::fetch("model",["id" => $id]); | ||
} | ||
|
||
/* | ||
* @param $values array of key-value pairs for each variable where id is the key | ||
*/ | ||
public static function run($id,$values) | ||
{ | ||
$values["id"] = $id; | ||
return self::fetch("run",$values); | ||
} | ||
|
||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
|
||
class JsonDecodeException extends Exception { } |
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
Binary file not shown.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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