From 85afb10784712414ba039aa0a1b2f90cd010e58f Mon Sep 17 00:00:00 2001 From: Matthew Inamdar Date: Sat, 30 Dec 2017 13:47:31 +0000 Subject: [PATCH] switched to guzzlehttp/guzzle library --- composer.json | 2 +- composer.lock | 254 +++++++++++++++++++++---------------------------- src/Client.php | 20 ++-- 3 files changed, 119 insertions(+), 157 deletions(-) diff --git a/composer.json b/composer.json index db884f1..10a068d 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "require": { "php": ">=7.2", - "guzzle/http": "^3.9" + "guzzlehttp/guzzle": "^6.3" }, "require-dev": { "phpunit/phpunit": "^6.5", diff --git a/composer.lock b/composer.lock index 5a88833..29ea0a9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,86 +4,47 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "1bdc390347fa902889f9ced425b5c532", + "content-hash": "5e5d58579c849f1a887dae1d51fb7753", "packages": [ { - "name": "guzzle/common", - "version": "v3.9.2", - "target-dir": "Guzzle/Common", + "name": "guzzlehttp/guzzle", + "version": "6.3.0", "source": { "type": "git", - "url": "https://github.com/Guzzle3/common.git", - "reference": "2e36af7cf2ce3ea1f2d7c2831843b883a8e7b7dc" + "url": "https://github.com/guzzle/guzzle.git", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Guzzle3/common/zipball/2e36af7cf2ce3ea1f2d7c2831843b883a8e7b7dc", - "reference": "2e36af7cf2ce3ea1f2d7c2831843b883a8e7b7dc", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699", "shasum": "" }, "require": { - "php": ">=5.3.2", - "symfony/event-dispatcher": ">=2.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.7-dev" - } - }, - "autoload": { - "psr-0": { - "Guzzle\\Common": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Common libraries used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "collection", - "common", - "event", - "exception" - ], - "abandoned": "guzzle/guzzle", - "time": "2014-08-11T04:32:36+00:00" - }, - { - "name": "guzzle/http", - "version": "v3.9.2", - "target-dir": "Guzzle/Http", - "source": { - "type": "git", - "url": "https://github.com/Guzzle3/http.git", - "reference": "1e8dd1e2ba9dc42332396f39fbfab950b2301dc5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Guzzle3/http/zipball/1e8dd1e2ba9dc42332396f39fbfab950b2301dc5", - "reference": "1e8dd1e2ba9dc42332396f39fbfab950b2301dc5", - "shasum": "" + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.4", + "php": ">=5.5" }, - "require": { - "guzzle/common": "self.version", - "guzzle/parser": "self.version", - "guzzle/stream": "self.version", - "php": ">=5.3.2" + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0 || ^5.0", + "psr/log": "^1.0" }, "suggest": { - "ext-curl": "*" + "psr/log": "Required for using the Log middleware" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.7-dev" + "dev-master": "6.2-dev" } }, "autoload": { - "psr-0": { - "Guzzle\\Http": "" + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -97,95 +58,107 @@ "homepage": "https://github.com/mtdowling" } ], - "description": "HTTP libraries used by Guzzle", + "description": "Guzzle is a PHP HTTP client library", "homepage": "http://guzzlephp.org/", "keywords": [ - "Guzzle", "client", "curl", + "framework", "http", - "http client" + "http client", + "rest", + "web service" ], - "abandoned": "guzzle/guzzle", - "time": "2014-08-11T04:32:36+00:00" + "time": "2017-06-22T18:50:49+00:00" }, { - "name": "guzzle/parser", - "version": "v3.9.2", - "target-dir": "Guzzle/Parser", + "name": "guzzlehttp/promises", + "version": "v1.3.1", "source": { "type": "git", - "url": "https://github.com/Guzzle3/parser.git", - "reference": "6874d171318a8e93eb6d224cf85e4678490b625c" + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Guzzle3/parser/zipball/6874d171318a8e93eb6d224cf85e4678490b625c", - "reference": "6874d171318a8e93eb6d224cf85e4678490b625c", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", "shasum": "" }, "require": { - "php": ">=5.3.2" + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.7-dev" + "dev-master": "1.4-dev" } }, "autoload": { - "psr-0": { - "Guzzle\\Parser": "" - } + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "Interchangeable parsers used by Guzzle", - "homepage": "http://guzzlephp.org/", + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", "keywords": [ - "URI Template", - "cookie", - "http", - "message", - "url" + "promise" ], - "abandoned": "guzzle/guzzle", - "time": "2014-02-05T18:29:46+00:00" + "time": "2016-12-20T10:07:11+00:00" }, { - "name": "guzzle/stream", - "version": "v3.9.2", - "target-dir": "Guzzle/Stream", + "name": "guzzlehttp/psr7", + "version": "1.4.2", "source": { "type": "git", - "url": "https://github.com/Guzzle3/stream.git", - "reference": "60c7fed02e98d2c518dae8f97874c8f4622100f0" + "url": "https://github.com/guzzle/psr7.git", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Guzzle3/stream/zipball/60c7fed02e98d2c518dae8f97874c8f4622100f0", - "reference": "60c7fed02e98d2c518dae8f97874c8f4622100f0", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", "shasum": "" }, "require": { - "guzzle/common": "self.version", - "php": ">=5.3.2" + "php": ">=5.4.0", + "psr/http-message": "~1.0" }, - "suggest": { - "guzzle/http": "To convert Guzzle request objects to PHP streams" + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.7-dev" + "dev-master": "1.4-dev" } }, "autoload": { - "psr-0": { - "Guzzle\\Stream": "" - } + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -196,62 +169,51 @@ "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" } ], - "description": "Guzzle stream wrapper component", - "homepage": "http://guzzlephp.org/", + "description": "PSR-7 message implementation that also provides common utility methods", "keywords": [ - "Guzzle", - "component", - "stream" + "http", + "message", + "request", + "response", + "stream", + "uri", + "url" ], - "abandoned": "guzzle/guzzle", - "time": "2014-05-01T21:36:02+00:00" + "time": "2017-03-20T17:10:46+00:00" }, { - "name": "symfony/event-dispatcher", - "version": "v4.0.2", + "name": "psr/http-message", + "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "d4face19ed8002eec8280bc1c5ec18130472bf43" + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d4face19ed8002eec8280bc1c5ec18130472bf43", - "reference": "d4face19ed8002eec8280bc1c5ec18130472bf43", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", "shasum": "" }, "require": { - "php": "^7.1.3" - }, - "conflict": { - "symfony/dependency-injection": "<3.4" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~3.4|~4.0", - "symfony/dependency-injection": "~3.4|~4.0", - "symfony/expression-language": "~3.4|~4.0", - "symfony/stopwatch": "~3.4|~4.0" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" + "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] + "Psr\\Http\\Message\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -259,17 +221,21 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "Symfony EventDispatcher Component", - "homepage": "https://symfony.com", - "time": "2017-12-14T19:48:22+00:00" + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" } ], "packages-dev": [ diff --git a/src/Client.php b/src/Client.php index 665c592..55df374 100644 --- a/src/Client.php +++ b/src/Client.php @@ -6,7 +6,7 @@ use GoldSpecDigital\VoodooSmsSdk\Exceptions\ExternalReferenceTooLongException; use GoldSpecDigital\VoodooSmsSdk\Exceptions\MessageTooLongException; -use Guzzle\Http\Client as HttpClient; +use GuzzleHttp\Client as HttpClient; use InvalidArgumentException; class Client @@ -18,7 +18,7 @@ class Client protected const RESPONSE_FORMAT = 'JSON'; /** - * @var \Guzzle\Http\Client + * @var \GuzzleHttp\Client */ protected $httpClient; @@ -37,11 +37,6 @@ class Client */ protected $from; - /** - * @var array - */ - protected $headers = ['Accept' => 'application/json']; - /** * Client constructor. * @@ -51,7 +46,10 @@ class Client */ public function __construct(string $username, string $password, string $from = null) { - $this->httpClient = new HttpClient(static::URI); + $this->httpClient = new HttpClient([ + 'base_uri' => static::URI, + 'headers' => ['Accept' => 'application/json'], + ]); $this->username = $username; $this->password = $password; $this->from = $from; @@ -101,8 +99,7 @@ public function send(string $message, string $to, string $from = null, string $e ]; $parameters = array_filter($parameters, [$this, 'isNotNull']); - $request = $this->httpClient->post($uri, $this->headers, $parameters); - $response = $this->httpClient->send($request); + $response = $this->httpClient->post($uri, ['form_params' => $parameters]); return json_decode((string)$response->getBody()); } @@ -121,8 +118,7 @@ public function getDeliveryStatus(string $referenceID): object 'reference_id' => $referenceID, ]; - $request = $this->httpClient->post($uri, $this->headers, $parameters); - $response = $this->httpClient->send($request); + $response = $this->httpClient->post($uri, ['form_params' => $parameters]); return json_decode((string)$response->getBody()); }