@@ 29-77 (lines=49) @@ | ||
26 | * @param float $timestamp |
|
27 | * @return Pin |
|
28 | */ |
|
29 | public function add($channel, $file = NULL, $file_comment = NULL, $timestamp = NULL) { |
|
30 | ||
31 | // Check if the type of the variables is valid. |
|
32 | if (!is_string($channel)) { |
|
33 | throw new InvalidArgumentException("The type of the channel variable is not valid."); |
|
34 | } |
|
35 | if (($file != NULL) && !is_string($file)) { |
|
36 | throw new InvalidArgumentException("The type of the file variable is not valid."); |
|
37 | } |
|
38 | if (($file_comment != NULL) && !is_string($file_comment)) { |
|
39 | throw new InvalidArgumentException("The type of the file_comment variable is not valid."); |
|
40 | } |
|
41 | if (($timestamp != NULL) && !is_float($timestamp)) { |
|
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 | "channel" => $channel |
|
48 | ); |
|
49 | ||
50 | if ($file != NULL) { |
|
51 | $arguments["file"] = $file; |
|
52 | } |
|
53 | if ($file_comment != NULL) { |
|
54 | $arguments["file_comment"] = $file_comment; |
|
55 | } |
|
56 | if ($timestamp != NULL) { |
|
57 | $arguments["timestamp"] = (string)$timestamp; |
|
58 | } |
|
59 | ||
60 | $this->setUrl("pin.add", $arguments); |
|
61 | ||
62 | // Send the request |
|
63 | try { |
|
64 | $client = new \GuzzleHttp\Client(); |
|
65 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
66 | $response = json_decode( $json_response->getBody() ); |
|
67 | } |
|
68 | catch (RequestException $e) { |
|
69 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
70 | } |
|
71 | ||
72 | if($response->{'ok'} === FALSE) { |
|
73 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
74 | } |
|
75 | ||
76 | return $this; |
|
77 | } |
|
78 | ||
79 | ||
80 | ||
@@ 131-179 (lines=49) @@ | ||
128 | * @param float $timestamp |
|
129 | * @return Pin |
|
130 | */ |
|
131 | public function remove($channel, $file = NULL, $file_comment = NULL, $timestamp = NULL) { |
|
132 | ||
133 | // Check if the type of the variables is valid. |
|
134 | if (!is_string($channel)) { |
|
135 | throw new InvalidArgumentException("The type of the channel variable is not valid."); |
|
136 | } |
|
137 | if (($file != NULL) && !is_string($file)) { |
|
138 | throw new InvalidArgumentException("The type of the file variable is not valid."); |
|
139 | } |
|
140 | if (($file_comment != NULL) && !is_string($file_comment)) { |
|
141 | throw new InvalidArgumentException("The type of the file_comment variable is not valid."); |
|
142 | } |
|
143 | if (($timestamp != NULL) && !is_float($timestamp)) { |
|
144 | throw new InvalidArgumentException("The type of the timestamp variable is not valid."); |
|
145 | } |
|
146 | ||
147 | // Set the arguments of the request |
|
148 | $arguments = array( |
|
149 | "channel" => $channel |
|
150 | ); |
|
151 | ||
152 | if ($file != NULL) { |
|
153 | $arguments["file"] = $file; |
|
154 | } |
|
155 | if ($file_comment != NULL) { |
|
156 | $arguments["file_comment"] = $file_comment; |
|
157 | } |
|
158 | if ($timestamp != NULL) { |
|
159 | $arguments["timestamp"] = (string)$timestamp; |
|
160 | } |
|
161 | ||
162 | $this->setUrl("pin.remove", $arguments); |
|
163 | ||
164 | // Send the request |
|
165 | try { |
|
166 | $client = new \GuzzleHttp\Client(); |
|
167 | $json_response = $client->request('GET', $this->getUrl(), []); |
|
168 | $response = json_decode( $json_response->getBody() ); |
|
169 | } |
|
170 | catch (RequestException $e) { |
|
171 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
|
172 | } |
|
173 | ||
174 | if($response->{'ok'} === FALSE) { |
|
175 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
|
176 | } |
|
177 | ||
178 | return $this; |
|
179 | } |
|
180 | } |
|
181 |