-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCryptolens.php
More file actions
249 lines (204 loc) · 8.32 KB
/
Cryptolens.php
File metadata and controls
249 lines (204 loc) · 8.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/**
* Cryptolens_PHP_Client
*
* Namespace for all classes implementing API endpoints
*/
namespace Cryptolens_PHP_Client {
use Cryptolens_PHP_Client\Analytics;
use Cryptolens_PHP_Client\Auth;
use Cryptolens_PHP_Client\Customer;
use Cryptolens_PHP_Client\Data;
use Cryptolens_PHP_Client\Endpoints;
use Cryptolens_PHP_Client\Key;
use Cryptolens_PHP_Client\License;
use Cryptolens_PHP_Client\Message;
use Cryptolens_PHP_Client\PaymentForm;
use Cryptolens_PHP_Client\Reseller;
use Cryptolens_PHP_Client\Results;
use Cryptolens_PHP_Client\Subscription;
use Cryptolens_PHP_Client\User;
/**
* Cryptolens main class
* This is the cryptolens main class containing an auto loader. It is also holding the sensitive login information needed for the API.
* You can define the output to either JSON or Arrays (PHP)
*
* @author Bryan Böhnke-Avan <bryan@openducks.org>
* @license MIT
* @since v0.1
* @link https://app.cryptolens.io/docs/api/v3
*/
class Cryptolens {
public const CRYPTOLENS_OUTPUT_PHP = 1;
public const CRYPTOLENS_OUTPUT_JSON = 2;
public const CRYPTOLENS_KEY = "Key";
public const CRYPTOLENS_AUTH = "Auth";
public const CRYPTOLENS_PRODUCT = "Product";
public const CRYPTOLENS_PAYMENTFORM = "PaymentForm";
public const CRYPTOLENS_MESSAGE = "Message";
public const CRYPTOLENS_RESELLER = "Reseller";
public const CRYPTOLENS_SUBSCRIPTION = "Subscription";
public const CRYPTOLENS_CUSTOMER = "Customer";
public const CRYPTOLENS_ANALYTICS = "Analytics";
public const CRYPTOLENS_LICENSE = "License";
public const CRYPTOLENS_DATA = "Data";
public const CRYPTOLENS_USER = "User";
private string $token;
private int $productId;
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;
/**
* `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 setProductId($product_id){
$this->productId = $product_id;
}
/**
* If $output equals CRYPTOLENS_OUTPUT_PHP you recieve arrays, if it's on CRYPTOLENS_OUTPUT_JSON you recieve json
*/
public function __construct($token, $productid, $output = self::CRYPTOLENS_OUTPUT_PHP){
self::$output = $output;
$this->setToken($token);
$this->setProductId($productid);
}
/**
* `getToken()` - Getter for API token
* @return string Returns the API Authentication token
*/
public function getToken(){
return $this->token;
}
/**
* `getProductId()` - Getter for product ID
* @return int Returns the product ID
*/
public function getProductId(){
return $this->productId;
}
/**
* `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";
require_once dirname(__FILE__) . "/classes/Key.cryptolens.php";
require_once dirname(__FILE__) . "/classes/Endpoints.cryptolens.php";
require_once dirname(__FILE__) . "/classes/Results.endpoints.cryptolens.php";
require_once dirname(__FILE__) . "/classes/Auth.cryptolens.php";
require_once dirname(__FILE__) . "/classes/Product.cryptolens.php";
require_once dirname(__FILE__) . "/classes/PaymentForm.cryptolens.php";
require_once dirname(__FILE__) . "/classes/Data.cryptolens.php";
require_once dirname(__FILE__) . "/classes/Message.cryptolens.php";
require_once dirname(__FILE__) . "/classes/Reseller.cryptolens.php";
require_once dirname(__FILE__) . "/classes/Subscription.cryptolens.php";
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";
}
/**
* `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){
return [
"error" => "An error occurred!",
"message" => $data["message"]
];
}
return (array) $data;
} elseif(self::$output == self::CRYPTOLENS_OUTPUT_JSON){
if($error == 1){
return [
"error" => "An error occurred!",
"message" => $data["message"]
];
}
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;
}
}
}