diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd48d2..abab714 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## v1.2 + +* All API classes can now directly be used from the Cryptolens base class + +* Analytics class no longer extends Cryptolens base class +* removed php closing tag within classes and excess empty lines +* added documentation for internal functions +* quality improvements +* added php class headers + ## v1.1 * added support to User authentication endpoints `login`, `register`, `associate`, `dissociate`, `getUsers`, `changePassword`, `resetPasswordToken`, `removeUser` diff --git a/Cryptolens.php b/Cryptolens.php index 189dc4d..a661f4c 100644 --- a/Cryptolens.php +++ b/Cryptolens.php @@ -1,10 +1,32 @@ + * @license MIT + * @since v0.1 + * @link https://app.cryptolens.io/docs/api/v3 */ class Cryptolens { @@ -43,11 +65,30 @@ class Cryptolens { public static int $output; + private $analytics; + private $auth; + private $customer; + private $data; + private $endpoints; + private $key; + private $license; + private $message; + private $paymentForm; + private $product; + private $reseller; + private $subscription; + private $user; + - private function set_token(string $token): void{ + /** + * `setToken()` - Setter for API token + * @param string $token The API token to set + * @return void + */ + private function setToken(string $token): void{ $this->token = $token; } - private function set_product_id($product_id){ + private function setProductId($product_id){ $this->productId = $product_id; } @@ -56,23 +97,40 @@ private function set_product_id($product_id){ */ public function __construct($token, $productid, $output = self::CRYPTOLENS_OUTPUT_PHP){ self::$output = $output; - $this->set_token($token); - $this->set_product_id($productid); + $this->setToken($token); + $this->setProductId($productid); } - public function get_token(){ + /** + * `getToken()` - Getter for API token + * @return string Returns the API Authentication token + */ + public function getToken(){ return $this->token; } - public function get_product_id(){ + /** + * `getProductId()` - Getter for product ID + * @return int Returns the product ID + */ + public function getProductId(){ return $this->productId; } - public function set_output($output){ + /** + * `setOutput()` - Setter for output mode, either `Cryptolens::CRYPTOLENS_OUTPUT_PHP` (1) or `Cryptolens::CRYPTOLENS_OUTPUT_JSON` (2) + * @param mixed $output + * @return void + */ + public function setOutput($output){ $this->output = $output; } + /** + * `loader()` - Loads all required sub classes + * @return void `require_once`s the API classes + */ public static function loader(){ require_once dirname(__FILE__) . "/classes/Helper.cryptolens.php"; require_once dirname(__FILE__) . "/classes/Errors.cryptolens.php"; @@ -89,11 +147,17 @@ public static function loader(){ require_once dirname(__FILE__) . "/classes/Customer.cryptolens.php"; require_once dirname(__FILE__) . "/classes/Analytics.cryptolens.php"; require_once dirname(__FILE__) . "/classes/User.cryptolens.php"; - @require_once dirname(__FILE__) . "/classes/License.cryptolens.php"; + require_once dirname(__FILE__) . "/classes/License.cryptolens.php"; } + /** + * `outputHelper` - Returns the corresponding data type, either JSON or an PHP array + * @param mixed $data The data returned checked by `Helper::connection(...)` + * @param int $error + * @return array|bool|string + */ public static function outputHelper($data, int $error = 0){ if(self::$output == self::CRYPTOLENS_OUTPUT_PHP){ if($error == 1){ @@ -113,11 +177,73 @@ public static function outputHelper($data, int $error = 0){ } return json_encode($data); } + return (array) $data; } - } -} + public function analytics(): Analytics { + if(!$this->analytics) $this->analytics = new Analytics($this); + return $this->analytics; + } + + public function auth(): Auth { + if(!$this->auth) $this->auth = new Auth($this); + return $this->auth; + } + + public function customer(): Customer { + if(!$this->customer || $this->customer === null) $this->customer = new Customer($this); + return $this->customer; + } + public function data(): Data{ + if(!$this->data) $this->data = new Data($this); + return $this->data; + } + + public function endpoints(): Endpoints { + if(!$this->endpoints) $this->endpoints = new Endpoints; + return $this->endpoints; + } + + public function key(): Key { + if(!$this->key) $this->key = new Key($this); + return $this->key; + } + + public function license(bool $publicKeyIsXMLFormat = false, ?string $publicKeyFile = null): License { + if(!$this->license) $this->license = new License($publicKeyIsXMLFormat, $publicKeyFile); + return $this->license; + } + + public function message(?string $channel = null): Message { + if(!$this->message) $this->message = new Message($this, $channel); + return $this->message; + } + + public function paymentForm(): PaymentForm { + if(!$this->paymentForm) $this->paymentForm = new PaymentForm($this); + return $this->paymentForm; + } + + public function product(): Product { + if(!$this->product) $this->product = new Product($this); + return $this->product; + } + + public function reseller(): Reseller { + if(!$this->reseller) $this->reseller = new Reseller($this); + return $this->reseller; + } + public function subscription(): Subscription { + if(!$this->subscription) $this->subscription = new Subscription($this); + return $this->subscription; + } + + public function user(): User { + if(!$this->user) $this->user = new User($this); + return $this->user; + } -?> + } +} diff --git a/Cryptolens_old.php b/Cryptolens_old.php index c7b8c59..7944ee0 100644 --- a/Cryptolens_old.php +++ b/Cryptolens_old.php @@ -1,6 +1,18 @@ getMachineId(); print_r("Key 'activate':" . var_dump($k->activate($key, $machine_id))); + +// OR + +$c->key()->activate($key, $c->key()->getMachineId()); + ?> ``` diff --git a/classes/Analytics.cryptolens.php b/classes/Analytics.cryptolens.php index ca0293e..2911a83 100644 --- a/classes/Analytics.cryptolens.php +++ b/classes/Analytics.cryptolens.php @@ -1,7 +1,16 @@ + * @license MIT + * @since v0.9 + * @link https://app.cryptolens.io/docs/api/v3/AI + */ + class Analytics { private Cryptolens $cryptolens; private string $group; @@ -38,7 +47,7 @@ public function register_event(string $key, string $machineid, string $featurena "Currency" => $currency, "Metadata" => $metadata ); - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, $machineid, $additional_flags); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, $machineid, $additional_flags); $c = Helper::connection($parms, "registerEvent", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -71,7 +80,7 @@ public function register_events(string $key = null, string $machineid = null, ar "MachineCode" => $machineid, "Events" => $events ); - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, $machineid, $additional_flags); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, $machineid, $additional_flags); $c = Helper::connection($parms, "registerEvents", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -102,7 +111,7 @@ public function get_events(int $limit = 10, int $startingafter = null, int $endi if(isset($key) && !isset($product_id)){ return false; } - $parms = Helper::build_params($this->cryptolens->get_token(), $product_id ?? $this->cryptolens->get_product_id(), $key, null, array("Limit" => $limit, "StartingAfter" => $startingafter, "EndingBefore" => $endingbefore, "Time" => $time, "Metadata" => $metadata)); + $parms = Helper::build_params($this->cryptolens->getToken(), $product_id ?? $this->cryptolens->getProductId(), $key, null, array("Limit" => $limit, "StartingAfter" => $startingafter, "EndingBefore" => $endingbefore, "Time" => $time, "Metadata" => $metadata)); $c = Helper::connection($parms, "getEvents", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -128,7 +137,7 @@ public function get_object_log(int $limit = 10, int $startingafter = null){ if($limit > 100){ return false; } - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("Limit" => $limit, "StartingAfter" => $startingafter)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("Limit" => $limit, "StartingAfter" => $startingafter)); $c = Helper::connection($parms, "getObjectLog", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -163,7 +172,7 @@ public function get_web_api_log(int $product_id = null, string $key = null, $lim return false; } - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("ProductId" => $product_id, "Key" => $key, "Limit" => $limit, "StartingAfter" => $startingafter, "EndingBefore" => $endingbefore, "AnomalyClassification" => $anomalyClassification)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("ProductId" => $product_id, "Key" => $key, "Limit" => $limit, "StartingAfter" => $startingafter, "EndingBefore" => $endingbefore, "AnomalyClassification" => $anomalyClassification)); $c = Helper::connection($parms, "getWebAPILog", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -177,6 +186,3 @@ public function get_web_api_log(int $product_id = null, string $key = null, $lim } } } - - -?> \ No newline at end of file diff --git a/classes/Auth.cryptolens.php b/classes/Auth.cryptolens.php index 1ddc3fa..1c6cfbe 100644 --- a/classes/Auth.cryptolens.php +++ b/classes/Auth.cryptolens.php @@ -1,5 +1,15 @@ cryptolens->get_token(), $this->cryptolens->get_product_id(), $key); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key); $c = Helper::connection($parms, "keyLock", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -33,6 +43,3 @@ public function key_lock($key){ } } } - - -?> \ No newline at end of file diff --git a/classes/Customer.cryptolens.php b/classes/Customer.cryptolens.php index 990ec7a..18b6fb6 100644 --- a/classes/Customer.cryptolens.php +++ b/classes/Customer.cryptolens.php @@ -1,5 +1,15 @@ + * @license MIT + * @since v0.8 + * @link https://app.cryptolens.io/docs/api/v3/Customer + */ class Customer { private Cryptolens $cryptolens; @@ -26,7 +36,7 @@ public function add_customer(string $name, string $email, string $company_name, if(!isset($additional_flags)){ $additional_flags=array(); }; - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array_merge(array("Name" => $name, "Email" => $email, "CompanyName" => $company_name), $additional_flags)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array_merge(array("Name" => $name, "Email" => $email, "CompanyName" => $company_name), $additional_flags)); $c = Helper::connection($parms, "addCustomer", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -47,7 +57,7 @@ public function add_customer(string $name, string $email, string $company_name, * @return array|false Returns either "Result" key with value 0 for success or "Error" key on an error */ public function edit_customer(int $customerId, array $additional_flags){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array_merge(array("CustomerId" => $customerId), $additional_flags)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array_merge(array("CustomerId" => $customerId), $additional_flags)); $c = Helper::connection($parms, "editCustomer", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -67,7 +77,7 @@ public function edit_customer(int $customerId, array $additional_flags){ * @return array|false Either "Result" with value 0 or false */ public function remove_customer(int $customerId){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("CustomerId" => $customerId)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("CustomerId" => $customerId)); $c = Helper::connection($parms, "removeCustomer", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -89,7 +99,7 @@ public function remove_customer(int $customerId){ * @return array|false Either an array containing the licenses or false */ public function get_customer_licenses(int $customerId, bool $detailed = false, bool $metadata = true){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("CustomerId" => $customerId, "Detailed" => $detailed, "Metdata" => $metadata)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("CustomerId" => $customerId, "Detailed" => $detailed, "Metdata" => $metadata)); $c = Helper::connection($parms, "getCustomerLicenses", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -102,7 +112,7 @@ public function get_customer_licenses(int $customerId, bool $detailed = false, b } } - /** + /** * `get_customer_licenses_by_secret()` - Allows you to retrieve all the customers licenses * * @param integer $secret The secret of the user to retrieve the licenses from @@ -111,7 +121,7 @@ public function get_customer_licenses(int $customerId, bool $detailed = false, b * @return array|false Either an array containing the licenses or false */ public function get_customer_licenses_by_secret(int $secret, bool $detailed = false, bool $metadata = true){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("Secret" => $secret, "Detailed" => $detailed, "Metdata" => $metadata)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("Secret" => $secret, "Detailed" => $detailed, "Metdata" => $metadata)); $c = Helper::connection($parms, "getCustomerLicensesBySecret", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -141,7 +151,7 @@ public function get_customers(string $search = null, int $modelversion = 1, int $additional_flags["Limit"] = $limit; } $additional_flags["ModelVersion"] = $modelversion; - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, $additional_flags); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, $additional_flags); $c = Helper::connection($parms, "getCustomers", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -155,6 +165,3 @@ public function get_customers(string $search = null, int $modelversion = 1, int } } } - - -?> \ No newline at end of file diff --git a/classes/Data.cryptolens.php b/classes/Data.cryptolens.php index 1e391f6..311c364 100644 --- a/classes/Data.cryptolens.php +++ b/classes/Data.cryptolens.php @@ -1,5 +1,15 @@ cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Name" => $name, "StringValue" => $value, "IntValue" => $int, @@ -56,7 +66,7 @@ public function addDataObject(string $name, string $value, int $int = 0, int $re * @return array|bool Array on success and false on failure */ public function listDataObjects(int $referencerType = 0, string $referencerId = "0", string $contains = "", bool $showAll = true){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "ReferencerType" => $referencerType, "ReferencerId" => $referencerId, "Contains" => $contains, @@ -84,7 +94,7 @@ public function listDataObjects(int $referencerType = 0, string $referencerId = * @return array|bool Array on success and false on failure */ public function incrementIntValue(int $id, int $value = 0, bool $enableBound = false, int $bound = 0){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Id" => $id, "IntValue" => $value, "EnableBound" => $enableBound, @@ -112,7 +122,7 @@ public function incrementIntValue(int $id, int $value = 0, bool $enableBound = f * @return array|bool Array on success and false on failure */ public function decrementIntValue(int $id, int $value = 0, bool $enableBound = false, int $bound = 0){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Id" => $id, "IntValue" => $value, "EnableBound" => $enableBound, @@ -138,7 +148,7 @@ public function decrementIntValue(int $id, int $value = 0, bool $enableBound = f * @return array|bool */ public function setStringValue(int $id, string $value = null){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Id" => $id, "StringValue" => $value ]); @@ -162,7 +172,7 @@ public function setStringValue(int $id, string $value = null){ * @return array|bool */ public function setIntValue(int $id, int $value = null){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Id" => $id, "IntValue" => $value ]); @@ -185,7 +195,7 @@ public function setIntValue(int $id, int $value = null){ * @return array|bool */ public function removeDataObject(int $id){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Id" => $id ]); $c = Helper::connection($parms, "removeDataObject", $this->group); @@ -200,7 +210,7 @@ public function removeDataObject(int $id){ } } - /** + /** * `uploadValues()` - Upload values from a Cryptolens log file to either increment or decrement a data object * @param int $id Unique ID of the data object * @param string $key Serial Key @@ -209,7 +219,7 @@ public function removeDataObject(int $id){ * @return array|bool */ public function uploadValues(int $id, string $key, string $data){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, null, [ "Id" => $id, "Data" => $data ]); @@ -226,6 +236,3 @@ public function uploadValues(int $id, string $key, string $data){ } } } - - -?> \ No newline at end of file diff --git a/classes/Endpoints.cryptolens.php b/classes/Endpoints.cryptolens.php index d02cadf..36da341 100644 --- a/classes/Endpoints.cryptolens.php +++ b/classes/Endpoints.cryptolens.php @@ -1,6 +1,20 @@ + * @license MIT + * @since v0.1 + */ class Endpoints { + + /** + * `$endpoints` Variable containing all supported endpoints + * @var array + */ public static array $endpoints = [ # Keys "activate" => "https://api.cryptolens.io/api/key/activate", @@ -67,6 +81,11 @@ class Endpoints { "removeUser" => "https://api.cryptolens.io/api/userauth/RemoveUser" ]; + /** + * `$no_response_check` Variable containing endpoint names which should be excluded from being checked by `Helper::check_response`, + * as these endpoints return lists or generally differ from the values at `Results::$results` + * @var array + */ public static array $no_response_check = [ "createKey", "getKeys", @@ -84,6 +103,11 @@ class Endpoints { "listDataObjects" ]; + /** + * `getEndpoint()` Returns the API URL for given endpoint name + * @param mixed $function_name Name of the endpoint + * @return null|string Either the API URL or null if not found + */ public static function get_endpoint($function_name){ if(array_search($function_name, array_flip(self::$endpoints))){ return self::$endpoints[$function_name]; @@ -91,6 +115,3 @@ public static function get_endpoint($function_name){ } } } - - -?> \ No newline at end of file diff --git a/classes/Helper.cryptolens.php b/classes/Helper.cryptolens.php index 1cd7428..e398f0c 100644 --- a/classes/Helper.cryptolens.php +++ b/classes/Helper.cryptolens.php @@ -1,5 +1,14 @@ \ No newline at end of file diff --git a/classes/Key.cryptolens.php b/classes/Key.cryptolens.php index 760e7fe..feed14e 100644 --- a/classes/Key.cryptolens.php +++ b/classes/Key.cryptolens.php @@ -1,5 +1,15 @@ + * @license MIT + * @since v0.1 + * @link https://app.cryptolens.io/docs/api/v3/Key + */ class Key { private Cryptolens $cryptolens; @@ -44,7 +54,7 @@ public static function getMachineIdPlain(){ * @link https://app.cryptolens.io/docs/api/v3/activate */ public function activate(string $key, string $machineid){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, $machineid); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, $machineid); $c = $this->connection($parms, "activate"); if($c == true){ $license = json_decode(base64_decode($c["licenseKey"]), true); @@ -57,7 +67,7 @@ public function activate(string $key, string $machineid){ return false; # Key, productid, expires or activatedMachines are not set } - if($license["ProductId"] !== $this->cryptolens->get_product_id() || $license["Key"] !== $key){ + if($license["ProductId"] !== $this->cryptolens->getProductId() || $license["Key"] !== $key){ return Cryptolens::outputHelper([ "error" => "An error occured while activating key - Malformed response recieved.", "response" => $c @@ -103,7 +113,7 @@ public function activate(string $key, string $machineid){ * @link https://api.cryptolens.io/api/key/deactivate */ public function deactivate(string $key, string $machineid = null){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, $machineid); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, $machineid); $c = $this->connection($parms, "deactivate"); if($c == true){ @@ -124,7 +134,7 @@ public function deactivate(string $key, string $machineid = null){ * @link https://api.cryptolens.io/api/key/createKey */ public function create_key(array $additional_flags = null){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, $additional_flags); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, $additional_flags); $c = $this->connection($parms, "createKey"); if($c == true){ switch($c){ @@ -151,7 +161,7 @@ public function create_key(array $additional_flags = null){ * @param string [optional] Lock the new generated key to a machineId */ public function create_trial_key(string $machineId = null){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, $machineId); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, $machineId); $c = $this->connection($parms, "createTrialKey"); if($c == true){ switch($c){ @@ -179,7 +189,7 @@ public function create_trial_key(string $machineId = null){ * @return array|bool Returns an array with the response or bool on failure */ public function create_key_from_template(int $template){ - $parms = $this->build_params($this->cryptolens->get_token(), null, null, null, ["LicenseTemplateId" => $template]); + $parms = $this->build_params($this->cryptolens->getToken(), null, null, null, ["LicenseTemplateId" => $template]); $c = $this->connection($parms, "createKeyFromTemplate"); if($c == true){ if($c["result"] != 0){ @@ -203,7 +213,7 @@ public function create_key_from_template(int $template){ * @return array|bool Returns the key "response" and "licenseKey" (base64 decoded JSON array) */ public function get_key(string $key, array $additional_flags = null){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, null, $additional_flags); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, null, $additional_flags); $c = $this->connection($parms, "getKey"); if($c == true){ switch($c){ @@ -238,7 +248,7 @@ public function get_key(string $key, array $additional_flags = null){ * @note When using SKGL a new key will be generated and included inside the "message" key, otherwise it will be empty */ public function add_feature(string $key, int $feature){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, null, ["Feature" => $feature]); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, null, ["Feature" => $feature]); $c = $this->connection($parms, "addFeature"); if($c == true){ if($c["result"] == 0){ @@ -255,7 +265,7 @@ public function add_feature(string $key, int $feature){ } public function block_key(string $key){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key); $c = $this->connection($parms, "blockKey"); if($c == true){ if($c["result"] == 0){ @@ -281,7 +291,7 @@ public function block_key(string $key){ * If the SKGL algorithm is used, the "message" key contains the new key, otherwise you can use the same key. */ public function extend_license(string $key, int $days){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, null, ["NoOfDays" => $days]); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, null, ["NoOfDays" => $days]); $c = $this->connection($parms, "extendLicense"); if($c == true){ if($c["result"] == 0){ @@ -298,7 +308,7 @@ public function extend_license(string $key, int $days){ } # returns new key if skgl public function remove_feature(string $key, int $feature){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, null, ["Feature" => $feature]); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, null, ["Feature" => $feature]); $c = $this->connection($parms, "removeFeature"); if($c == true || $this->check_rm($c)){ return Cryptolens::outputHelper($c); @@ -311,7 +321,7 @@ public function remove_feature(string $key, int $feature){ } public function unblock_key(string $key){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key); $c = $this->connection($parms, "unblockKey"); if($c == true || $this->check_rm($c)){ return true; @@ -324,7 +334,7 @@ public function unblock_key(string $key){ } public function machine_lock_limit(string $key, int $machines){ - $parms = $this->build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), $key, null, ["NumberOfMachines" => $machines]); + $parms = $this->build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), $key, null, ["NumberOfMachines" => $machines]); $c = $this->connection($parms, "machineLockLimit"); if($c == true || $this->check_rm($c)){ return Cryptolens::outputHelper($c); @@ -349,7 +359,7 @@ private function build_params($token, $product_id, $key = null, $machineid = nul ); if($key != null){ $parms["Key"] = $key; - }; + } if($machineid != null){ $parms["MachineCode"] = "";# empty string to prevent error } @@ -369,7 +379,6 @@ private function build_params($token, $product_id, $key = null, $machineid = nul } $parms[$key] = $value; } - #print_r(var_dump($parms)); } else { echo "Parsed \$additional_flags not as an array!"; } @@ -378,7 +387,7 @@ private function build_params($token, $product_id, $key = null, $machineid = nul foreach($parms as $i => $x){ if (is_array($x)) { // detect array an skip - continue; // Überspringe die Kodierung für diesen Durchlauf + continue; } if($first) { $first = false; } else { $postfields .= '&';} @@ -438,5 +447,3 @@ private function check_rm($data){ } } } - -?> \ No newline at end of file diff --git a/classes/License.cryptolens.php b/classes/License.cryptolens.php index 0975c53..2b90c94 100644 --- a/classes/License.cryptolens.php +++ b/classes/License.cryptolens.php @@ -2,6 +2,16 @@ namespace Cryptolens_PHP_Client { use OpenSSLAsymmetricKey; + /** + * License + * + * Allows to validate license files offline + * + * @author Bryan Böhnke-Avan + * @license MIT + * @since v1.0 + * @requires \OpenSSLAsymetricKey + */ class License { @@ -111,6 +121,3 @@ public function readLicenseFile(string $filePath) } } } - - - diff --git a/classes/Message.cryptolens.php b/classes/Message.cryptolens.php index 904912e..a7f11d9 100644 --- a/classes/Message.cryptolens.php +++ b/classes/Message.cryptolens.php @@ -3,6 +3,9 @@ /** * Messages - Allows you to broadcast messages. * You can create messages via GUI here: https://app.cryptolens.io/Message + * @author Bryan Böhnke-Avan channel; } if($additional_flags == null){$additional_flags = array();}; - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array_merge(array("Content" => $content), $additional_flags)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array_merge(array("Content" => $content), $additional_flags)); $c = Helper::connection($parms, "createMessage", "Message"); if($c == true){ if(Helper::check_rm($c)){ @@ -64,7 +67,7 @@ public function create_message(string $content, array $additional_flags = null){ * @return array|false Returns either an array, containing the "Result" key which either is 0 for success or 1 if an error occured. Returning false on connection error. */ public function remove_message(int $message_id){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("Id" => $message_id)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("Id" => $message_id)); $c = Helper::connection($parms, "removeMessage", "Message"); if($c == true){ if(Helper::check_rm($c)){ @@ -94,7 +97,7 @@ public function get_messages(string $channel = null, int $greater_than = null){ if(isset($greater_than)){ $additional_flags["Time"] = $greater_than; } - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, $additional_flags); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, $additional_flags); $c = Helper::connection($parms, "getMessages", "Message"); if($c == true){ if(Helper::check_rm($c)){ @@ -108,6 +111,3 @@ public function get_messages(string $channel = null, int $greater_than = null){ } } } - - -?> \ No newline at end of file diff --git a/classes/PaymentForm.cryptolens.php b/classes/PaymentForm.cryptolens.php index be4c446..d04cfa0 100644 --- a/classes/PaymentForm.cryptolens.php +++ b/classes/PaymentForm.cryptolens.php @@ -1,5 +1,15 @@ + * @license MIT + * @since v0.4.3 + * @link https://app.cryptolens.io/docs/api/v3/PaymentForm + */ class PaymentForm { private Cryptolens $cryptolens; @@ -29,7 +39,7 @@ public function __construct(Cryptolens $cryptolens){ public function create_session(int $form_id, int $expires = 60, float $price = 0, string $currency = "USD", array $additional_flags = null){ if($additional_flags == null){$additional_flags = array();}; - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array_merge(array("PaymentFormId" => $form_id, "Expires" => $expires, "Prices" => $price, "Currency" => $currency), $additional_flags)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array_merge(array("PaymentFormId" => $form_id, "Expires" => $expires, "Prices" => $price, "Currency" => $currency), $additional_flags)); $c = Helper::connection($parms, "createSession", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -43,6 +53,3 @@ public function create_session(int $form_id, int $expires = 60, float $price = 0 } } } - - -?> \ No newline at end of file diff --git a/classes/Product.cryptolens.php b/classes/Product.cryptolens.php index dd247f6..ff51cde 100644 --- a/classes/Product.cryptolens.php +++ b/classes/Product.cryptolens.php @@ -1,5 +1,15 @@ + * @license MIT + * @since v0.4 + * @link https://app.cryptolens.io/docs/api/v3/Product + */ class Product { private Cryptolens $cryptolens; @@ -67,7 +77,7 @@ public function get_keys($page = 1, $additional_flags = null){ $additional_flags = array_merge(["page" => $page], $additional_flags); }; } - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, $additional_flags); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, $additional_flags); $c = Helper::connection($parms, "getKeys", $this->group); if($c == true){ @@ -80,7 +90,7 @@ public function get_keys($page = 1, $additional_flags = null){ } public function get_products(){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id()); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId()); $c = Helper::connection($parms, "getProducts", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -92,6 +102,3 @@ public function get_products(){ } } } - - -?> \ No newline at end of file diff --git a/classes/Reseller.cryptolens.php b/classes/Reseller.cryptolens.php index c4480db..234962c 100644 --- a/classes/Reseller.cryptolens.php +++ b/classes/Reseller.cryptolens.php @@ -1,5 +1,15 @@ + * @license MIT + * @since v0.6 + * @link https://app.cryptolens.io/docs/api/v3/Reseller + */ class Reseller { private Cryptolens $cryptolens; @@ -29,7 +39,7 @@ public function __construct(Cryptolens $cryptolens){ public function add_reseller(string $name, string $email, array $additional_flags = null){ if($additional_flags == null){$additional_flags = array();}; - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array_merge(array("Name" => $name, "Email" => $email), $additional_flags)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array_merge(array("Name" => $name, "Email" => $email), $additional_flags)); $c = Helper::connection($parms, "addReseller", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -53,7 +63,7 @@ public function add_reseller(string $name, string $email, array $additional_flag * @link https://api.cryptolens.io/api/reseller/EditReseller */ public function edit_reseller(int $resellerId, array $additional_flags){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array_merge(array("ResellerId" => $resellerId), $additional_flags)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array_merge(array("ResellerId" => $resellerId), $additional_flags)); $c = Helper::connection($parms, "editReseller", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -74,7 +84,7 @@ public function edit_reseller(int $resellerId, array $additional_flags){ * @link https://api.cryptolens.io/api/reseller/RemoveReseller */ public function remove_reseller(int $resellerId){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("ResellerId" => $resellerId)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("ResellerId" => $resellerId)); $c = Helper::connection($parms, "removeReseller", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -104,7 +114,7 @@ public function get_resellers(string $search = null, int $limit = null){ $additional_flags["Limit"] = $limit; } - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, $additional_flags); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, $additional_flags); $c = Helper::connection($parms, "getResellers", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -125,7 +135,7 @@ public function get_resellers(string $search = null, int $limit = null){ * @link https://api.cryptolens.io/api/reseller/GetResellers */ public function get_reseller_by_id(int $resellerId){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("ResellerId" => $resellerId)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("ResellerId" => $resellerId)); $c = Helper::connection($parms, "getResellers", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -146,7 +156,7 @@ public function get_reseller_by_id(int $resellerId){ * @link https://api.cryptolens.io/api/reseller/GetResellerCustomers */ public function get_reseller_customers(int $resellerId){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("ResellerId" => $resellerId)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("ResellerId" => $resellerId)); $c = Helper::connection($parms, "getResellerCustomers", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -160,6 +170,3 @@ public function get_reseller_customers(int $resellerId){ } } } - - -?> \ No newline at end of file diff --git a/classes/Results.endpoints.cryptolens.php b/classes/Results.endpoints.cryptolens.php index 85f80e9..57d1634 100644 --- a/classes/Results.endpoints.cryptolens.php +++ b/classes/Results.endpoints.cryptolens.php @@ -1,6 +1,19 @@ + * @license MIT + * @since v0.1 + */ class Results extends Endpoints { + /** + * `$results` An array containing each returned key for given endpoint group and name + * @var array + */ public static array $results = [ "Key" => [ "activate" => [ @@ -234,12 +247,12 @@ class Results extends Endpoints { ]; + /** + * `get_results` Returns the `Results::$results` array + * @return array + */ public static function get_results(){ return self::$results; } } } - - - -?> \ No newline at end of file diff --git a/classes/Subscription.cryptolens.php b/classes/Subscription.cryptolens.php index 031f695..9f9fbd4 100644 --- a/classes/Subscription.cryptolens.php +++ b/classes/Subscription.cryptolens.php @@ -1,5 +1,15 @@ + * @license MIT + * @since v0.7 + * @link https://app.cryptolens.io/docs/api/v3/Reseller + */ class Subscription { private Cryptolens $cryptolens; @@ -25,7 +35,7 @@ public function __construct(Cryptolens $cryptolens){ * @link https://api.cryptolens.io/api/subscription/RecordUsage */ public function record_usage(string $key, int $amount = 0){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, array("Key" => $key, "Amount" => $amount)); + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, array("Key" => $key, "Amount" => $amount)); $c = Helper::connection($parms, "recordUsage", $this->group); if($c == true){ if(Helper::check_rm($c)){ @@ -39,6 +49,3 @@ public function record_usage(string $key, int $amount = 0){ } } } - - -?> \ No newline at end of file diff --git a/classes/User.cryptolens.php b/classes/User.cryptolens.php index 9dcfc1f..7113e50 100644 --- a/classes/User.cryptolens.php +++ b/classes/User.cryptolens.php @@ -1,6 +1,15 @@ + * @license MIT + * @since v1.1 + * @link https://app.cryptolens.io/docs/api/v3/UserAuth + */ class User { public Cryptolens $cryptolens; @@ -20,7 +29,7 @@ public function __construct(Cryptolens $cryptolens){ * @return array|bool|string */ public function login(string $username, string $password){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Username" => $username, "Password" => $password ]); @@ -47,7 +56,7 @@ public function login(string $username, string $password){ * @return array|bool|string */ public function register(string $username, string $password, string $customerId = null, string $email = null){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Username" => $username, "Password" => $password, "CustomerId" => $customerId, @@ -74,7 +83,7 @@ public function register(string $username, string $password, string $customerId * @return array|bool */ public function associate(string $username, string $customerId = null){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Username" => $username, "CustomerId" => $customerId, ]); @@ -98,7 +107,7 @@ public function associate(string $username, string $customerId = null){ * @return array|bool */ public function dissociate(string $username){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Username" => $username ]); @@ -121,7 +130,7 @@ public function dissociate(string $username){ * @return array|bool */ public function getUsers(string $customerId = null){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "customerId" => $customerId, ]); @@ -148,7 +157,7 @@ public function getUsers(string $customerId = null){ * @return array|bool */ public function changePassword(string $username, string $newPassword, string $oldPassword = null, string $passwordResetToken = null, bool $adminMode = false){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Username" => $username, "OldPassword" => $oldPassword, "NewPassword" => $newPassword, @@ -175,7 +184,7 @@ public function changePassword(string $username, string $newPassword, string $ol * @return array|bool */ public function resetPasswordToken(string $username){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Username" => $username, ]); @@ -198,7 +207,7 @@ public function resetPasswordToken(string $username){ * @return array|bool */ public function removeUser(string $username){ - $parms = Helper::build_params($this->cryptolens->get_token(), $this->cryptolens->get_product_id(), null, null, [ + $parms = Helper::build_params($this->cryptolens->getToken(), $this->cryptolens->getProductId(), null, null, [ "Username" => $username, ]); @@ -214,4 +223,4 @@ public function removeUser(string $username){ } } } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index 8cfe84b..3e44b52 100644 --- a/composer.json +++ b/composer.json @@ -3,11 +3,11 @@ "description": "Manage your licenses with this Cryptolens API client", "type": "library", "license": "MIT", - "version": "1.1", + "version": "1.2", "authors": [ { - "name": "Ente", - "email": "github@openducks.org" + "name": "Bryan Böhnke-Avan", + "email": "bryan@openducks.org" }, { "name": "Cryptolens AB", diff --git a/examples/create-key-for-customer.php b/examples/create-key-for-customer.php index cf148d5..2bf86f4 100644 --- a/examples/create-key-for-customer.php +++ b/examples/create-key-for-customer.php @@ -74,4 +74,6 @@ function link_key($customer_id, $k){ ]; $data = http_build_query($data); header("Location: ?{$data}"); -} \ No newline at end of file +} + +?> \ No newline at end of file diff --git a/examples/enable-and-check-feature.php b/examples/enable-and-check-feature.php index 905c01e..7073d76 100644 --- a/examples/enable-and-check-feature.php +++ b/examples/enable-and-check-feature.php @@ -50,3 +50,5 @@ function check_pro_enabled($key, $k){ echo "Failed to check for enabled Feature 1 on key " . "EXAMPLE_KEY"; } } + +?> \ No newline at end of file