From d2e16e0549484259e1dfa9e192c9b6517027fe4f Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Mon, 18 Oct 2021 08:14:02 +0200 Subject: [PATCH 01/16] feat: credential chaching --- .gitignore | 6 + composer.json | 46 +++-- composer.lock | 529 +++++++++++++++++++++++++++++++++++++++++++++++ src/OnenceWS.php | 96 +++++---- 4 files changed, 606 insertions(+), 71 deletions(-) create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index 264b736..c2f6b64 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ test.php +composer.phar +/vendor/ + +# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock diff --git a/composer.json b/composer.json index 7f903b1..8405597 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,27 @@ { - "name": "pipinstallpip/onencews", - "type": "library", - "description": "Http client for official 1nce rest api https://api.1nce.com", - "keywords": ["1nce","once","onence","client","http"], - "license": "MIT", - "homepage": "https://github.com/pipinstallpip/1nce", - "authors": [ - { - "name": "pipinstallpip", - "role": "Developer" - } - ], - "require": { - "guzzlehttp/guzzle": "~6.0" - }, - "autoload": { - "psr-4": { - "pipinstallpip\\onencews\\": "src/" - } - }, - "minimum-stability": "dev" + "name": "esyoil-gmbh/onencews", + "type": "library", + "description": "Http client for official 1nce rest api https://api.1nce.com", + "keywords": [ + "1nce", + "once", + "onence", + "client", + "http" + ], + "license": "MIT", + "homepage": "https://github.com/esyoil-gmbh/1nce", + "authors": [{ + "name": "esyoil-gmbh", + "role": "Developer" + }], + "require": { + "guzzlehttp/guzzle": "~6.0" + }, + "autoload": { + "psr-4": { + "pipinstallpip\\onencews\\": "src/" + } + }, + "minimum-stability": "dev" } \ No newline at end of file diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..415c9b5 --- /dev/null +++ b/composer.lock @@ -0,0 +1,529 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "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": "446748c554ed22a66a6276d17196d7f8", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "6.5.x-dev", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "e8ed4dbf49b260ff129ff0e0400718c3269971bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/e8ed4dbf49b260ff129ff0e0400718c3269971bf", + "reference": "e8ed4dbf49b260ff129ff0e0400718c3269971bf", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.6.1", + "php": ">=5.5", + "symfony/polyfill-intl-idn": "^1.17.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", + "psr/log": "^1.1" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.5-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2020-07-02T06:52:04+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "b2e8301545358f39b94576b34b305b89cee04193" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/b2e8301545358f39b94576b34b305b89cee04193", + "reference": "b2e8301545358f39b94576b34b305b89cee04193", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "symfony/phpunit-bridge": "^4.4 || ^5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2021-10-14T23:58:19+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.x-dev", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/1afdd860a2566ed3c2b0b4a3de6e23434a79ec85", + "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "ext-zlib": "*", + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2021-10-05T13:56:00+00:00" + }, + { + "name": "psr/http-message", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", + "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2019-08-29T13:16:46+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "symfony/polyfill-intl-idn", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-idn.git", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/749045c69efb97c70d25d7463abba812e91f3a44", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "symfony/polyfill-intl-normalizer": "^1.10", + "symfony/polyfill-php72": "^1.10" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Idn\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Laurent Bassin", + "email": "laurent@bassin.info" + }, + { + "name": "Trevor Rowbotham", + "email": "trevor.rowbotham@pm.me" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "idn", + "intl", + "polyfill", + "portable", + "shim" + ], + "time": "2021-09-14T14:02:44+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8", + "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "time": "2021-02-19T12:13:01+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/9a142215a36a3888e30d0a9eeea9766764e96976", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2021-05-27T09:17:38+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/src/OnenceWS.php b/src/OnenceWS.php index cadef02..3c1b144 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -9,8 +9,7 @@ use \stdClass; -class OnenceWS extends Client -{ +class OnenceWS extends Client { const ACTIVATED = 'Activated'; const DISABLED = 'Disabled'; @@ -21,7 +20,7 @@ class OnenceWS extends Client private $clientId; private $clientSecret; - private $encodedAuthorization ; + private $encodedAuthorization; private $authToken; private $tokenType; private $expiresIn; @@ -29,8 +28,7 @@ class OnenceWS extends Client private $apiVersion; - public function __construct($clientId,$clientSecret,$version = self::V1) - { + public function __construct($clientId, $clientSecret, $version = self::V1) { parent::__construct(['base_uri' => self::$baseUrl]); $this->clientId = $clientId; $this->clientSecret = $clientSecret; @@ -41,8 +39,10 @@ public function __construct($clientId,$clientSecret,$version = self::V1) /** * @return Request */ - private function __getTokenRequest(){ - return new Request('POST',"{$this::$baseUrl}/oauth/token", + private function __getTokenRequest() { + return new Request( + 'POST', + "{$this::$baseUrl}/oauth/token", [ 'Content-Type' => 'application/x-www-form-urlencoded', 'authorization' => "Basic $this->encodedAuthorization" @@ -55,9 +55,14 @@ private function __getTokenRequest(){ * @return void setta auth token. * @throws ErrorException */ - private function __setAuthToken(){ - $responseContent = json_decode($this->send($this->__getTokenRequest())->getBody()->getContents()); - if((isset($responseContent->access_token))){ + private function __setAuthToken() { + if (!\apcu_exists("1nce_auth_token")) { + $responseContent = json_decode($this->send($this->__getTokenRequest())->getBody()->getContents()); + \apcu_store("1nce_auth_token", $responseContent, $responseContent->expires_in); + } else { + $responseContent = \apcu_fetch("1nce_auth_token"); + } + if ((isset($responseContent->access_token))) { $this->authToken = $responseContent->access_token; $this->tokenType = $responseContent->token_type; $this->expiresIn = $responseContent->expires_in; @@ -70,7 +75,7 @@ private function __setAuthToken(){ 'Accept-Encoding' => 'gzip, deflate', 'Connection' => 'keep-alive', ]; - }else{ + } else { throw new ErrorException('Errore durante il decoding del access token'); } } @@ -82,9 +87,9 @@ private function __setAuthToken(){ * @param string $type * @param array $params */ - private function __prepare($url,$type,$params = []){ + private function __prepare($url, $type, $params = []) { $this->__setAuthToken(); - return new Request($type,"{$this::$baseUrl}/$this->apiVersion/$url?access_token=$this->authToken", $this->header, json_encode($params)); + return new Request($type, "{$this::$baseUrl}/$this->apiVersion/$url?access_token=$this->authToken", $this->header, json_encode($params)); } @@ -95,8 +100,8 @@ private function __prepare($url,$type,$params = []){ * @param string $type * @param array $params */ - private function __standard($url,$type,$params = []){ - return $this->send($this->__prepare($url,$type,$params)); + private function __standard($url, $type, $params = []) { + return $this->send($this->__prepare($url, $type, $params)); } /** @@ -105,8 +110,8 @@ private function __standard($url,$type,$params = []){ * @param array $params * @throws ErrorException */ - private function __standardGet($url,$params = []){ - return json_decode($this->__standard($url,'GET',$params)->getBody()->getContents()); + private function __standardGet($url, $params = []) { + return json_decode($this->__standard($url, 'GET', $params)->getBody()->getContents()); } /** @@ -115,8 +120,8 @@ private function __standardGet($url,$params = []){ * @param array $params * @throws ErrorException */ - private function __standardPost($url,$params = []){ - return $this->__standard($url,'POST',$params)->getStatusCode(); + private function __standardPost($url, $params = []) { + return $this->__standard($url, 'POST', $params)->getStatusCode(); } /** @@ -125,8 +130,8 @@ private function __standardPost($url,$params = []){ * @param array $params * @throws ErrorException */ - private function __standardPut($url,$params = []){ - return $this->__standard($url,'PUT',$params)->getStatusCode(); + private function __standardPut($url, $params = []) { + return $this->__standard($url, 'PUT', $params)->getStatusCode(); } /** @@ -135,8 +140,8 @@ private function __standardPut($url,$params = []){ * @param array $params * @throws ErrorException */ - private function __standardDelete($url,$params = []){ - return $this->__standard($url,'DELETE',$params)->getStatusCode(); + private function __standardDelete($url, $params = []) { + return $this->__standard($url, 'DELETE', $params)->getStatusCode(); } @@ -145,7 +150,7 @@ private function __standardDelete($url,$params = []){ /** * get all sims */ - public function getSimsList(){ + public function getSimsList() { return $this->__standardGet('sims'); } @@ -154,7 +159,7 @@ public function getSimsList(){ * @throws ErrorException * @return stdClass */ - public function getSimReachibility($iccid){ + public function getSimReachibility($iccid) { return $this->__standardGet("sims/$iccid/connectivity_info"); } @@ -163,8 +168,7 @@ public function getSimReachibility($iccid){ * @throws ErrorException * @return stdClass */ - public function getSimUsage($iccid) - { + public function getSimUsage($iccid) { return $this->__standardGet("sims/$iccid/usage"); } @@ -173,8 +177,7 @@ public function getSimUsage($iccid) * @throws ErrorException * @return stdClass */ - public function getSimRemainingData($iccid) - { + public function getSimRemainingData($iccid) { return $this->__standardGet("sims/$iccid/quota/data"); } @@ -183,8 +186,7 @@ public function getSimRemainingData($iccid) * @throws ErrorException * @return stdClass */ - public function getSimRemainingSms($iccid) - { + public function getSimRemainingSms($iccid) { return $this->__standardGet("sims/$iccid/quota/sms"); } @@ -193,8 +195,7 @@ public function getSimRemainingSms($iccid) * @throws ErrorException * @return stdClass */ - public function getSmsList($iccid) - { + public function getSmsList($iccid) { return $this->__standardGet("sims/$iccid/sms"); } @@ -203,8 +204,7 @@ public function getSmsList($iccid) * @throws ErrorException * @return stdClass */ - public function getSimInfo($iccid) - { + public function getSimInfo($iccid) { return $this->__standardGet("sims/$iccid"); } @@ -213,8 +213,7 @@ public function getSimInfo($iccid) * @throws ErrorException * @return stdClass */ - public function getSimStatus($iccid) - { + public function getSimStatus($iccid) { return $this->__standardGet("sims/$iccid/status"); } @@ -223,8 +222,7 @@ public function getSimStatus($iccid) * @throws ErrorException * @return stdClass */ - public function getSimEvents($iccid) - { + public function getSimEvents($iccid) { return $this->__standardGet("sims/$iccid/events"); } @@ -234,8 +232,7 @@ public function getSimEvents($iccid) * @throws ErrorException * @return stdClass */ - public function getSmsDetails($iccid,$idSms) - { + public function getSmsDetails($iccid, $idSms) { return $this->__standardGet("sims/$iccid/sms/$idSms"); } @@ -255,8 +252,8 @@ public function getSmsDetails($iccid,$idSms) * @throws ErrorException * @return int */ - public function sendSms($iccid,$sms,$expiry_date = null,$source_address = 1234567890,$udh = 'string',$dcs = 8){ - if(is_null($expiry_date)) + public function sendSms($iccid, $sms, $expiry_date = null, $source_address = 1234567890, $udh = 'string', $dcs = 8) { + if (is_null($expiry_date)) $expiry_date = date("Y-m-d", strtotime("+7 days")); return $this->__standardPost( @@ -269,7 +266,7 @@ public function sendSms($iccid,$sms,$expiry_date = null,$source_address = 123456 'source_address_type' => [ 'id' => 145 ], - 'expiry_date' => $expiry_date.'T18:10:29.000+0000' + 'expiry_date' => $expiry_date . 'T18:10:29.000+0000' ] ); } @@ -279,7 +276,7 @@ public function sendSms($iccid,$sms,$expiry_date = null,$source_address = 123456 * @throws ErrorException * @return int */ - public function resetSim($iccid){ + public function resetSim($iccid) { return $this->__standardPost("sims/$iccid/reset"); } //INFO: END POST REQUEST @@ -293,9 +290,10 @@ public function resetSim($iccid){ * @throws ErrorException * @return int */ - public function changeSimState($iccid,$newStatus ,$newLabel = '' ,$imeiLock = true){ + public function changeSimState($iccid, $newStatus, $newLabel = '', $imeiLock = true) { return $this->__standardPut( - "sims/$iccid",[ + "sims/$iccid", + [ "iccid" => $iccid, "label" => $newLabel, "imei_lock" => $imeiLock, @@ -314,12 +312,10 @@ public function changeSimState($iccid,$newStatus ,$newLabel = '' ,$imeiLock = tr * @throws ErrorException * @return int */ - public function deleteSpecificSms($iccid,$smsId) - { + public function deleteSpecificSms($iccid, $smsId) { return $this->__standardDelete("sims/$iccid/sms/$smsId"); } //INFO: END DELETE REQUEST } - From 05611fd09f432480f0f17844281a17dd49cd50ba Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Mon, 18 Oct 2021 08:16:06 +0200 Subject: [PATCH 02/16] chore: updated readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index c0578e2..05735e5 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,13 @@ OnenceWS Http client for official 1nce rest api https://api.1nce.com composer require pipinstallpip/onencews:dev-master ``` +Make sure that you have the PHP Module for `APCu` enabled and loaded. This is used to store the oauth2-token for subsequent requests, so we do not exhaust the ratelimit of the Endpoint. +You can check this by running: +```sh +php -m | grep apcu +``` +in your terminal. + ## Usage ```php From 8f70ee2cb66e2f026576a67474209ffd7cf75087 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Mon, 18 Oct 2021 08:17:42 +0200 Subject: [PATCH 03/16] chore: translation --- src/OnenceWS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index 3c1b144..0b8345a 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -76,7 +76,7 @@ private function __setAuthToken() { 'Connection' => 'keep-alive', ]; } else { - throw new ErrorException('Errore durante il decoding del access token'); + throw new ErrorException('Error while getting an authorization token.'); } } From 9875385a5f18939d8bd0fc5665734e4d2c85f7b1 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Mon, 25 Oct 2021 11:48:39 +0200 Subject: [PATCH 04/16] chore: update deps --- composer.json | 4 +- composer.lock | 339 +++++++++++++++++++++++++------------------------- 2 files changed, 171 insertions(+), 172 deletions(-) diff --git a/composer.json b/composer.json index 8405597..8385519 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "role": "Developer" }], "require": { - "guzzlehttp/guzzle": "~6.0" + "guzzlehttp/guzzle": "^7.0" }, "autoload": { "psr-4": { @@ -24,4 +24,4 @@ } }, "minimum-stability": "dev" -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 415c9b5..71c1be4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,41 +4,49 @@ "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": "446748c554ed22a66a6276d17196d7f8", + "content-hash": "f820d54fb06d6f80a9b6ccdceb679bd4", "packages": [ { "name": "guzzlehttp/guzzle", - "version": "6.5.x-dev", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "e8ed4dbf49b260ff129ff0e0400718c3269971bf" + "reference": "868b3571a039f0ebc11ac8f344f4080babe2cb94" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/e8ed4dbf49b260ff129ff0e0400718c3269971bf", - "reference": "e8ed4dbf49b260ff129ff0e0400718c3269971bf", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/868b3571a039f0ebc11ac8f344f4080babe2cb94", + "reference": "868b3571a039f0ebc11ac8f344f4080babe2cb94", "shasum": "" }, "require": { "ext-json": "*", - "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.6.1", - "php": ">=5.5", - "symfony/polyfill-intl-idn": "^1.17.0" + "guzzlehttp/promises": "^1.5", + "guzzlehttp/psr7": "^1.8.3 || ^2.1", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2" + }, + "provide": { + "psr/http-client-implementation": "1.0" }, "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", "ext-curl": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", - "psr/log": "^1.1" + "php-http/client-integration-tests": "^3.0", + "phpunit/phpunit": "^8.5.5 || ^9.3.5", + "psr/log": "^1.1 || ^2.0 || ^3.0" }, "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", "psr/log": "Required for using the Log middleware" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "6.5-dev" + "dev-master": "7.4-dev" } }, "autoload": { @@ -54,24 +62,55 @@ "MIT" ], "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" } ], "description": "Guzzle is a PHP HTTP client library", - "homepage": "http://guzzlephp.org/", "keywords": [ "client", "curl", "framework", "http", "http client", + "psr-18", + "psr-7", "rest", "web service" ], - "time": "2020-07-02T06:52:04+00:00" + "time": "2021-10-18T09:52:00+00:00" }, { "name": "guzzlehttp/promises", @@ -79,12 +118,12 @@ "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "b2e8301545358f39b94576b34b305b89cee04193" + "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/b2e8301545358f39b94576b34b305b89cee04193", - "reference": "b2e8301545358f39b94576b34b305b89cee04193", + "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da", + "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da", "shasum": "" }, "require": { @@ -137,33 +176,36 @@ "keywords": [ "promise" ], - "time": "2021-10-14T23:58:19+00:00" + "time": "2021-10-22T20:56:57+00:00" }, { "name": "guzzlehttp/psr7", - "version": "1.x-dev", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85" + "reference": "9e3511bee5efa86e591fb27efb7a894571c7a244" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/1afdd860a2566ed3c2b0b4a3de6e23434a79ec85", - "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/9e3511bee5efa86e591fb27efb7a894571c7a244", + "reference": "9e3511bee5efa86e591fb27efb7a894571c7a244", "shasum": "" }, "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "ralouphie/getallheaders": "^3.0" }, "provide": { + "psr/http-factory-implementation": "1.0", "psr/http-message-implementation": "1.0" }, "require-dev": { - "ext-zlib": "*", - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" + "bamarni/composer-bin-plugin": "^1.4.1", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.8 || ^9.3.10" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" @@ -171,16 +213,13 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7-dev" + "dev-master": "2.1-dev" } }, "autoload": { "psr-4": { "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -216,6 +255,11 @@ "name": "Tobias Schultze", "email": "webmaster@tubo-world.de", "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" } ], "description": "PSR-7 message implementation that also provides common utility methods", @@ -229,24 +273,25 @@ "uri", "url" ], - "time": "2021-10-05T13:56:00+00:00" + "time": "2021-10-21T23:15:39+00:00" }, { - "name": "psr/http-message", + "name": "psr/http-client", "version": "dev-master", "source": { "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4" + "url": "https://github.com/php-fig/http-client.git", + "reference": "22b2ef5687f43679481615605d7a15c557ce85b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", - "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/22b2ef5687f43679481615605d7a15c557ce85b1", + "reference": "22b2ef5687f43679481615605d7a15c557ce85b1", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0" }, "type": "library", "extra": { @@ -256,7 +301,7 @@ }, "autoload": { "psr-4": { - "Psr\\Http\\Message\\": "src/" + "Psr\\Http\\Client\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -266,47 +311,47 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", "keywords": [ "http", - "http-message", + "http-client", "psr", - "psr-7", - "request", - "response" + "psr-18" ], - "time": "2019-08-29T13:16:46+00:00" + "time": "2020-09-19T09:12:31+00:00" }, { - "name": "ralouphie/getallheaders", - "version": "3.0.3", + "name": "psr/http-factory", + "version": "dev-master", "source": { "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" + "url": "https://github.com/php-fig/http-factory.git", + "reference": "36fa03d50ff82abcae81860bdaf4ed9a1510c7cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/36fa03d50ff82abcae81860bdaf4ed9a1510c7cd", + "reference": "36fa03d50ff82abcae81860bdaf4ed9a1510c7cd", "shasum": "" }, "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" + "php": ">=7.0.0", + "psr/http-message": "^1.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { - "files": [ - "src/getallheaders.php" - ] + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -314,52 +359,50 @@ ], "authors": [ { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" } ], - "description": "A polyfill for getallheaders.", - "time": "2019-03-08T08:55:37+00:00" + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "time": "2020-09-17T16:52:55+00:00" }, { - "name": "symfony/polyfill-intl-idn", - "version": "dev-main", + "name": "psr/http-message", + "version": "dev-master", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "749045c69efb97c70d25d7463abba812e91f3a44" + "url": "https://github.com/php-fig/http-message.git", + "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/749045c69efb97c70d25d7463abba812e91f3a44", - "reference": "749045c69efb97c70d25d7463abba812e91f3a44", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", + "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", "shasum": "" }, "require": { - "php": ">=7.1", - "symfony/polyfill-intl-normalizer": "^1.10", - "symfony/polyfill-php72": "^1.10" - }, - "suggest": { - "ext-intl": "For best performance" + "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "dev-master": "1.0.x-dev" } }, "autoload": { "psr-4": { - "Symfony\\Polyfill\\Intl\\Idn\\": "" - }, - "files": [ - "bootstrap.php" - ] + "Psr\\Http\\Message\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -367,69 +410,47 @@ ], "authors": [ { - "name": "Laurent Bassin", - "email": "laurent@bassin.info" - }, - { - "name": "Trevor Rowbotham", - "email": "trevor.rowbotham@pm.me" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", - "homepage": "https://symfony.com", + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", "keywords": [ - "compatibility", - "idn", - "intl", - "polyfill", - "portable", - "shim" + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" ], - "time": "2021-09-14T14:02:44+00:00" + "time": "2019-08-29T13:16:46+00:00" }, { - "name": "symfony/polyfill-intl-normalizer", - "version": "dev-main", + "name": "ralouphie/getallheaders", + "version": "3.0.3", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8" + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8", - "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=5.6" }, - "suggest": { - "ext-intl": "For best performance" + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" }, "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Intl\\Normalizer\\": "" - }, "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" + "src/getallheaders.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -438,38 +459,25 @@ ], "authors": [ { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" } ], - "description": "Symfony polyfill for intl's Normalizer class and related functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "intl", - "normalizer", - "polyfill", - "portable", - "shim" - ], - "time": "2021-02-19T12:13:01+00:00" + "description": "A polyfill for getallheaders.", + "time": "2019-03-08T08:55:37+00:00" }, { - "name": "symfony/polyfill-php72", - "version": "dev-main", + "name": "symfony/deprecation-contracts", + "version": "2.5.x-dev", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "9a142215a36a3888e30d0a9eeea9766764e96976" + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/9a142215a36a3888e30d0a9eeea9766764e96976", - "reference": "9a142215a36a3888e30d0a9eeea9766764e96976", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/6f981ee24cf69ee7ce9736146d1c57c2780598a8", + "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8", "shasum": "" }, "require": { @@ -478,19 +486,16 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.23-dev" + "dev-main": "2.5-dev" }, "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php72\\": "" - }, "files": [ - "bootstrap.php" + "function.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -507,15 +512,9 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "time": "2021-05-27T09:17:38+00:00" + "time": "2021-07-12T14:48:14+00:00" } ], "packages-dev": [], From 58b0a3500e9e5533e8d6ab22be39bd01e3b4fab9 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Mon, 25 Oct 2021 11:50:24 +0200 Subject: [PATCH 05/16] Revert "chore: update deps" This reverts commit 9875385a5f18939d8bd0fc5665734e4d2c85f7b1. --- composer.json | 4 +- composer.lock | 339 +++++++++++++++++++++++++------------------------- 2 files changed, 172 insertions(+), 171 deletions(-) diff --git a/composer.json b/composer.json index 8385519..8405597 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "role": "Developer" }], "require": { - "guzzlehttp/guzzle": "^7.0" + "guzzlehttp/guzzle": "~6.0" }, "autoload": { "psr-4": { @@ -24,4 +24,4 @@ } }, "minimum-stability": "dev" -} +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index 71c1be4..415c9b5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,49 +4,41 @@ "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": "f820d54fb06d6f80a9b6ccdceb679bd4", + "content-hash": "446748c554ed22a66a6276d17196d7f8", "packages": [ { "name": "guzzlehttp/guzzle", - "version": "dev-master", + "version": "6.5.x-dev", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "868b3571a039f0ebc11ac8f344f4080babe2cb94" + "reference": "e8ed4dbf49b260ff129ff0e0400718c3269971bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/868b3571a039f0ebc11ac8f344f4080babe2cb94", - "reference": "868b3571a039f0ebc11ac8f344f4080babe2cb94", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/e8ed4dbf49b260ff129ff0e0400718c3269971bf", + "reference": "e8ed4dbf49b260ff129ff0e0400718c3269971bf", "shasum": "" }, "require": { "ext-json": "*", - "guzzlehttp/promises": "^1.5", - "guzzlehttp/psr7": "^1.8.3 || ^2.1", - "php": "^7.2.5 || ^8.0", - "psr/http-client": "^1.0", - "symfony/deprecation-contracts": "^2.2" - }, - "provide": { - "psr/http-client-implementation": "1.0" + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.6.1", + "php": ">=5.5", + "symfony/polyfill-intl-idn": "^1.17.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", "ext-curl": "*", - "php-http/client-integration-tests": "^3.0", - "phpunit/phpunit": "^8.5.5 || ^9.3.5", - "psr/log": "^1.1 || ^2.0 || ^3.0" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", + "psr/log": "^1.1" }, "suggest": { - "ext-curl": "Required for CURL handler support", - "ext-intl": "Required for Internationalized Domain Name (IDN) support", "psr/log": "Required for using the Log middleware" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "7.4-dev" + "dev-master": "6.5-dev" } }, "autoload": { @@ -62,55 +54,24 @@ "MIT" ], "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" - }, - { - "name": "Jeremy Lindblom", - "email": "jeremeamia@gmail.com", - "homepage": "https://github.com/jeremeamia" - }, - { - "name": "George Mponos", - "email": "gmponos@gmail.com", - "homepage": "https://github.com/gmponos" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://github.com/sagikazarmark" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" } ], "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", "keywords": [ "client", "curl", "framework", "http", "http client", - "psr-18", - "psr-7", "rest", "web service" ], - "time": "2021-10-18T09:52:00+00:00" + "time": "2020-07-02T06:52:04+00:00" }, { "name": "guzzlehttp/promises", @@ -118,12 +79,12 @@ "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da" + "reference": "b2e8301545358f39b94576b34b305b89cee04193" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da", - "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da", + "url": "https://api.github.com/repos/guzzle/promises/zipball/b2e8301545358f39b94576b34b305b89cee04193", + "reference": "b2e8301545358f39b94576b34b305b89cee04193", "shasum": "" }, "require": { @@ -176,36 +137,33 @@ "keywords": [ "promise" ], - "time": "2021-10-22T20:56:57+00:00" + "time": "2021-10-14T23:58:19+00:00" }, { "name": "guzzlehttp/psr7", - "version": "dev-master", + "version": "1.x-dev", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "9e3511bee5efa86e591fb27efb7a894571c7a244" + "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/9e3511bee5efa86e591fb27efb7a894571c7a244", - "reference": "9e3511bee5efa86e591fb27efb7a894571c7a244", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/1afdd860a2566ed3c2b0b4a3de6e23434a79ec85", + "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85", "shasum": "" }, "require": { - "php": "^7.2.5 || ^8.0", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.0", - "ralouphie/getallheaders": "^3.0" + "php": ">=5.4.0", + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" }, "provide": { - "psr/http-factory-implementation": "1.0", "psr/http-message-implementation": "1.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", - "http-interop/http-factory-tests": "^0.9", - "phpunit/phpunit": "^8.5.8 || ^9.3.10" + "ext-zlib": "*", + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" @@ -213,13 +171,16 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "1.7-dev" } }, "autoload": { "psr-4": { "GuzzleHttp\\Psr7\\": "src/" - } + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -255,11 +216,6 @@ "name": "Tobias Schultze", "email": "webmaster@tubo-world.de", "homepage": "https://github.com/Tobion" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://sagikazarmark.hu" } ], "description": "PSR-7 message implementation that also provides common utility methods", @@ -273,25 +229,24 @@ "uri", "url" ], - "time": "2021-10-21T23:15:39+00:00" + "time": "2021-10-05T13:56:00+00:00" }, { - "name": "psr/http-client", + "name": "psr/http-message", "version": "dev-master", "source": { "type": "git", - "url": "https://github.com/php-fig/http-client.git", - "reference": "22b2ef5687f43679481615605d7a15c557ce85b1" + "url": "https://github.com/php-fig/http-message.git", + "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/22b2ef5687f43679481615605d7a15c557ce85b1", - "reference": "22b2ef5687f43679481615605d7a15c557ce85b1", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", + "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", "shasum": "" }, "require": { - "php": "^7.0 || ^8.0", - "psr/http-message": "^1.0" + "php": ">=5.3.0" }, "type": "library", "extra": { @@ -301,7 +256,7 @@ }, "autoload": { "psr-4": { - "Psr\\Http\\Client\\": "src/" + "Psr\\Http\\Message\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -311,47 +266,47 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" + "homepage": "http://www.php-fig.org/" } ], - "description": "Common interface for HTTP clients", - "homepage": "https://github.com/php-fig/http-client", + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", "keywords": [ "http", - "http-client", + "http-message", "psr", - "psr-18" + "psr-7", + "request", + "response" ], - "time": "2020-09-19T09:12:31+00:00" + "time": "2019-08-29T13:16:46+00:00" }, { - "name": "psr/http-factory", - "version": "dev-master", + "name": "ralouphie/getallheaders", + "version": "3.0.3", "source": { "type": "git", - "url": "https://github.com/php-fig/http-factory.git", - "reference": "36fa03d50ff82abcae81860bdaf4ed9a1510c7cd" + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/36fa03d50ff82abcae81860bdaf4ed9a1510c7cd", - "reference": "36fa03d50ff82abcae81860bdaf4ed9a1510c7cd", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", "shasum": "" }, "require": { - "php": ">=7.0.0", - "psr/http-message": "^1.0" + "php": ">=5.6" }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" }, + "type": "library", "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } + "files": [ + "src/getallheaders.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -359,50 +314,52 @@ ], "authors": [ { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" } ], - "description": "Common interfaces for PSR-7 HTTP message factories", - "keywords": [ - "factory", - "http", - "message", - "psr", - "psr-17", - "psr-7", - "request", - "response" - ], - "time": "2020-09-17T16:52:55+00:00" + "description": "A polyfill for getallheaders.", + "time": "2019-03-08T08:55:37+00:00" }, { - "name": "psr/http-message", - "version": "dev-master", + "name": "symfony/polyfill-intl-idn", + "version": "dev-main", "source": { "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4" + "url": "https://github.com/symfony/polyfill-intl-idn.git", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", - "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/749045c69efb97c70d25d7463abba812e91f3a44", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=7.1", + "symfony/polyfill-intl-normalizer": "^1.10", + "symfony/polyfill-php72": "^1.10" + }, + "suggest": { + "ext-intl": "For best performance" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { "psr-4": { - "Psr\\Http\\Message\\": "src/" - } + "Symfony\\Polyfill\\Intl\\Idn\\": "" + }, + "files": [ + "bootstrap.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -410,47 +367,69 @@ ], "authors": [ { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "name": "Laurent Bassin", + "email": "laurent@bassin.info" + }, + { + "name": "Trevor Rowbotham", + "email": "trevor.rowbotham@pm.me" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", + "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", + "homepage": "https://symfony.com", "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" + "compatibility", + "idn", + "intl", + "polyfill", + "portable", + "shim" ], - "time": "2019-08-29T13:16:46+00:00" + "time": "2021-09-14T14:02:44+00:00" }, { - "name": "ralouphie/getallheaders", - "version": "3.0.3", + "name": "symfony/polyfill-intl-normalizer", + "version": "dev-main", "source": { "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8", + "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8", "shasum": "" }, "require": { - "php": ">=5.6" + "php": ">=7.1" }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" + "suggest": { + "ext-intl": "For best performance" }, "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, "files": [ - "src/getallheaders.php" + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" ] }, "notification-url": "https://packagist.org/downloads/", @@ -459,25 +438,38 @@ ], "authors": [ { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "A polyfill for getallheaders.", - "time": "2019-03-08T08:55:37+00:00" + "description": "Symfony polyfill for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "time": "2021-02-19T12:13:01+00:00" }, { - "name": "symfony/deprecation-contracts", - "version": "2.5.x-dev", + "name": "symfony/polyfill-php72", + "version": "dev-main", "source": { "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8" + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/6f981ee24cf69ee7ce9736146d1c57c2780598a8", - "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/9a142215a36a3888e30d0a9eeea9766764e96976", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976", "shasum": "" }, "require": { @@ -486,16 +478,19 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "1.23-dev" }, "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + }, "files": [ - "function.php" + "bootstrap.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -512,9 +507,15 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "A generic function and convention to trigger deprecation notices", + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", "homepage": "https://symfony.com", - "time": "2021-07-12T14:48:14+00:00" + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2021-05-27T09:17:38+00:00" } ], "packages-dev": [], From 699c3d22e270d7ee61333153b0e3a90749b79094 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Tue, 26 Oct 2021 09:07:01 +0200 Subject: [PATCH 06/16] fix: moved to curl and away from guzzle --- src/OnenceWS.php | 63 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index 0b8345a..ff4a900 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -5,6 +5,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Client; use \ErrorException; +use Exception; use Psr\Http\Message\ResponseInterface; use \stdClass; @@ -23,10 +24,11 @@ class OnenceWS extends Client { private $encodedAuthorization; private $authToken; private $tokenType; - private $expiresIn; private $header; private $apiVersion; + private $curl; + public function __construct($clientId, $clientSecret, $version = self::V1) { parent::__construct(['base_uri' => self::$baseUrl]); @@ -67,13 +69,13 @@ private function __setAuthToken() { $this->tokenType = $responseContent->token_type; $this->expiresIn = $responseContent->expires_in; $this->header = [ - 'Content-Type' => "application/json", - 'Authorization' => "$this->tokenType $this->authToken", - 'Accept' => '*/*', - 'Cache-Control' => 'no-cache', - 'Host' => 'api.1nce.com', - 'Accept-Encoding' => 'gzip, deflate', - 'Connection' => 'keep-alive', + 'Content-Type: application/json', + 'Authorization: ' . $this->tokenType . ' ' . $this->authToken, + 'Accept: */*', + 'Cache-Control: no-cache', + 'Host: api.1nce.com', + 'Accept-Encoding: gzip, deflate', + 'Connection: keep-alive', ]; } else { throw new ErrorException('Error while getting an authorization token.'); @@ -93,6 +95,31 @@ private function __prepare($url, $type, $params = []) { } + private function prepareCurlRequest($url, $type, $params) { + $this->__setAuthToken(); + + $curl = curl_init(); + + $postBody = []; + + if ($type == "POST") { + curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); + } + curl_setopt_array($curl, [ + CURLOPT_URL => self::$baseUrl . "/" . $this->apiVersion . "/" . $url, //. "?access_token=" . $this->authToken, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => $type, + CURLOPT_HTTPHEADER => $this->header, + ]); + + return $curl; + } + + /** * @return ResponseInterface|string * @throws ErrorException @@ -101,6 +128,18 @@ private function __prepare($url, $type, $params = []) { * @param array $params */ private function __standard($url, $type, $params = []) { + $curl = $this->prepareCurlRequest($url, $type, $params); + + $response = curl_exec($curl); + $err = curl_error($curl); + if ($err) { + throw new Exception($err); + } + curl_close($curl); + return $response; + } + + private function __sendGuzzle($url, $type, $params = []) { return $this->send($this->__prepare($url, $type, $params)); } @@ -111,7 +150,7 @@ private function __standard($url, $type, $params = []) { * @throws ErrorException */ private function __standardGet($url, $params = []) { - return json_decode($this->__standard($url, 'GET', $params)->getBody()->getContents()); + return json_decode($this->__standard($url, 'GET', $params)); } /** @@ -121,7 +160,7 @@ private function __standardGet($url, $params = []) { * @throws ErrorException */ private function __standardPost($url, $params = []) { - return $this->__standard($url, 'POST', $params)->getStatusCode(); + return json_decode($this->__standard($url, 'POST', $params)); } /** @@ -131,7 +170,7 @@ private function __standardPost($url, $params = []) { * @throws ErrorException */ private function __standardPut($url, $params = []) { - return $this->__standard($url, 'PUT', $params)->getStatusCode(); + return json_decode($this->__standard($url, 'PUT', $params)); } /** @@ -141,7 +180,7 @@ private function __standardPut($url, $params = []) { * @throws ErrorException */ private function __standardDelete($url, $params = []) { - return $this->__standard($url, 'DELETE', $params)->getStatusCode(); + return json_decode($this->__standard($url, 'DELETE', $params)); } From cc4ef76c5c39ab591c2ab6db8414fcb068fe5db0 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Tue, 26 Oct 2021 09:20:32 +0200 Subject: [PATCH 07/16] fix: body for put, post --- src/OnenceWS.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index ff4a900..c2ebb41 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -102,7 +102,7 @@ private function prepareCurlRequest($url, $type, $params) { $postBody = []; - if ($type == "POST") { + if ($type != "GET") { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); } curl_setopt_array($curl, [ @@ -129,13 +129,12 @@ private function prepareCurlRequest($url, $type, $params) { */ private function __standard($url, $type, $params = []) { $curl = $this->prepareCurlRequest($url, $type, $params); - $response = curl_exec($curl); $err = curl_error($curl); + curl_close($curl); if ($err) { throw new Exception($err); } - curl_close($curl); return $response; } @@ -329,7 +328,7 @@ public function resetSim($iccid) { * @throws ErrorException * @return int */ - public function changeSimState($iccid, $newStatus, $newLabel = '', $imeiLock = true) { + public function changeSimState($iccid, $newStatus = "Enabled", $newLabel = '', $imeiLock = true) { return $this->__standardPut( "sims/$iccid", [ From e614d6057e1f23c5b1b738042c8260de24ed12ec Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Wed, 27 Oct 2021 10:14:52 +0200 Subject: [PATCH 08/16] fix: imeiLock defaults to false --- src/OnenceWS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index c2ebb41..5cffab1 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -328,7 +328,7 @@ public function resetSim($iccid) { * @throws ErrorException * @return int */ - public function changeSimState($iccid, $newStatus = "Enabled", $newLabel = '', $imeiLock = true) { + public function changeSimState($iccid, $newStatus = "Enabled", $newLabel = '', $imeiLock = false) { return $this->__standardPut( "sims/$iccid", [ From b1c5c63914f8a8c042f7fcedc5f82b5fc5c75129 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Thu, 28 Oct 2021 11:54:48 +0200 Subject: [PATCH 09/16] fix: status returns status --- src/OnenceWS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index 5cffab1..aa3d896 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -252,7 +252,7 @@ public function getSimInfo($iccid) { * @return stdClass */ public function getSimStatus($iccid) { - return $this->__standardGet("sims/$iccid/status"); + return $this->__standardGet("sims/$iccid/status")->status; } /** From 631acf3757f086403ea856937836af920ca7607a Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 3 Feb 2023 13:16:07 +0100 Subject: [PATCH 10/16] feat: add missing parameter option to sim-usage --- src/OnenceWS.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index aa3d896..7f7fea7 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -206,8 +206,8 @@ public function getSimReachibility($iccid) { * @throws ErrorException * @return stdClass */ - public function getSimUsage($iccid) { - return $this->__standardGet("sims/$iccid/usage"); + public function getSimUsage($iccid, $options = []) { + return $this->__standardGet("sims/$iccid/usage", $options); } /** From 368b3f36b56f4f6dfb96895484d4cfd5f9a9ffc9 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 3 Feb 2023 13:16:36 +0100 Subject: [PATCH 11/16] chore: formatting --- src/OnenceWS.php | 96 ++++++++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 36 deletions(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index 7f7fea7..35c639f 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -4,18 +4,17 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Client; -use \ErrorException; +use ErrorException; use Exception; use Psr\Http\Message\ResponseInterface; -use \stdClass; +use stdClass; - -class OnenceWS extends Client { - - const ACTIVATED = 'Activated'; - const DISABLED = 'Disabled'; - const APN = 'iot.1nce.net'; - const V1 = 'v1'; +class OnenceWS extends Client +{ + public const ACTIVATED = 'Activated'; + public const DISABLED = 'Disabled'; + public const APN = 'iot.1nce.net'; + public const V1 = 'v1'; private static $baseUrl = 'https://api.1nce.com/management-api'; @@ -30,7 +29,8 @@ class OnenceWS extends Client { private $curl; - public function __construct($clientId, $clientSecret, $version = self::V1) { + public function __construct($clientId, $clientSecret, $version = self::V1) + { parent::__construct(['base_uri' => self::$baseUrl]); $this->clientId = $clientId; $this->clientSecret = $clientSecret; @@ -41,7 +41,8 @@ public function __construct($clientId, $clientSecret, $version = self::V1) { /** * @return Request */ - private function __getTokenRequest() { + private function __getTokenRequest() + { return new Request( 'POST', "{$this::$baseUrl}/oauth/token", @@ -57,7 +58,8 @@ private function __getTokenRequest() { * @return void setta auth token. * @throws ErrorException */ - private function __setAuthToken() { + private function __setAuthToken() + { if (!\apcu_exists("1nce_auth_token")) { $responseContent = json_decode($this->send($this->__getTokenRequest())->getBody()->getContents()); \apcu_store("1nce_auth_token", $responseContent, $responseContent->expires_in); @@ -89,13 +91,15 @@ private function __setAuthToken() { * @param string $type * @param array $params */ - private function __prepare($url, $type, $params = []) { + private function __prepare($url, $type, $params = []) + { $this->__setAuthToken(); return new Request($type, "{$this::$baseUrl}/$this->apiVersion/$url?access_token=$this->authToken", $this->header, json_encode($params)); } - private function prepareCurlRequest($url, $type, $params) { + private function prepareCurlRequest($url, $type, $params) + { $this->__setAuthToken(); $curl = curl_init(); @@ -127,7 +131,8 @@ private function prepareCurlRequest($url, $type, $params) { * @param string $type * @param array $params */ - private function __standard($url, $type, $params = []) { + private function __standard($url, $type, $params = []) + { $curl = $this->prepareCurlRequest($url, $type, $params); $response = curl_exec($curl); $err = curl_error($curl); @@ -138,7 +143,8 @@ private function __standard($url, $type, $params = []) { return $response; } - private function __sendGuzzle($url, $type, $params = []) { + private function __sendGuzzle($url, $type, $params = []) + { return $this->send($this->__prepare($url, $type, $params)); } @@ -148,7 +154,8 @@ private function __sendGuzzle($url, $type, $params = []) { * @param array $params * @throws ErrorException */ - private function __standardGet($url, $params = []) { + private function __standardGet($url, $params = []) + { return json_decode($this->__standard($url, 'GET', $params)); } @@ -158,7 +165,8 @@ private function __standardGet($url, $params = []) { * @param array $params * @throws ErrorException */ - private function __standardPost($url, $params = []) { + private function __standardPost($url, $params = []) + { return json_decode($this->__standard($url, 'POST', $params)); } @@ -168,7 +176,8 @@ private function __standardPost($url, $params = []) { * @param array $params * @throws ErrorException */ - private function __standardPut($url, $params = []) { + private function __standardPut($url, $params = []) + { return json_decode($this->__standard($url, 'PUT', $params)); } @@ -178,7 +187,8 @@ private function __standardPut($url, $params = []) { * @param array $params * @throws ErrorException */ - private function __standardDelete($url, $params = []) { + private function __standardDelete($url, $params = []) + { return json_decode($this->__standard($url, 'DELETE', $params)); } @@ -188,7 +198,8 @@ private function __standardDelete($url, $params = []) { /** * get all sims */ - public function getSimsList() { + public function getSimsList() + { return $this->__standardGet('sims'); } @@ -197,7 +208,8 @@ public function getSimsList() { * @throws ErrorException * @return stdClass */ - public function getSimReachibility($iccid) { + public function getSimReachibility($iccid) + { return $this->__standardGet("sims/$iccid/connectivity_info"); } @@ -206,7 +218,8 @@ public function getSimReachibility($iccid) { * @throws ErrorException * @return stdClass */ - public function getSimUsage($iccid, $options = []) { + public function getSimUsage($iccid, $options = []) + { return $this->__standardGet("sims/$iccid/usage", $options); } @@ -215,7 +228,8 @@ public function getSimUsage($iccid, $options = []) { * @throws ErrorException * @return stdClass */ - public function getSimRemainingData($iccid) { + public function getSimRemainingData($iccid) + { return $this->__standardGet("sims/$iccid/quota/data"); } @@ -224,7 +238,8 @@ public function getSimRemainingData($iccid) { * @throws ErrorException * @return stdClass */ - public function getSimRemainingSms($iccid) { + public function getSimRemainingSms($iccid) + { return $this->__standardGet("sims/$iccid/quota/sms"); } @@ -233,7 +248,8 @@ public function getSimRemainingSms($iccid) { * @throws ErrorException * @return stdClass */ - public function getSmsList($iccid) { + public function getSmsList($iccid) + { return $this->__standardGet("sims/$iccid/sms"); } @@ -242,7 +258,8 @@ public function getSmsList($iccid) { * @throws ErrorException * @return stdClass */ - public function getSimInfo($iccid) { + public function getSimInfo($iccid) + { return $this->__standardGet("sims/$iccid"); } @@ -251,7 +268,8 @@ public function getSimInfo($iccid) { * @throws ErrorException * @return stdClass */ - public function getSimStatus($iccid) { + public function getSimStatus($iccid) + { return $this->__standardGet("sims/$iccid/status")->status; } @@ -260,7 +278,8 @@ public function getSimStatus($iccid) { * @throws ErrorException * @return stdClass */ - public function getSimEvents($iccid) { + public function getSimEvents($iccid) + { return $this->__standardGet("sims/$iccid/events"); } @@ -270,7 +289,8 @@ public function getSimEvents($iccid) { * @throws ErrorException * @return stdClass */ - public function getSmsDetails($iccid, $idSms) { + public function getSmsDetails($iccid, $idSms) + { return $this->__standardGet("sims/$iccid/sms/$idSms"); } @@ -290,9 +310,11 @@ public function getSmsDetails($iccid, $idSms) { * @throws ErrorException * @return int */ - public function sendSms($iccid, $sms, $expiry_date = null, $source_address = 1234567890, $udh = 'string', $dcs = 8) { - if (is_null($expiry_date)) + public function sendSms($iccid, $sms, $expiry_date = null, $source_address = 1234567890, $udh = 'string', $dcs = 8) + { + if (is_null($expiry_date)) { $expiry_date = date("Y-m-d", strtotime("+7 days")); + } return $this->__standardPost( "sims/$iccid/sms", @@ -314,7 +336,8 @@ public function sendSms($iccid, $sms, $expiry_date = null, $source_address = 123 * @throws ErrorException * @return int */ - public function resetSim($iccid) { + public function resetSim($iccid) + { return $this->__standardPost("sims/$iccid/reset"); } //INFO: END POST REQUEST @@ -328,7 +351,8 @@ public function resetSim($iccid) { * @throws ErrorException * @return int */ - public function changeSimState($iccid, $newStatus = "Enabled", $newLabel = '', $imeiLock = false) { + public function changeSimState($iccid, $newStatus = "Enabled", $newLabel = '', $imeiLock = false) + { return $this->__standardPut( "sims/$iccid", [ @@ -350,10 +374,10 @@ public function changeSimState($iccid, $newStatus = "Enabled", $newLabel = '', $ * @throws ErrorException * @return int */ - public function deleteSpecificSms($iccid, $smsId) { + public function deleteSpecificSms($iccid, $smsId) + { return $this->__standardDelete("sims/$iccid/sms/$smsId"); } //INFO: END DELETE REQUEST - } From 2019a27169e603e7d06d1fabc7955210ab5e1dec Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 3 Feb 2023 13:24:48 +0100 Subject: [PATCH 12/16] chore: remove const for backwards compatibility --- src/OnenceWS.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index 35c639f..2f39f31 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -11,10 +11,10 @@ class OnenceWS extends Client { - public const ACTIVATED = 'Activated'; - public const DISABLED = 'Disabled'; - public const APN = 'iot.1nce.net'; - public const V1 = 'v1'; + public $ACTIVATED = 'Activated'; + public $DISABLED = 'Disabled'; + public $APN = 'iot.1nce.net'; + public $V1 = 'v1'; private static $baseUrl = 'https://api.1nce.com/management-api'; @@ -29,7 +29,7 @@ class OnenceWS extends Client private $curl; - public function __construct($clientId, $clientSecret, $version = self::V1) + public function __construct($clientId, $clientSecret, $version = self::$V1) { parent::__construct(['base_uri' => self::$baseUrl]); $this->clientId = $clientId; From 7631999aa4e0bce7682af6cec82c3a2cd3f75e82 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 3 Feb 2023 13:26:29 +0100 Subject: [PATCH 13/16] fix: broken --- src/OnenceWS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index 2f39f31..850a99c 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -29,7 +29,7 @@ class OnenceWS extends Client private $curl; - public function __construct($clientId, $clientSecret, $version = self::$V1) + public function __construct($clientId, $clientSecret, $version = "v1") { parent::__construct(['base_uri' => self::$baseUrl]); $this->clientId = $clientId; From 87073f7a63d849781c195bc3b69da23f9c5e544f Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 3 Feb 2023 13:59:01 +0100 Subject: [PATCH 14/16] chore: support get parameters --- src/OnenceWS.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index 850a99c..10703c3 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -109,6 +109,9 @@ private function prepareCurlRequest($url, $type, $params) if ($type != "GET") { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); } + if ($type == "GET" && array_size($params) > 0) { + $url = $url . '?' . http_build_query(params); + } curl_setopt_array($curl, [ CURLOPT_URL => self::$baseUrl . "/" . $this->apiVersion . "/" . $url, //. "?access_token=" . $this->authToken, CURLOPT_RETURNTRANSFER => true, From 07f689ef4023e0114e1427a0747bd81c9fd1d979 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 3 Feb 2023 13:59:39 +0100 Subject: [PATCH 15/16] fixup! chore: support get parameters --- src/OnenceWS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index 10703c3..7de8f2c 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -109,7 +109,7 @@ private function prepareCurlRequest($url, $type, $params) if ($type != "GET") { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); } - if ($type == "GET" && array_size($params) > 0) { + if ($type == "GET" && sizeof($params) > 0) { $url = $url . '?' . http_build_query(params); } curl_setopt_array($curl, [ From ad49902974d27bfb0d918a689f001e1ef97ed8ab Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 3 Feb 2023 14:05:41 +0100 Subject: [PATCH 16/16] fix --- src/OnenceWS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OnenceWS.php b/src/OnenceWS.php index 7de8f2c..08bb6bd 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -110,7 +110,7 @@ private function prepareCurlRequest($url, $type, $params) curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); } if ($type == "GET" && sizeof($params) > 0) { - $url = $url . '?' . http_build_query(params); + $url = $url . '?' . http_build_query($params); } curl_setopt_array($curl, [ CURLOPT_URL => self::$baseUrl . "/" . $this->apiVersion . "/" . $url, //. "?access_token=" . $this->authToken,