Skip to content

Commit

Permalink
bumping guzzle version,adding user agent header to http client and be…
Browse files Browse the repository at this point in the history
…tter debug control.
  • Loading branch information
padams committed Jul 9, 2022
1 parent 3c1ef0d commit a7ede06
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 19 deletions.
53 changes: 45 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions src/OwaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public function __construct( $config ) {
'instance_url' => '',
'ns' => 'owa_',
'endpoint' => 'api',
'credentials' => []
'credentials' => [],
'debug' => false
];

// override default config with config array passed in.
Expand Down Expand Up @@ -159,11 +160,14 @@ public function makeRequest( $params ) {

$conf = [

'base_uri' => $this->getSetting('instance_url')
'base_uri' => $this->getSetting('instance_url'),

];

$http = $this->getHttpClient( $conf );

//$http->setUserAgent('OWA SDK Client', true);

$uri = $this->getSetting('endpoint') . $params['uri'];

$request_options = [];
Expand All @@ -183,7 +187,8 @@ public function makeRequest( $params ) {
$request_options[ 'headers' ] = [

'X-SIGNATURE' => $this->generateRequestSignature( $params, $credentials ),
'X-API-KEY' => $credentials['api_key']
'X-API-KEY' => $credentials['api_key'],
'User-Agent' => 'OWA SDK Client'

];

Expand Down Expand Up @@ -222,12 +227,16 @@ public function makeRequest( $params ) {
$this->last_response = $res ;

$b = $res->getBody();
$b = json_decode( $b, true);

if ( array_key_exists( 'data', $b ) ) {
if ( $b ) {

return $b['data'];
}
$b = json_decode( $b, true);

if ( $b && array_key_exists( 'data', $b ) ) {

return $b['data'];
}
}
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/sdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class sdk {

private $config;

public static $inDebug;

public function __construct( $config = [] ) {

$this->config = $config;
Expand All @@ -22,6 +24,7 @@ public function __construct( $config = [] ) {
ini_set('display_errors', 1);
error_reporting( -1 );

self::$inDebug = true;

}
}
Expand Down Expand Up @@ -89,12 +92,15 @@ private function addToConfig( $service, $config ) {

static function debug( $msg ) {

if ( is_object( $msg ) || is_array( $msg ) ) {
if ( self::$inDebug ) {

if ( is_object( $msg ) || is_array( $msg ) ) {

$msg = print_r( $msg, true );
}

$msg = print_r( $msg, true );
error_log( $msg . "\n", 3, "./errors.log" );
}

error_log( $msg . "\n", 3, "./errors.log" );
}

}
Expand Down

0 comments on commit a7ede06

Please sign in to comment.