@@ -25,7 +25,7 @@ public function connect($config)
2525 $ missingKeys = array_diff (self ::$ requiredConfig , $ configKeys );
2626 if (!empty ($ missingKeys ))
2727 {
28- throw new InvalidArgumentException ("Missing required config keys: " . implode (", " , $ missingKeys ));
28+ throw new \ InvalidArgumentException ("Missing required config keys: " . implode (", " , $ missingKeys ));
2929 }
3030 $ this ->baseURL = $ config ["baseURL " ];
3131
@@ -45,7 +45,7 @@ public function connect($config)
4545 return $ this ->readPlatform ();
4646 }
4747
48- public function request ($ method , $ uri , $ params = array (), $ data = array ())
48+ public function request ($ method , $ uri , $ params = array (), $ data = array (), $ useJson = true )
4949 {
5050 // Refresh token if expired
5151 if ($ this ->token ->hasExpired ())
@@ -80,14 +80,26 @@ public function request($method, $uri, $params = array(), $data = array())
8080 }
8181 else
8282 {
83- $ request = $ this ->provider ->getAuthenticatedRequest ($ method , $ url , $ this ->token , [
84- "body " => json_encode ((object )$ data )
85- ]);
83+ $ payload = $ data ;
84+ if ($ useJson )
85+ {
86+ $ payload = array (
87+ "body " => json_encode ((object )$ data )
88+ );
89+ }
90+
91+ $ request = $ this ->provider ->getAuthenticatedRequest ($ method , $ url , $ this ->token , $ payload );
8692 }
8793
8894 $ response = $ this ->provider ->getResponse ($ request );
8995
90- return json_decode ($ response ->getBody (), true );
96+ $ result = $ response ->getBody ();
97+ if ($ useJson )
98+ {
99+ $ result = json_decode ($ result , true );
100+ }
101+
102+ return $ result ;
91103 }
92104
93105 public function get ($ uri , $ params = array ())
@@ -109,6 +121,24 @@ public function delete($uri, $params = array())
109121 {
110122 return $ this ->request ("DELETE " , $ uri , $ params );
111123 }
124+
125+ public function download ($ uri , $ params = array ())
126+ {
127+ $ response = $ this ->request ("GET " , $ uri , $ params , null , false );
128+ return $ response ->getContents ();
129+ }
130+
131+ public function upload ($ uri , $ name , $ file , $ mimetype , $ params = array ())
132+ {
133+ $ data = array (
134+ "body " => $ file ,
135+ "headers " => ["Content-Type " => $ mimetype ]
136+ );
137+
138+ $ params ["filename " ] = $ name ;
139+
140+ return $ this ->request ("POST " , $ uri , $ params , $ data , false );
141+ }
112142
113143 public function readPlatform ()
114144 {
0 commit comments