@@ 29-78 (lines=50) @@ | ||
26 | * @param float $timestamp |
|
27 | * @return Stars |
|
28 | */ |
|
29 | public function add($file = NULL, $file_comment = NULL, $channel = NULL, $timestamp = NULL) { |
|
30 | ||
31 | // Check if the type of the variables is valid. |
|
32 | if (!is_string($file) && ($file != NULL)) { |
|
33 | throw new InvalidArgumentException("The type of the file variable is not valid."); |
|
34 | } |
|
35 | if (!is_string($file_comment) && ($file_comment != NULL)) { |
|
36 | throw new InvalidArgumentException("The type of the file_comment variable is not valid."); |
|
37 | } |
|
38 | if (!is_string($channel) && ($channel != NULL)) { |
|
39 | throw new InvalidArgumentException("The type of the channel variable is not valid."); |
|
40 | } |
|
41 | if (!is_float($timestamp) && ($timestamp != NULL)) { |
|
42 | throw new InvalidArgumentException("The type of the timestamp variable is not valid."); |
|
43 | } |
|
44 | ||
45 | // Set the arguments of the request |
|
46 | $arguments = array(); |
|
47 | ||
48 | if ($file != NULL) { |
|
49 | $arguments["file"] = $file; |
|
50 | } |
|
51 | if ($file_comment != NULL) { |
|
52 | $arguments["file_comment"] = $file_comment; |
|
53 | } |
|
54 | if ($channel != NULL) { |
|
55 | $arguments["channel"] = $channel; |
|
56 | } |
|
57 | if ($timestamp != NULL) { |
|
58 | $arguments["timestamp"] = (string)$timestamp; |
|
59 | } |
|
60 | ||
61 | $this->setUrl("stars.add", $arguments); |
|
62 | ||
63 | // Send the request |
|
64 | try { |
|
65 | $client = new \GuzzleHttp\Client(); |
|
66 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
67 | $response = json_decode( $json_response->getBody() ); |
|
68 | } |
|
69 | catch (RequestException $e) { |
|
70 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
71 | } |
|
72 | ||
73 | if($response->{'ok'} === FALSE) { |
|
74 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
75 | } |
|
76 | ||
77 | return $this; |
|
78 | } |
|
79 | ||
80 | ||
81 | ||
@@ 137-186 (lines=50) @@ | ||
134 | * @param float $timestamp |
|
135 | * @return Stars |
|
136 | */ |
|
137 | public function remove($file = NULL, $file_comment = NULL, $channel = NULL, $timestamp = NULL) { |
|
138 | ||
139 | // Check if the type of the variables is valid. |
|
140 | if (!is_string($file) && ($file != NULL)) { |
|
141 | throw new InvalidArgumentException("The type of the file variable is not valid."); |
|
142 | } |
|
143 | if (!is_string($file_comment) && ($file_comment != NULL)) { |
|
144 | throw new InvalidArgumentException("The type of the file_comment variable is not valid."); |
|
145 | } |
|
146 | if (!is_string($channel) && ($channel != NULL)) { |
|
147 | throw new InvalidArgumentException("The type of the channel variable is not valid."); |
|
148 | } |
|
149 | if (!is_float($timestamp) && ($timestamp != NULL)) { |
|
150 | throw new InvalidArgumentException("The type of the timestamp variable is not valid."); |
|
151 | } |
|
152 | ||
153 | // Set the arguments of the request |
|
154 | $arguments = array(); |
|
155 | ||
156 | if ($file != NULL) { |
|
157 | $arguments["file"] = $file; |
|
158 | } |
|
159 | if ($file_comment != NULL) { |
|
160 | $arguments["file_comment"] = $file_comment; |
|
161 | } |
|
162 | if ($channel != NULL) { |
|
163 | $arguments["channel"] = $channel; |
|
164 | } |
|
165 | if ($timestamp != NULL) { |
|
166 | $arguments["timestamp"] = (float)$timestamp; |
|
167 | } |
|
168 | ||
169 | $this->setUrl("stars.remove", $arguments); |
|
170 | ||
171 | // Send the request |
|
172 | try { |
|
173 | $client = new \GuzzleHttp\Client(); |
|
174 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
175 | $response = json_decode( $json_response->getBody() ); |
|
176 | } |
|
177 | catch (RequestException $e) { |
|
178 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
179 | } |
|
180 | ||
181 | if($response->{'ok'} === FALSE) { |
|
182 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
183 | } |
|
184 | ||
185 | return $this; |
|
186 | } |
|
187 | } |
|
188 |
@@ 78-127 (lines=50) @@ | ||
75 | * @param string $value |
|
76 | * @return string |
|
77 | */ |
|
78 | public function set($user = NULL, $profile = NULL, $name = NULL, $value = NULL) { |
|
79 | ||
80 | // Check if the type of the variables is valid. |
|
81 | if (!is_string($user) && ($user != NULL)) { |
|
82 | throw new InvalidArgumentException("The type of the user variable is not valid."); |
|
83 | } |
|
84 | if (!is_string($profile) && ($profile != NULL)) { |
|
85 | throw new InvalidArgumentException("The type of the profile variable is not valid."); |
|
86 | } |
|
87 | if (!is_string($name) && ($name != NULL)) { |
|
88 | throw new InvalidArgumentException("The type of the name variable is not valid."); |
|
89 | } |
|
90 | if (!is_string($value) && ($value != NULL)) { |
|
91 | throw new InvalidArgumentException("The type of the value variable is not valid."); |
|
92 | } |
|
93 | ||
94 | // Set the arguments of the request |
|
95 | $arguments = array(); |
|
96 | ||
97 | if ($user != NULL) { |
|
98 | $arguments["user"] = $user; |
|
99 | } |
|
100 | if ($profile != NULL) { |
|
101 | $arguments["profile"] = $profile; |
|
102 | } |
|
103 | if ($name != NULL) { |
|
104 | $arguments["name"] = $name; |
|
105 | } |
|
106 | if ($value != NULL) { |
|
107 | $arguments["value"] = $value; |
|
108 | } |
|
109 | ||
110 | $this->setUrl("users.profile.set", $arguments); |
|
111 | ||
112 | // Send the request |
|
113 | try { |
|
114 | $client = new \GuzzleHttp\Client(); |
|
115 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
116 | $response = json_decode( $json_response->getBody() ); |
|
117 | } |
|
118 | catch (RequestException $e) { |
|
119 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
120 | } |
|
121 | ||
122 | if($response->{'ok'} === FALSE) { |
|
123 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
124 | } |
|
125 | ||
126 | return $json_response->getBody(); |
|
127 | } |
|
128 | } |
|
129 |