Skip to content

Commit

Permalink
Merge pull request #9 from trevorsibanda/master
Browse files Browse the repository at this point in the history
Added option for json_decode return type
  • Loading branch information
appleboy committed Apr 4, 2015
2 parents 08f85aa + 49bd7bd commit 72b3eef
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion libraries/nexmo.php
Expand Up @@ -41,6 +41,8 @@ class nexmo
private $_api_key;
private $_api_secret;
private $_format = 'json';
//either assoc for (assoc array) or class for ( stdClass )
private $_json_format = 'assoc';

// debug mode
private $_enable_debug = false;
Expand Down Expand Up @@ -611,6 +613,20 @@ public function set_format($format = 'json')

return $this;
}

/**
* Set the json return format
*
* @param String $ JSON format, assoc or class for ASSOC ARRAY and stdClass respectively
*
* @return NULL
*/
public function set_json_format( $format = 'assoc' )
{
if( $format !== 'assoc' and $format !== 'class' )
$format = 'assoc';
$this->_json_format = $format;
}

/**
*
Expand All @@ -626,7 +642,10 @@ protected function response()
break;
case 'json':
default:
$response_obj = json_decode($this->_http_response);
{
$is_assoc = ( $this->_json_format === 'assoc' ) ? TRUE : FALSE;
$response_obj = json_decode($this->_http_response , $is_assoc );
}
}

return $response_obj;
Expand Down

0 comments on commit 72b3eef

Please sign in to comment.