Пример #1
0
 public function testPutRequest()
 {
     $request = Spore_Request::put("https://httpbin.org/put", ["json" => ["name" => "Pepe"]]);
     $response = $request->send();
     $json = $response->json();
     $this->assertSame($json["json"], ["name" => "Pepe"]);
 }
Пример #2
0
 protected function exec(array $call, array $arguments)
 {
     $method = strtolower($call["method"] ?? "GET");
     $url = $this->getRequestUrl($call, $arguments);
     $arguments = $this->getRequestParams($arguments);
     switch ($method) {
         case "get":
             $response = Spore_Request::get($url, $arguments)->send();
             break;
         case "post":
             $response = Spore_Request::post($url, $arguments)->send();
             break;
         case "put":
             $response = Spore_Request::put($url, $arguments)->send();
             break;
         default:
             throw new Spore_Exception('Invalid method: ' . $method, 1);
     }
     if (isset($call["model"])) {
         return (new Spore_Model($call["model"]))->hydrateFrom($response->json());
     }
     return $response->object();
 }