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(); }
public function testGetHeaders() { $headers = $this->getMock('Versionable\\Prospect\\Header\\CollectionInterface'); $this->object->setHeaders($headers); $this->assertEquals($this->object->getHeaders(), $this->readAttribute($this->object, 'headers')); }