File tree Expand file tree Collapse file tree 6 files changed +98
-5
lines changed
Expand file tree Collapse file tree 6 files changed +98
-5
lines changed Original file line number Diff line number Diff line change 1+ ## 2.0.1 - 2023-06-18
2+
3+ - Added new method for create next page request
4+ - Added examples
5+
6+ ## 2.0.0 - 2023-04-30
7+
8+ - Switching to a new API client
9+ - Refusal of rest-api
10+ - Added examples
11+ - Added make commands
12+
113## 0.3 - 2022-12-14
214
315- changed the logic of region and language parsing
416- fix support php7.4
5- - add docker-compose.yaml
6- - add examples
17+ - Added docker-compose.yaml
18+ - Added examples
Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ get_catalog_ps4:
1010get_catalog_ps5 :
1111 make run_example name=get_catalog_ps5
1212
13+ get_catalog_pagination_next_page :
14+ make run_example name=get_catalog_pagination_next_page
15+
16+ get_catalog_pagination_last_page :
17+ make run_example name=get_catalog_pagination_last_page
18+
1319ps_plus_deluxe :
1420 make run_example name=ps_plus_deluxe
1521
Original file line number Diff line number Diff line change @@ -61,7 +61,11 @@ $response = $client->get(new RequestConceptById('10002694'));
6161``` php
6262use PlaystationStoreApi\Request\RequestProductList;
6363
64- $response = $client->get(RequestProductList::createFromCategory(CategoryEnum::PS5_GAMES));
64+ $request = RequestProductList::createFromCategory(CategoryEnum::PS5_GAMES);
65+
66+ $firstPageResponse = $client->get($request);
67+
68+ $nextPageResponse = $client->get($request->createNextPageRequest());
6569```
6670
6771## 5. Run examples
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ use PlaystationStoreApi \Client ;
5+ use GuzzleHttp \Client as HTTPClient ;
6+ use PlaystationStoreApi \Enum \CategoryEnum ;
7+ use PlaystationStoreApi \Enum \RegionEnum ;
8+ use PlaystationStoreApi \Request \RequestProductList ;
9+ use PlaystationStoreApi \ValueObject \Pagination ;
10+
11+ require_once __DIR__ . '/../vendor/autoload.php ' ;
12+
13+ const API_URL = 'https://web.np.playstation.com/api/graphql/v1/ ' ;
14+
15+ $ client = new Client (RegionEnum::UNITED_STATES , new HTTPClient (['base_uri ' => API_URL , 'timeout ' => 5 ]));
16+
17+ $ request = RequestProductList::createFromCategory (CategoryEnum::PS5_GAMES );
18+ $ firstPageResult = $ client ->get ($ request );
19+
20+ $ totalCount = $ firstPageResult ['data ' ]['categoryGridRetrieve ' ]['pageInfo ' ]['totalCount ' ];
21+ $ size = $ firstPageResult ['data ' ]['categoryGridRetrieve ' ]['pageInfo ' ]['size ' ];
22+
23+ $ request ->pageArgs = new Pagination ($ size , (int )(floor ($ totalCount / $ size ) * $ size ));
24+
25+ $ lastPageResult = $ client ->get ($ request );
26+
27+ echo json_encode (
28+ [
29+ 'first page result ' => $ firstPageResult ,
30+ 'last page result ' => $ lastPageResult ,
31+ ],
32+ JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
33+ );
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ use PlaystationStoreApi \Client ;
5+ use GuzzleHttp \Client as HTTPClient ;
6+ use PlaystationStoreApi \Enum \CategoryEnum ;
7+ use PlaystationStoreApi \Enum \RegionEnum ;
8+ use PlaystationStoreApi \Request \RequestProductList ;
9+
10+ require_once __DIR__ . '/../vendor/autoload.php ' ;
11+
12+ const API_URL = 'https://web.np.playstation.com/api/graphql/v1/ ' ;
13+
14+ $ client = new Client (RegionEnum::UNITED_STATES , new HTTPClient (['base_uri ' => API_URL , 'timeout ' => 5 ]));
15+
16+ $ request = RequestProductList::createFromCategory (CategoryEnum::FREE_GAMES );
17+
18+ $ result = [];
19+
20+ do {
21+
22+ $ currentPageNumber = $ request ->pageArgs ->offset ? $ request ->pageArgs ->offset / $ request ->pageArgs ->size : 1 ;
23+ $ result ['Result for page number - ' . $ currentPageNumber ] = $ currentPageResult = $ client ->get ($ request );
24+ $ totalCount = $ currentPageResult ['data ' ]['categoryGridRetrieve ' ]['pageInfo ' ]['totalCount ' ];
25+
26+ } while (($ request = $ request ->createNextPageRequest ()) && $ request ->pageArgs ->offset < $ totalCount );
27+
28+ echo json_encode ($ result , JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE );
Original file line number Diff line number Diff line change @@ -23,11 +23,21 @@ public static function createFromCategory(CategoryEnum $categoryEnum): RequestPr
2323 );
2424 }
2525
26-
2726 public function __construct (
2827 public readonly string $ id ,
29- public readonly Pagination $ pageArgs ,
28+ public Pagination $ pageArgs ,
3029 public readonly Sorting $ sortBy
3130 ) {
3231 }
32+
33+ public function createNextPageRequest (): RequestProductList
34+ {
35+ $ nextPageRequest = clone $ this ;
36+ $ nextPageRequest ->pageArgs = new Pagination (
37+ $ this ->pageArgs ->size ,
38+ $ this ->pageArgs ->offset + $ this ->pageArgs ->size
39+ );
40+
41+ return $ nextPageRequest ;
42+ }
3343}
You can’t perform that action at this time.
0 commit comments