@@ -41,15 +41,15 @@ public function getApiUrl($endpoint)
4141 return $ url ;
4242 }
4343
44- public function request ($ endpoint , $ method = 'GET ' , $ params = array (), $ header = array ())
44+ public function request ($ endpoint , $ method = 'GET ' , $ params = array (), $ headers = array ())
4545 {
4646 $ request = array (
4747 'url ' => $ this ->getApiUrl ($ endpoint ),
4848 'method ' => $ method ,
4949 'params ' => $ params ,
5050 'clientId ' => $ this ->getClientId (),
5151 'accessToken ' => $ this ->getAccessToken (),
52- 'header ' => $ header
52+ 'headers ' => $ headers
5353 );
5454 $ response = Eyeem_Http::request ($ request );
5555 $ array = json_decode ($ response ['body ' ], true );
@@ -59,6 +59,14 @@ public function request($endpoint, $method = 'GET', $params = array(), $header =
5959 return $ array ;
6060 }
6161
62+ public function jsonRequest ($ endpoint , $ method = 'GET ' , $ params = array (), $ headers = array ())
63+ {
64+ $ headers [] = 'Content-Type: application/json ' ;
65+ $ params = json_encode ($ params );
66+ $ response = $ this ->request ($ endpoint , $ method , $ params , $ headers );
67+ return $ response ;
68+ }
69+
6270 public function getRessourceObject ($ type , $ ressource = array ())
6371 {
6472 // Support getUser('me')
@@ -182,9 +190,20 @@ public function getToken($code, $redirect_uri = null)
182190
183191 // Upload
184192
193+ public function getFile ($ filename )
194+ {
195+ // PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
196+ // See: https://wiki.php.net/rfc/curl-file-upload
197+ if (function_exists ('curl_file_create ' )) {
198+ return curl_file_create ($ filename );
199+ }
200+ // Use the old style if using an older version of PHP
201+ return "@ {$ filename }" ;
202+ }
203+
185204 public function uploadPhoto ($ filename )
186205 {
187- $ params = array ('photo ' => " @ $ filename" );
206+ $ params = array ('photo ' => $ this -> getFile ( $ filename) );
188207 $ response = $ this ->request ('/photos/upload ' , 'POST ' , $ params );
189208 return $ response ['filename ' ];
190209 }
0 commit comments