Exemplo n.º 1
0
 /**
  * Makes a call to the API.
  *
  * This method will make the actial API call by the given arguments. It
  * will return the response on success (200) or will throw an exception
  * on failure.
  *
  * @param string $method The HTTP method to use (e.g. Http::GET, Http::POST, etc.).
  * @param string $resourcePath The path to the resource (e.g. contacts/john@example.com/)
  * @param string $payload The data that is sent to the service. Not used for GET or DELETE.
  * @return \Httpful\Response The response object from the service.
  * @throws \Gan\ApiException
  */
 public function call($method, $resourcePath, $payload = null)
 {
     $uri = $this->baseUri . $resourcePath;
     Request::ini($this->requestTemplate);
     $request = Request::init($method)->uri($uri);
     if ($payload) {
         $request->body($payload);
     }
     try {
         $response = $request->send();
     } finally {
         Request::resetIni();
     }
     if (floor($response->code / 100) != 2) {
         throw new ApiException($response);
     }
     return $response;
 }
Exemplo n.º 2
0
 function testIni()
 {
     // Test setting defaults/templates
     // Create the template
     $template = Request::init()->method(Http::POST)->withStrictSsl()->expectsType(Mime::HTML)->sendsType(Mime::FORM);
     Request::ini($template);
     $r = Request::init();
     $this->assertTrue($r->strict_ssl);
     $this->assertEquals(Http::POST, $r->method);
     $this->assertEquals(Mime::HTML, $r->expected_type);
     $this->assertEquals(Mime::FORM, $r->content_type);
     // Test the default accessor as well
     $this->assertTrue(Request::d('strict_ssl'));
     $this->assertEquals(Http::POST, Request::d('method'));
     $this->assertEquals(Mime::HTML, Request::d('expected_type'));
     $this->assertEquals(Mime::FORM, Request::d('content_type'));
     Request::resetIni();
 }