-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmortalsoft.class.php
117 lines (100 loc) · 3.28 KB
/
mortalsoft.class.php
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
<?php
/*********************************************************************
__ .__ _____ __
_____ ____________/ |______ | | ___________/ ____\/ |_
/ \ / _ \_ __ \ __\__ \ | | / ___/ _ \ __\\ __\
| Y Y ( <_> ) | \/| | / __ \| |__\___ ( <_> ) | | |
|__|_| /\____/|__| |__| (____ /____/____ >____/|__| |__|
\/ \/ \/
**********************************************************************/
class MortalSoftClient
{
private $baseUrl;
private $token;
public function __construct($baseUrl, $token)
{
$this->baseUrl = $baseUrl;
$this->token = $token;
}
/**
* List Games
*
* @param array $queryParams Query parameters to filter the list of games.
* @return array|false Returns an array of games or false on failure.
*/
public function listGames($queryParams = [])
{
$url = $this->baseUrl . '/api/' . $this->token . '/listGames';
$queryString = http_build_query($queryParams);
if (!empty($queryString)) {
$url .= '?' . $queryString;
}
return $this->sendRequest($url);
}
/**
* Get Balance
*
* @param string $identifier The unique identifier of the user.
* @return array|false Returns the user's balance or false on failure.
*/
public function getBalance($identifier)
{
$url = $this->baseUrl . '/api/' . $this->token . '/getBalance';
$data = [
'identifier' => $identifier
];
return $this->sendRequest($url, $data);
}
/**
* Change Balance
*
* @param string $identifier The unique identifier of the user.
* @param float $amount The new balance amount.
* @return array|false Returns the response status or false on failure.
*/
public function changeBalance($identifier, $amount)
{
$url = $this->baseUrl . '/api/' . $this->token . '/changeBalance';
$data = [
'identifier' => $identifier,
'amount' => $amount
];
return $this->sendRequest($url, $data);
}
/**
* Create Session
*
* @param string $identifier The unique identifier of the user.
* @return array|false Returns the JWT token for the user's session or false on failure.
*/
public function createSession($identifier)
{
$url = $this->baseUrl . '/api/' . $this->token . '/createSession';
$data = [
'identifier' => $identifier
];
return $this->sendRequest($url, $data);
}
private function sendRequest($url, $data = [])
{
$headers = [
'Authorization: Bearer ' . $this->token,
'Content-Type: application/json'
];
$options = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
];
if (!empty($data)) {
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = json_encode($data);
}
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
}
?>