-
Notifications
You must be signed in to change notification settings - Fork 8
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
4 changed files
with
151 additions
and
4 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,42 @@ | ||
<?php | ||
|
||
namespace Yodlee\Api; | ||
|
||
abstract class Api | ||
{ | ||
/** | ||
* Base URL of the Yodlee API. | ||
* | ||
* @var string | ||
*/ | ||
protected $baseUrl = 'https://developer.api.yodlee.com/ysl'; | ||
|
||
/** | ||
* Get the Base URL of Yodlee API. | ||
* | ||
* @return string | ||
*/ | ||
protected function getBaseUrl() | ||
{ | ||
return trim($this->baseUrl, '/'); | ||
} | ||
|
||
/** | ||
* Get the full URL to the endpoint. | ||
* | ||
* @param string | ||
* @param string | ||
* @return string | ||
*/ | ||
protected function getUrl($cobrandName, $endpoint) | ||
{ | ||
$url = sprintf( | ||
'%s/%s/v1/%s', | ||
$this->getBaseUrl(), | ||
trim($cobrandName, '/'), | ||
trim($endpoint, '/') | ||
); | ||
|
||
return $url; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Yodlee\RestClient; | ||
|
||
class Curl | ||
{ | ||
/** | ||
* Call API via cURL. | ||
* | ||
* Regarding CURLOPT_POSTFIELDS, passing an array will encode the request as | ||
* multipart/form-data while URL encoded string will be in | ||
* application/x-www-form-urlencoded. | ||
* @see http://php.net/manual/en/function.curl-setopt.php#84916 | ||
* @see http://stackoverflow.com/a/4073451/4183317 | ||
* | ||
* @param string | ||
* @param string | ||
* @param array | ||
* @return array | ||
*/ | ||
public static function callApi($method = 'GET', $url = '', array $parameters = []) | ||
{ | ||
$return_values = array(); | ||
|
||
$ch = curl_init(); | ||
|
||
curl_setopt_array($ch, [ | ||
CURLOPT_CUSTOMREQUEST => $method, | ||
CURLOPT_URL => $url, | ||
CURLOPT_POSTFIELDS => http_build_query($parameters), | ||
CURLOPT_SSL_VERIFYPEER => false, | ||
CURLOPT_RETURNTRANSFER => 1, | ||
CURLOPT_TIMEOUT => 360 | ||
]); | ||
|
||
$response = curl_exec($ch); | ||
|
||
if (curl_errno($ch)) { | ||
$return_values['Error'] = "Failed to reach $url."; | ||
} else { | ||
if ($response) { | ||
if (gettype($response) == "string") { | ||
$result = json_decode($response); | ||
if ($result) { | ||
$exitsError = array_key_exists("Error", $result); | ||
if ($exitsError) { | ||
// @todo | ||
//$return_values["Body"] = self::_getErrors($result); | ||
$return_values["Body"] = 'Get errors'; | ||
} else { | ||
$return_values["Body"] = $result; | ||
} | ||
} else { | ||
$result = simplexml_load_string($response); | ||
$return_values["Body"] = $response; | ||
} | ||
} else { | ||
$result = json_decode($response); | ||
if ($result === null) { | ||
$return_values['Body'] = "The request does not return any value."; | ||
} else { | ||
$return_values["Body"] = $result; | ||
} | ||
} | ||
} else { | ||
$return_values['Error'] = "Failed to reach $url."; | ||
} | ||
} | ||
|
||
curl_close($ch); | ||
|
||
return $return_values; | ||
} | ||
} |