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/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 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..08bb6bd 100644 --- a/src/OnenceWS.php +++ b/src/OnenceWS.php @@ -4,32 +4,32 @@ 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'; + public $ACTIVATED = 'Activated'; + public $DISABLED = 'Disabled'; + public $APN = 'iot.1nce.net'; + public $V1 = 'v1'; private static $baseUrl = 'https://api.1nce.com/management-api'; private $clientId; private $clientSecret; - private $encodedAuthorization ; + private $encodedAuthorization; private $authToken; private $tokenType; - private $expiresIn; private $header; private $apiVersion; + 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; @@ -41,8 +41,11 @@ 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,23 +58,29 @@ 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; $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('Errore durante il decoding del access token'); + } else { + throw new ErrorException('Error while getting an authorization token.'); } } @@ -82,9 +91,39 @@ 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) + { $this->__setAuthToken(); - return new Request($type,"{$this::$baseUrl}/$this->apiVersion/$url?access_token=$this->authToken", $this->header, json_encode($params)); + + $curl = curl_init(); + + $postBody = []; + + if ($type != "GET") { + curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); + } + if ($type == "GET" && sizeof($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, + 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; } @@ -95,8 +134,21 @@ 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 = []) + { + $curl = $this->prepareCurlRequest($url, $type, $params); + $response = curl_exec($curl); + $err = curl_error($curl); + curl_close($curl); + if ($err) { + throw new Exception($err); + } + return $response; + } + + private function __sendGuzzle($url, $type, $params = []) + { + return $this->send($this->__prepare($url, $type, $params)); } /** @@ -105,8 +157,9 @@ 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)); } /** @@ -115,8 +168,9 @@ 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 json_decode($this->__standard($url, 'POST', $params)); } /** @@ -125,8 +179,9 @@ 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 json_decode($this->__standard($url, 'PUT', $params)); } /** @@ -135,8 +190,9 @@ 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 json_decode($this->__standard($url, 'DELETE', $params)); } @@ -145,7 +201,8 @@ private function __standardDelete($url,$params = []){ /** * get all sims */ - public function getSimsList(){ + public function getSimsList() + { return $this->__standardGet('sims'); } @@ -154,7 +211,8 @@ public function getSimsList(){ * @throws ErrorException * @return stdClass */ - public function getSimReachibility($iccid){ + public function getSimReachibility($iccid) + { return $this->__standardGet("sims/$iccid/connectivity_info"); } @@ -163,9 +221,9 @@ public function getSimReachibility($iccid){ * @throws ErrorException * @return stdClass */ - public function getSimUsage($iccid) + public function getSimUsage($iccid, $options = []) { - return $this->__standardGet("sims/$iccid/usage"); + return $this->__standardGet("sims/$iccid/usage", $options); } /** @@ -215,7 +273,7 @@ public function getSimInfo($iccid) */ public function getSimStatus($iccid) { - return $this->__standardGet("sims/$iccid/status"); + return $this->__standardGet("sims/$iccid/status")->status; } /** @@ -234,7 +292,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,9 +313,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", @@ -269,7 +329,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 +339,8 @@ 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 +354,11 @@ public function resetSim($iccid){ * @throws ErrorException * @return int */ - public function changeSimState($iccid,$newStatus ,$newLabel = '' ,$imeiLock = true){ + public function changeSimState($iccid, $newStatus = "Enabled", $newLabel = '', $imeiLock = false) + { return $this->__standardPut( - "sims/$iccid",[ + "sims/$iccid", + [ "iccid" => $iccid, "label" => $newLabel, "imei_lock" => $imeiLock, @@ -314,12 +377,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 - } -