| @@ 131-177 (lines=47) @@ | ||
| 128 | * @return array|Segment |
|
| 129 | * @throws ClientException |
|
| 130 | */ |
|
| 131 | public function getUserList($id = null) |
|
| 132 | { |
|
| 133 | $compiledUrl = self::BASE_URL_USER; |
|
| 134 | ||
| 135 | $requestBody = $this->twigCompiler->getTwig()->render( |
|
| 136 | self::API_VERSION . '/' . self::GET_USER_LIST_TPL, |
|
| 137 | [ |
|
| 138 | 'clientCustomerId' => $this->clientCustomerId, |
|
| 139 | 'id' => $id |
|
| 140 | ] |
|
| 141 | ); |
|
| 142 | ||
| 143 | try { |
|
| 144 | $response = $this->client->request('POST', $compiledUrl, ['body' => $requestBody]); |
|
| 145 | } catch (RequestException $e) { |
|
| 146 | $response = $e->getResponse(); |
|
| 147 | } |
|
| 148 | ||
| 149 | ||
| 150 | $repositoryResponse = ApiResponse::fromResponse($response); |
|
| 151 | ||
| 152 | if (!$repositoryResponse->isSuccessful()) { |
|
| 153 | throw ClientException::failed($repositoryResponse); |
|
| 154 | } |
|
| 155 | ||
| 156 | if (!isset($repositoryResponse->getResponseArray()['body']['envelope']['body']['getresponse']['rval']['entries']) |
|
| 157 | ) { |
|
| 158 | throw ClientException::failed($repositoryResponse); |
|
| 159 | } |
|
| 160 | ||
| 161 | ||
| 162 | $entries = $repositoryResponse->getResponseArray()['body']['envelope']['body']['getresponse']['rval']['entries']; |
|
| 163 | ||
| 164 | if (is_array($entries) && isset($entries['id'])) { |
|
| 165 | //ok, this is the case when you search a specific user list. So we don't have an array of array in response but just a single array |
|
| 166 | ||
| 167 | return Segment::fromArray($entries); |
|
| 168 | } |
|
| 169 | ||
| 170 | $segments = []; |
|
| 171 | ||
| 172 | foreach ($entries as $entry) { |
|
| 173 | $segments[] = Segment::fromArray($entry); |
|
| 174 | } |
|
| 175 | ||
| 176 | return $segments; |
|
| 177 | } |
|
| 178 | } |
|
| 179 | ||
| @@ 118-162 (lines=45) @@ | ||
| 115 | * @return UserListClient[]|UserListClient |
|
| 116 | * @throws ClientException |
|
| 117 | */ |
|
| 118 | public function getUserClientList($id = null) |
|
| 119 | { |
|
| 120 | $compiledUrl = self::URL_LIST_CLIENT; |
|
| 121 | ||
| 122 | $requestBody = $this->twigCompiler->getTwig()->render( |
|
| 123 | self::API_VERSION . '/' . self::GET_USER_CLIENT_LIST_TPL, |
|
| 124 | [ |
|
| 125 | 'clientCustomerId' => $this->clientCustomerId, |
|
| 126 | 'userlistid' => $id |
|
| 127 | ] |
|
| 128 | ); |
|
| 129 | ||
| 130 | try { |
|
| 131 | $response = $this->client->request('POST', $compiledUrl, ['body' => $requestBody]); |
|
| 132 | } catch (RequestException $e) { |
|
| 133 | $response = $e->getResponse(); |
|
| 134 | } |
|
| 135 | ||
| 136 | ||
| 137 | $repositoryResponse = ApiResponse::fromResponse($response); |
|
| 138 | ||
| 139 | if (!$repositoryResponse->isSuccessful()) { |
|
| 140 | throw ClientException::failed($repositoryResponse); |
|
| 141 | } |
|
| 142 | ||
| 143 | if (!isset($repositoryResponse->getResponseArray()['body']['envelope']['body']['getresponse']['rval']['entries']) |
|
| 144 | ) { |
|
| 145 | throw ClientException::failed($repositoryResponse); |
|
| 146 | } |
|
| 147 | ||
| 148 | ||
| 149 | $entries = $repositoryResponse->getResponseArray()['body']['envelope']['body']['getresponse']['rval']['entries']; |
|
| 150 | ||
| 151 | if (is_array($entries) && isset($entries['id'])) { |
|
| 152 | return UserListClient::fromArray($entries); |
|
| 153 | } |
|
| 154 | ||
| 155 | $licenses = []; |
|
| 156 | ||
| 157 | foreach ($entries as $entry) { |
|
| 158 | $licenses[] = UserListClient::fromArray($entry); |
|
| 159 | } |
|
| 160 | ||
| 161 | return $licenses; |
|
| 162 | } |
|
| 163 | } |
|
| 164 | ||