Skip to content

Modify API Client using Intrinio V2 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/Intrinio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -64,4 +71,4 @@ private function uriConstruct($slug, $params) {

return $uri;
}
}
}