Skip to content

Commit

Permalink
Added in ability to change token type
Browse files Browse the repository at this point in the history
  • Loading branch information
JWMarchant committed Feb 3, 2016
1 parent 685c33c commit 7f778bf
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions optimizely.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ class Optimizely {
protected $ssl_verifypeer = FALSE;

/**
* Optimize API token
* Optimizely API token
*/
protected $api_token;

/**
* Optimizely API token type
*/
protected $token_type = 'default';

/**
* base url for API
*/
Expand All @@ -63,8 +68,9 @@ class Optimizely {
/**
* Setup the object
*/
public function __construct( $api_token ) {
public function __construct( $api_token, $token_type = 'default' ) {
$this->api_token = $api_token;
$this->token_type = $token_type;
}// end __construct

/**
Expand All @@ -91,10 +97,18 @@ protected function request( $options ) {
curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer );
curl_setopt( $c, CURLOPT_HEADER, FALSE );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $c, CURLOPT_HTTPHEADER, array(
'Token: ' . $this->api_token,
'Content-Type: application/json'
) );

if ( $this->token_type === 'oauth' ) {
curl_setopt( $c, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $this->api_token,
'Content-Type: application/json'
) );
} else {
curl_setopt( $c, CURLOPT_HTTPHEADER, array(
'Token: ' . $this->api_token,
'Content-Type: application/json'
) );
}

$url = $this->api_url . $options['function'];

Expand Down

0 comments on commit 7f778bf

Please sign in to comment.