Skip to content

Commit d1463eb

Browse files
committed
Peer reviews
1 parent 200a3c4 commit d1463eb

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ API Keys are a "password" for your data in an application and should always be t
8686

8787
In our UI you will find an API Settings screen which divides API Keys into two distinct categories:
8888
* Personal Access Tokens, which are scoped to your own user account and can only see and manipulate the data you have access to
89-
* Service Account Keys, which can only be authorized by an Admin and have full access to the data stored in the application
89+
* Service Account Keys, which can only be authorized by an Administrator and have full access to the data stored in the application
9090

9191
For additional information on how to authorize and use PATs and SAKs please see our [developer documentation](https://developer.infusionsoft.com/pat-and-sak/).
9292

src/Infusionsoft/Infusionsoft.php

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -492,25 +492,11 @@ public function request()
492492
// Reset the empty key flag back to the default for the next request
493493
$this->needsEmptyKey = true;
494494

495-
$options = [];
495+
$options = $this->setOptionsForRequest([]);
496496

497-
if ( $this->authenticationType === AuthenticationType::OAuth2AccessToken ) {
498-
$options['headers'] = array(
499-
'Content-Type' => 'application/json',
500-
'Authorization' => 'Bearer ' . $token->getAccessToken()
501-
);
502-
} else {
503-
$options['headers'] = array(
504-
'Content-Type' => 'application/json',
505-
'X-Keap-API-Key' => $this->apikey
506-
);
507-
}
497+
$client = $this->getSerializer();
508498

509-
$client = $this->getSerializer();
510-
511-
$response = $client->request($method, $this->getUrl(), $params, $this->getHttpClient($options));
512-
513-
return $response;
499+
return $client->request($method, $this->getUrl(), $params, $this->getHttpClient($options));
514500
}
515501

516502
/**
@@ -539,17 +525,7 @@ public function restfulRequest($method, $url, $params = array())
539525
$params['body'] = json_encode($params);
540526
}
541527

542-
if ( $this->authenticationType === AuthenticationType::OAuth2AccessToken ) {
543-
$params['headers'] = array(
544-
'Content-Type' => 'application/json',
545-
'Authorization' => 'Bearer ' . $token->getAccessToken()
546-
);
547-
} else {
548-
$params['headers'] = array(
549-
'Content-Type' => 'application/json',
550-
'X-Keap-API-Key' => $this->apikey
551-
);
552-
}
528+
$params = $this->setOptionsForRequest($params);
553529

554530
$response = (string)$client->call($method, $url, $params);
555531

@@ -914,5 +890,25 @@ public function getRestApi($class)
914890
return new $class($this);
915891
}
916892

893+
/**
894+
* @param array $options
895+
* @return array
896+
*/
897+
public function setOptionsForRequest(array $options): array
898+
{
899+
if ($this->authenticationType === AuthenticationType::OAuth2AccessToken) {
900+
$options['headers'] = array(
901+
'Content-Type' => 'application/json',
902+
'Authorization' => 'Bearer ' . $this->getToken()->getAccessToken()
903+
);
904+
} else {
905+
$options['headers'] = array(
906+
'Content-Type' => 'application/json',
907+
'X-Keap-API-Key' => $this->apikey
908+
);
909+
}
910+
return $options;
911+
}
912+
917913
}
918914

0 commit comments

Comments
 (0)