From 7a17137f7cf13f5c50a1cf05b68b70ed2484b9f7 Mon Sep 17 00:00:00 2001 From: Aleh Tanasiuk Date: Wed, 11 Dec 2019 16:28:27 +0300 Subject: [PATCH 1/3] Build SDK specific user-agent for all API requests --- composer.json | 13 ++++++------- composer.lock | 4 ++-- lib/Factory.php | 8 ++++++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index d26558e1..5e9d256a 100644 --- a/composer.json +++ b/composer.json @@ -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 PHP SDK", + "homepage": "https://hubspot.com/" } ], "require": { @@ -32,8 +34,5 @@ "HubSpot\\Client\\" : "codegen/", "HubSpot\\" : "lib/" } - }, - "autoload-dev": { - "psr-4": { "Swagger\\Client\\" : "test/" } } } diff --git a/composer.lock b/composer.lock index bf646bf4..c72c85de 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dcc657d0f6ed86d1f8ee15b77a1f0fda", + "content-hash": "242bd6c445950a5a92856c43df1b7f0f", "packages": [ { "name": "guzzlehttp/guzzle", @@ -2815,7 +2815,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.5", + "php": ">=7.0", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*" diff --git a/lib/Factory.php b/lib/Factory.php index 953e3bd8..62bdc9f5 100644 --- a/lib/Factory.php +++ b/lib/Factory.php @@ -12,7 +12,7 @@ */ class Factory { - const API_KEY_IDENTIFIED = 'hapikey'; + const API_KEY_IDENTIFIER = 'hapikey'; /** @var string */ private $apiKey; @@ -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); } From cc4c183ec2c657b928356ddee3ccd77478c1882e Mon Sep 17 00:00:00 2001 From: Aleh Tanasiuk Date: Wed, 11 Dec 2019 16:31:30 +0300 Subject: [PATCH 2/3] Fix composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5e9d256a..fa18bde7 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "license": "proprietary", "authors": [ { - "name": "HubSpot PHP SDK", + "name": "HubSpot", "homepage": "https://hubspot.com/" } ], From 1413ef0274c85e5971bd75246b0178c28e6f05b9 Mon Sep 17 00:00:00 2001 From: Aleh Tanasiuk Date: Wed, 11 Dec 2019 16:40:24 +0300 Subject: [PATCH 3/3] Switch from private to protected for apiKey&token properties --- lib/Factory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Factory.php b/lib/Factory.php index 62bdc9f5..4b99c348 100644 --- a/lib/Factory.php +++ b/lib/Factory.php @@ -15,10 +15,10 @@ class Factory const API_KEY_IDENTIFIER = 'hapikey'; /** @var string */ - private $apiKey; + protected $apiKey; /** @var string */ - private $accessToken; + protected $accessToken; /** * @param string $name