public function translateRequest(\Neuron\Net\Request $request)
 {
     $headers = array();
     foreach ($request->getHeaders() as $k => $v) {
         $headers[strtoupper($k)] = $v;
     }
     return new \OAuth2\Request($request->getParameters(), $request->getPost(), array(), $request->getCookies(), array(), array(), null, $headers);
 }
Example #2
0
 private function api(Request $request, $method)
 {
     $ch = curl_init();
     $post = $request->getBody();
     $parsedUrl = $request->getUrl();
     if ($request->getParameters()) {
         if (strpos($parsedUrl, '?')) {
             $parsedUrl .= '&';
         } else {
             $parsedUrl .= '?';
         }
         $parsedUrl .= http_build_query($request->getParameters());
     }
     curl_setopt($ch, CURLOPT_URL, $parsedUrl);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     if ($request->getHeaders()) {
         $headers = $request->getHeaders();
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     }
     switch ($method) {
         case 'GET':
             break;
         case 'POST':
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
             break;
         case 'DELETE':
             throw new NotImplemented("Not implemented.");
             break;
         case 'PUT':
             curl_setopt($ch, CURLOPT_PUT, 1);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
             break;
     }
     $output = curl_exec($ch);
     // Response
     $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     $header = substr($output, 0, $header_size);
     $body = substr($output, $header_size);
     $response = Response::fromRaw($body, self::http_parse_headers($header));
     curl_close($ch);
     return $response;
 }