public function testGroup() { $request = new FaceRequest('key', 'secret', 'http://apicn.faceplusplus.com', 'POST', '/foo', []); $body = '{ "person": [ { "person_id": "98b0fe01f6f212e19a3e659e324e37ab", "tag": "", "person_name": "Alice" }, { "person_id": "9d1598f2831eadfc5817008859865cbd", "tag": "", "person_name": "Bob" } ], "group_id": "f539fa9f6e4689397c76c57f2cfb4edc", "tag": "created_by_Alice", "group_name": "Family" }'; $response = new FaceResponse($request, $body, 200, []); /** @var \FaceSDK\Node\Group $groupInfo */ $groupInfo = $response->getGroupInfo(); $this->assertInstanceOf('\\FaceSDK\\Node\\Group', $groupInfo); $personList = $groupInfo->getPersons(); $this->assertEquals('Alice', $personList[0]->getName()); }
/** * @param FaceRequest $request * * @return FaceResponse * @throws FaceAPIException */ public function sendRequest(FaceRequest $request) { list($endpoint, $method, $options) = $this->prepareRequestMessage($request); // Since file uploads can take a while, we need to give more time for uploads try { $rawResponse = $this->client->request($method, $endpoint, $options); } catch (RequestException $e) { $rawResponse = $e->getResponse(); if ($e->getPrevious() instanceof RingException || !$rawResponse instanceof ResponseInterface) { throw new FaceAPIException($e->getMessage(), $e->getCode()); } } $returnResponse = new FaceResponse($request, $rawResponse->getBody()->getContents(), $rawResponse->getStatusCode(), $rawResponse->getHeaders()); if ($returnResponse->isError()) { throw $returnResponse->getThrownException(); } return $returnResponse; }
public static function create(FaceResponse $response) { $data = $response->getDecodedBody(); $code = $data->error_code; $message = static::formatMessage($data->error); switch ($code) { case 1001: return new static($response, new FaceInternalException($message, $code)); case 1004: case 1005: return new static($response, new FaceArgumentException($message, $code)); case 1202: return new static($response, new FaceServerException($message, $code)); case 1003: return new static($response, new FaceAuthorizationException($message, $code)); } // All others return new static($response, new FaceOtherException($message, $code)); }
/** * Init this Graph object. * * @param FaceResponse $response The response entity from Graph. */ public function __construct(FaceResponse $response) { $this->response = $response; $this->decodedBody = $response->getDecodedBody(); }