1 | <?php |
||
18 | class SodaClient |
||
19 | { |
||
20 | /** |
||
21 | * The URL or domain of where the data set will be received from |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | private $domain; |
||
26 | |||
27 | /** |
||
28 | * The AppToken used to read private data and to allow the application to work with less throttling |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $token; |
||
33 | |||
34 | /** |
||
35 | * The user email for the account that will be adding, deleting, or modifying data |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | private $email; |
||
40 | |||
41 | /** |
||
42 | * The password for said account |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $password; |
||
47 | |||
48 | /** |
||
49 | * The OAuth 2.0 Access Token to be used with requests |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $oAuth2Token; |
||
54 | |||
55 | /** |
||
56 | * Whether or not to return the decoded JSON as an associative array. When set to false, it will return stdClass |
||
57 | * objects |
||
58 | * |
||
59 | * @var bool |
||
60 | */ |
||
61 | private $associativeArray; |
||
62 | |||
63 | /** |
||
64 | * Create a client object to connect to the Socrata API |
||
65 | * |
||
66 | * @param string $url The URL or domain of the Socrata data set |
||
67 | * @param string $token The AppToken used to access this information |
||
68 | * @param string $email Username for authentication |
||
69 | * @param string $password Password for authentication |
||
70 | * |
||
71 | * @since 0.1.0 |
||
72 | */ |
||
73 | public function __construct ($url, $token = "", $email = "", $password = "") |
||
82 | |||
83 | /** |
||
84 | * When fetching a data set, the returned data will be in an array of associative arrays. |
||
85 | * |
||
86 | * ``` |
||
87 | * Array |
||
88 | * ( |
||
89 | * [foo] => Test data |
||
90 | * [bar] => Array |
||
91 | * ( |
||
92 | * [baaz] => Testing |
||
93 | * [fooz] => Array |
||
94 | * ( |
||
95 | * [baz] => Testing again |
||
96 | * ) |
||
97 | * |
||
98 | * ) |
||
99 | * [foox] => Just test |
||
100 | * ) |
||
101 | * ``` |
||
102 | * |
||
103 | * When returned in this format, all of the children elements are array elements and are accessed as such. |
||
104 | * |
||
105 | * ```php |
||
106 | * $myVariable = $results['bar']['baz']; // Testing |
||
107 | * ``` |
||
108 | * |
||
109 | * @since 0.1.0 |
||
110 | */ |
||
111 | public function enableAssociativeArrays () |
||
115 | |||
116 | /** |
||
117 | * When fetching a data set, the returned data will be in an array of stdClass objects. When AssociativeArrays is |
||
118 | * disabled, the returned data will in the follow format: |
||
119 | * |
||
120 | * ``` |
||
121 | * stdClass Object |
||
122 | * ( |
||
123 | * [foo] => Test data |
||
124 | * [bar] => stdClass Object |
||
125 | * ( |
||
126 | * [baz] => Testing |
||
127 | * [foz] => stdClass Object |
||
128 | * ( |
||
129 | * [baz] => Testing again |
||
130 | * ) |
||
131 | * ) |
||
132 | * [fox] => Just test |
||
133 | * ) |
||
134 | * ``` |
||
135 | * |
||
136 | * When returned in this format, all of the children elements are objects and are accessed as such. |
||
137 | * |
||
138 | * ```php |
||
139 | * $myVariable = $results->bar->baz; // Testing |
||
140 | * ``` |
||
141 | * |
||
142 | * @since 0.1.0 |
||
143 | */ |
||
144 | public function disableAssociativeArrays () |
||
148 | |||
149 | /** |
||
150 | * Get whether or not the returned data should be associative arrays or as stdClass objects |
||
151 | * |
||
152 | * @since 0.1.0 |
||
153 | * |
||
154 | * @return bool True if the data is returned as associative arrays |
||
155 | */ |
||
156 | public function associativeArrayEnabled () |
||
160 | |||
161 | /** |
||
162 | * Get the domain of the API endpoint. This function will **always** return just the domain without the protocol |
||
163 | * in order to let this library use the appropriate protocol |
||
164 | * |
||
165 | * @since 0.1.0 |
||
166 | * |
||
167 | * @return string The domain of the API endpoint |
||
168 | */ |
||
169 | public function getDomain () |
||
173 | |||
174 | /** |
||
175 | * Get the email of the account that will be used for authenticated actions |
||
176 | * |
||
177 | * @since 0.1.0 |
||
178 | * |
||
179 | * @return string The user's email address. Returns an empty string if not set. |
||
180 | */ |
||
181 | public function getEmail () |
||
185 | |||
186 | /** |
||
187 | * Get the app token used by the library to bypass throttling and appear as a registered application |
||
188 | * |
||
189 | * @since 0.1.0 |
||
190 | * |
||
191 | * @return string The app token used. Returns an empty string if not set. |
||
192 | */ |
||
193 | public function getToken () |
||
197 | |||
198 | /** |
||
199 | * Get the password of the account that will be used for authenticated actions |
||
200 | * |
||
201 | * @since 0.1.0 |
||
202 | * |
||
203 | * @return string The password used. Returns an empty string if not set. |
||
204 | */ |
||
205 | public function getPassword () |
||
209 | |||
210 | /** |
||
211 | * Get the access token being used for OAuth 2.0 |
||
212 | * |
||
213 | * @return string The access token being used |
||
214 | * |
||
215 | * @since 0.1.1 |
||
216 | */ |
||
217 | public function getOAuth2Token () |
||
221 | |||
222 | /** |
||
223 | * Set the OAuth 2.0 access token |
||
224 | * |
||
225 | * @param string $token The access token to be used in queries |
||
226 | * |
||
227 | * @since 0.1.1 |
||
228 | */ |
||
229 | public function setOAuth2Token ($token) |
||
233 | } |
||
234 |