Skip to content

Commit

Permalink
Merge pull request HubSpot#4 from HubSpot/user-agent
Browse files Browse the repository at this point in the history
 Provide consistent User-Agent header to every API request
  • Loading branch information
atanasiuk-hubspot authored and GitHub Enterprise committed Dec 12, 2019
2 parents bb417ff + 1413ef0 commit a8b4aad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"name": "hubspot/php-hubpost-3",
"name": "hubspot/php-hubspot-3",
"version": "0.1",
"description": "",
"keywords": [
"hubspot",
"swagger",
"php",
"sdk",
"api"
],
"homepage": "http://swagger.io",
"homepage": "https://hubspot.com/",
"license": "proprietary",
"authors": [
{
"name": "Swagger and contributors",
"homepage": "https://github.com/swagger-api/swagger-codegen"
"name": "HubSpot",
"homepage": "https://hubspot.com/"
}
],
"require": {
Expand All @@ -32,8 +34,5 @@
"HubSpot\\Client\\" : "codegen/",
"HubSpot\\" : "lib/"
}
},
"autoload-dev": {
"psr-4": { "Swagger\\Client\\" : "test/" }
}
}
4 changes: 2 additions & 2 deletions composer.lock

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

12 changes: 8 additions & 4 deletions lib/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/
class Factory
{
const API_KEY_IDENTIFIED = 'hapikey';
const API_KEY_IDENTIFIER = 'hapikey';

/** @var string */
private $apiKey;
protected $apiKey;

/** @var string */
private $accessToken;
protected $accessToken;

/**
* @param string $name
Expand All @@ -32,13 +32,17 @@ public function __call($name, $args)
$configuration = '\\HubSpot\\Client\\Crm\\'.ucfirst($name).'\\Configuration';
/** @var Configuration $config */
$config = new $configuration();

if (null !== $this->apiKey) {
$config->setApiKey(static::API_KEY_IDENTIFIED, $this->apiKey);
$config->setApiKey(static::API_KEY_IDENTIFIER, $this->apiKey);
}
if (null !== $this->accessToken) {
$config->setAccessToken($this->accessToken);
}

$package = json_decode(file_get_contents(__DIR__.'/../composer.json'), true);
$config->setUserAgent("{$package['name']}; {$package['version']}");

return new $resource(new Client(), $config);
}

Expand Down

0 comments on commit a8b4aad

Please sign in to comment.