Exemplo n.º 1
0
 public function send($uri, array $payload = array())
 {
     // add key to payload
     $payload['key'] = $this->apiKey;
     $request = new Request(new URL(strtr(static::API_URL, array(':action' => $uri))));
     $request->setMethod('POST');
     $request->getHeaders()->add(new ContentType('application/json charset=utf-8'));
     $request->setBody(json_encode($payload));
     $response = $this->client->send($request, new Response());
     if ($response->getCode() != 200) {
         $data = json_decode($response->getContent());
         switch ($data->name) {
             case "ValidationError":
                 throw new ValidationErrorException($data->message, $data->code);
                 break;
             case "Unknown_Webhook":
                 throw new UnknownWebhookException($data->message);
                 break;
             case "Unknown_Url":
                 throw new UnknownUrlException($data->message);
                 break;
             default:
                 throw new \RuntimeException(sprintf('%s: %s', $data->name, $data->message), $data->code);
         }
     }
     return $response->getContent();
 }
Exemplo n.º 2
0
 /**
  * @depends testSetMethod
  * @covers Versionable\Prospect\Request\Request::setMethod
  * @covers Versionable\Prospect\Request\Request::getFiles
  * @covers Versionable\Prospect\Request\Request::hasContent
  * @covers Versionable\Prospect\Request\Request::isMultipart
  * @covers Versionable\Prospect\Request\Request::getMethod
  * @covers Versionable\Prospect\Request\Request::isBodySupported
  */
 public function testBodyNotSupport()
 {
     $files = $this->getMock('Versionable\\Prospect\\File\\CollectionInterface', array('isEmpty', 'toString', 'setBoundary'));
     $files->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
     $this->object->setFiles($files);
     $this->object->setMethod('test');
     $this->object->setBody('some body');
     $this->assertFalse($this->object->isMultipart());
 }
Exemplo n.º 3
0
 public function test__toString()
 {
     $request = new Request();
     $request->setUrl(new Url('http://www.versionable.co.uk'));
     $this->object->setRequest($request);
     $this->assertEquals($this->object->toString(), (string) $this->object);
 }