-
Notifications
You must be signed in to change notification settings - Fork 1
/
QaymAPI.php
285 lines (233 loc) · 5.94 KB
/
QaymAPI.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
/**
* Qaym API Class
*
* An implementation of Qaym's public API V0.1
*
* Arabic documentation of the API can be found at:
* http://www.qaym.com/a/api_01_docs
*
* @author Ahmad Salman <[email protected]>
* @version 1.0
* @license MIT License
* @link http://github.com/ahmads/Qaym-API-Class/
*/
class QaymAPI
{
/* Constant for the base API URL */
const API_URL = 'http://api.qaym.com/0.1/';
/* Qaym's API key */
private $_APIKey;
/* Last API response received */
private $_lastResponse;
/* Last API URL called */
private $_lastURL;
/**
* Constructor function
*
* @param string $key Qaym's API Key
*/
public function __construct($key = '') {
$this->setAPIKey($key);
}
/**
* sets the API key that will be used
*
* @param string $key Qaym's API Key
*/
public function setAPIKey($key) {
$this->_APIKey = $key;
}
/**
* Returns all the available Countries
*
* @return array
*/
public function getCountries() {
$url = $this->_buildURL('countries');
return $this->_call($url);
}
/**
* Returns the information about the specified Country
*
* @param integer $countryId the ID of the country
* @return array
*/
public function getCountryInfo($countryId) {
$url = $this->_buildURL('countries', $countryId);
return $this->_call($url);
}
/**
* Returns all the available Cities in the specified Country
*
* @param integer $countryId the ID of the country
* @return array
*/
public function getCountryCities($countryId) {
$url = $this->_buildURL('countries', $countryId, 'cities');
return $this->_call($url);
}
/**
* Returns all the available Cities
*
* @return array
*/
public function getCities() {
$url = $this->_buildURL('cities');
return $this->_call($url);
}
/**
* Returns the information about the specified City
*
* @param integer $cityId the ID of the City
* @return array
*/
public function getCityInfo($cityId) {
$url = $this->_buildURL('cities', $cityId);
return $this->_call($url);
}
/**
* Returns all the available Restaurants in the specified City
*
* @param integer $cityId the ID of the City
* @return array
*/
public function getCityItems($cityId) {
$url = $this->_buildURL('cities', $cityId, 'items');
return $this->_call($url);
}
/**
* Returns the top 50 Restaurants in the specified City
*
* @param integer $cityId the ID of the City
* @return array
*/
public function getCityTopItems($cityId) {
$url = $this->_buildURL('cities', $cityId, 'items/top');
return $this->_call($url);
}
/**
* Returns the information about the specified Restaurant
*
* @param integer $itemId the ID of the Restaurant
* @return array
*/
public function getItemInfo($itemId) {
$url = $this->_buildURL('items', $itemId);
return $this->_call($url);
}
/**
* Returns all the available Branches for the specified Restaurant
*
* @param integer $itemId the ID of the Restaurant
* @return array
*/
public function getItemLocations($itemId) {
$url = $this->_buildURL('items', $itemId, 'locations');
return $this->_call($url);
}
/**
* Returns all the available Reviews for the specified Restaurant
*
* @param integer $itemId the ID of the Restaurant
* @return array
*/
public function getItemReviews($itemId) {
$url = $this->_buildURL('items', $itemId, 'reviews');
return $this->_call($url);
}
/**
* Returns all the available Images for the specified Restaurant
*
* @param integer $itemId the ID of the Restaurant
* @return array
*/
public function getItemImages($itemId) {
$url = $this->_buildURL('items', $itemId, 'images');
return $this->_call($url);
}
/**
* Returns all the available Votes for the specified Restaurant
*
* @param integer $itemId the ID of the Restaurant
* @return array
*/
public function getItemVotes($itemId) {
$url = $this->_buildURL('items', $itemId, 'votes');
return $this->_call($url);
}
/**
* Returns all the available Tags
*
* @return array
*/
public function getTags() {
$url = $this->_buildURL('tags');
return $this->_call($url);
}
/**
* Returns all the Restaurants tagged with the specified Tag
*
* @param integer $tagId the ID of the Tag
* @return array
*/
public function getTagItems($tagId) {
$url = $this->_buildURL('tags', $tagId, 'items');
return $this->_call($url);
}
/**
* Returns the last API response received
*
* @return array
*/
public function getLastResponse() {
return $this->_lastResponse;
}
/**
* Returns the last URL called
*
* @return string
*/
public function getLastURL() {
return $this->_lastURL;
}
/**
* Makes the cURL call and decodes the JSON response
*
* @param string $url the url to be called
* @return array
*/
private function _call($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$this->_lastResponse = json_decode($response, true);
return $this->_lastResponse;
}
/**
* Constructs the full URL for the API call
*
* @param string $origin countries, cities, items or tags
* @param integer $id the ID of the concerned country/city/item/tag
* @param string $request the type of request (for cities, items, votes..etc)
* @return string
*/
private function _buildURL($origin, $id = '', $request = '') {
$key = $this->_APIKey;
$url = self::API_URL;
$url .= $origin;
if ($id) {
$url .= '/' . $id;
}
if ($request) {
$url .= '/' . $request;
}
$url .= '/key=' . $key;
$this->_lastURL = $url;
return $this->_lastURL;
}
}
/* being nice is nice. */
?>