コード例 #1
0
 public function testUsers()
 {
     $response = ObjectResponse::factory(new Client(), 'account', ['_embedded' => ['users' => [['user' => ['name' => 'Kees'], 'right' => ['metadata' => 'meta']], ['user' => ['name' => 'Jan'], 'right' => ['metadata' => 'meta']]]]]);
     $users = $response->get('users');
     $this->assertEquals(2, count($users));
     $jan = array_pop($users);
     $this->assertEquals('Jan', $jan->get('name'));
 }
コード例 #2
0
ファイル: Client.php プロジェクト: eresults/unity-php-api
 /**
  * Handle the response. Returns either an array or a PaginatedCollection.
  *
  * @param ResponseInterface $response
  * @return ObjectResponse|PaginatedCollection
  * @throws Exception\HttpException
  */
 protected function handleResponse(ResponseInterface $response, array $requestOptions = [])
 {
     $body = json_decode($response->getBody()->getContents(), true) ?: [];
     if (!preg_match('~[23][0-9]{2}~', $response->getStatusCode())) {
         throw new Exception\HttpException($response->getStatusCode(), $body);
     }
     if (isset($body['pages'], $body['_embedded']) && ctype_digit($body['pages'])) {
         return new PaginatedCollection($this, $body);
     }
     if (isset($requestOptions['type'])) {
         return ObjectResponse::factory($this, $requestOptions['type'], $body);
     }
     return new ObjectResponse($body, $this->getOptions());
 }
コード例 #3
0
 public function testFactory()
 {
     $this->assertInstanceOf('\\eResults\\Unity\\Api\\Response\\ObjectResponse', ObjectResponse::factory(new Client(), null));
     $this->assertInstanceOf('\\eResults\\Unity\\Api\\Response\\AccountResponse', ObjectResponse::factory(new Client(), 'account', ['_embedded' => ['users' => []]]));
     $this->assertInstanceOf('\\eResults\\Unity\\Api\\Response\\UserResponse', ObjectResponse::factory(new Client(), 'user'));
 }