@@ -41,15 +41,15 @@ public function getApiUrl($endpoint)
41
41
return $ url ;
42
42
}
43
43
44
- public function request ($ endpoint , $ method = 'GET ' , $ params = array (), $ header = array ())
44
+ public function request ($ endpoint , $ method = 'GET ' , $ params = array (), $ headers = array ())
45
45
{
46
46
$ request = array (
47
47
'url ' => $ this ->getApiUrl ($ endpoint ),
48
48
'method ' => $ method ,
49
49
'params ' => $ params ,
50
50
'clientId ' => $ this ->getClientId (),
51
51
'accessToken ' => $ this ->getAccessToken (),
52
- 'header ' => $ header
52
+ 'headers ' => $ headers
53
53
);
54
54
$ response = Eyeem_Http::request ($ request );
55
55
$ array = json_decode ($ response ['body ' ], true );
@@ -59,6 +59,14 @@ public function request($endpoint, $method = 'GET', $params = array(), $header =
59
59
return $ array ;
60
60
}
61
61
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
+
62
70
public function getRessourceObject ($ type , $ ressource = array ())
63
71
{
64
72
// Support getUser('me')
@@ -182,9 +190,20 @@ public function getToken($code, $redirect_uri = null)
182
190
183
191
// Upload
184
192
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
+
185
204
public function uploadPhoto ($ filename )
186
205
{
187
- $ params = array ('photo ' => " @ $ filename" );
206
+ $ params = array ('photo ' => $ this -> getFile ( $ filename) );
188
207
$ response = $ this ->request ('/photos/upload ' , 'POST ' , $ params );
189
208
return $ response ['filename ' ];
190
209
}
0 commit comments