File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,11 +99,22 @@ public function getWebProperties(): array
9999 return $ body ['items ' ] ?? [];
100100 }
101101
102- public function getAccountProfiles (): array
102+ public function getAccountProfiles (int $ pageSize = self :: PAGE_SIZE ): array
103103 {
104- $ response = $ this ->api ->request (self ::ACCOUNT_PROFILES_URL );
105- $ body = json_decode ($ response ->getBody ()->getContents (), true );
106- return $ body ['items ' ] ?? [];
104+ $ items = [];
105+ do {
106+ $ url = sprintf ('%s?max-results=%d ' , self ::ACCOUNT_PROFILES_URL , $ pageSize );
107+ if (isset ($ body ['nextLink ' ])) {
108+ $ url = $ body ['nextLink ' ];
109+ }
110+ $ response = $ this ->api ->request ($ url );
111+ $ body = json_decode ($ response ->getBody ()->getContents (), true );
112+ if (isset ($ body ['items ' ])) {
113+ $ items [] = $ body ['items ' ];
114+ }
115+ } while (isset ($ body ['nextLink ' ]));
116+
117+ return array_merge ([], ...$ items );
107118 }
108119
109120 public function getCustomMetrics (int $ accountId , string $ webPropertyId ): array
Original file line number Diff line number Diff line change @@ -199,7 +199,7 @@ public function testGetProfilesProperties(): void
199199 ->with ($ this ->logicalOr (
200200 sprintf ('%s?pageSize=%d ' , Client::ACCOUNT_PROPERTIES_URL , Client::PAGE_SIZE ),
201201 Client::ACCOUNT_WEB_PROPERTIES_URL ,
202- Client::ACCOUNT_PROFILES_URL ,
202+ sprintf ( ' %s?max-results=%d ' , Client::ACCOUNT_PROFILES_URL , Client:: PAGE_SIZE ) ,
203203 Client::ACCOUNTS_URL
204204 ))
205205 ->will ($ this ->returnCallback (array ($ this , 'returnMockServerRequest ' )))
@@ -257,8 +257,8 @@ public function testGetEmptyProfilesProperties(): void
257257 ->method ('request ' )
258258 ->with ($ this ->logicalOr (
259259 sprintf ('%s?pageSize=%d ' , Client::ACCOUNT_PROPERTIES_URL , Client::PAGE_SIZE ),
260+ sprintf ('%s?max-results=%d ' , Client::ACCOUNT_PROFILES_URL , Client::PAGE_SIZE ),
260261 Client::ACCOUNT_WEB_PROPERTIES_URL ,
261- Client::ACCOUNT_PROFILES_URL ,
262262 Client::ACCOUNTS_URL
263263 ))
264264 ->will ($ this ->returnCallback (array ($ this , 'returnMockServerRequestEmptyResponse ' )))
You can’t perform that action at this time.
0 commit comments