From 5ae67da57827c31e47d0e7bf5e88868f3c055bf1 Mon Sep 17 00:00:00 2001 From: Nicolas Menescardi Date: Thu, 13 Feb 2020 10:48:06 -0300 Subject: [PATCH] Modify API Client using Intrinio V2 --- src/Intrinio.php | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Intrinio.php b/src/Intrinio.php index 7c5a043..1cf48ac 100644 --- a/src/Intrinio.php +++ b/src/Intrinio.php @@ -5,28 +5,32 @@ use Requests; /** -* Intrinio Client -*/ -class Intrinio { + * Intrinio Client + */ +class Intrinio +{ - const API_HOST = 'https://api.intrinio.com'; + const API_HOST = 'https://api-v2.intrinio.com'; /** * @var string */ - protected $options; + protected $options; + protected $token; - /** * Intrinio constructor. * * @param string $username * @param string $password */ - function __construct($username, $password) { + function __construct($username, $password, $token) + { $this->options = array( 'auth' => array($username, $password) - ); + ); + + $this->token = $token; } @@ -36,13 +40,15 @@ function __construct($username, $password) { * @param string $slug * @param array $params */ - public function request($slug, $params = []) { + public function request($slug, $params = []) + { $headers = array( - 'Accept' => 'application/json', - 'Accept-Encoding' =>'gzip, deflate' - ); + 'Accept' => 'application/json', + 'Accept-Encoding' => 'gzip, deflate', + 'Authorization' => 'Bearer ' . $this->token + ); $uri = $this->uriConstruct($slug, $params); - $response = Requests::get($uri , $headers, $this->options); + $response = Requests::get($uri, $headers, $this->options); return $response->body; } @@ -55,7 +61,8 @@ public function request($slug, $params = []) { * @param array $params * @return string */ - private function uriConstruct($slug, $params) { + private function uriConstruct($slug, $params) + { $uri = self::API_HOST . '/' . $slug; if ($params) { $queryData = http_build_query($params); @@ -64,4 +71,4 @@ private function uriConstruct($slug, $params) { return $uri; } -} \ No newline at end of file +}