22
33## 1. Prerequisites
44
5- * PHP 7.4 or later
5+ * PHP 8.1 or later
66
77## 2. Installation
88
@@ -17,41 +17,113 @@ composer require mrt1m/playstation-store-api
1717Create Client object using the following code:
1818
1919``` php
20+ <?php
21+ declare(strict_types=1);
22+
2023use PlaystationStoreApi\Client;
21- use PlaystationStoreApi\Enum\Region;
22- use GuzzleHttp\Client as HttpClient;
24+ use GuzzleHttp\Client as HTTPClient;
25+ use PlaystationStoreApi\Enum\CategoryEnum;
26+ use PlaystationStoreApi\Enum\RegionEnum;
27+
28+ require_once __DIR__ . '/../vendor/autoload.php';
2329
24- $clientApi = new Client(new Region(Region::UKRAINE_RUSSIAN), new HttpClient());
30+ const API_URL = 'https://web.np.playstation.com/api/graphql/v1/';
31+
32+ $client = new Client(RegionEnum::UNITED_STATES, new HTTPClient(['base_uri' => API_URL, 'timeout' => 5]));
2533```
2634
2735## 4. API Requests
2836
29- ### 4.1. Request product data
37+ ### 4.1. Request product data by id
3038
3139``` php
32- $response = $clientApi->product()->get('EP0001-CUSA12042_00-GAME000000000000');
40+ use PlaystationStoreApi\Request\RequestProductById;
41+
42+ /**
43+ * Example for https://store.playstation.com/en-us/product/UP0001-CUSA09311_00-GAME000000000000
44+ */
45+ $response = $client->get(new RequestProductById('UP0001-CUSA09311_00-GAME000000000000'));
3346```
3447
35- ### 4.2. Request catalog data
48+ ### 4.2. Request concept data by id
3649
3750``` php
38- use PlaystationStoreApi\Query\CatalogProducts;
39- use PlaystationStoreApi\Enum\Category;
40- use PlaystationStoreApi\ValueObject\Pagination;
51+ use PlaystationStoreApi\Request\RequestConceptById;
4152
42- $sha256Hash = '<insert-your-sha256Hash >';
43- $query = new CatalogProducts(new Category(Category::PS4_GAMES), $sha256Hash);
44- $query->setPagination(new Pagination(10, 0));
53+ /**
54+ Example for https://store.playstation.com/en-us/concept/10002694
55+ */
56+ $response = $client->get(new RequestConceptById('10002694'));
57+ ```
58+
59+ ### 4.3. Request catalog data
4560
46- $response = $clientApi->catalog()->products($query);
61+ ``` php
62+ use PlaystationStoreApi\Request\RequestProductList;
63+
64+ $response = $client->get(RequestProductList::createFromCategory(CategoryEnum::PS5_GAMES));
65+ ```
66+
67+ ## 5. Run examples
68+
69+ If you want run [ examples] ( ./examples ) , you need:
70+ 1 ) Docker and docker compose
71+ 2 ) Execute make command for example:
72+ ``` bash
73+ make get_add_ons_by_title_id
4774```
75+ 3 ) Get api response from [ response] ( ./response ) directory
76+
77+ ## 5. About request signing
4878
49- #### 4.2.1 Get sha256Hash
79+ For all request you need send sha256Hash. It's request signature.
5080
81+ You can get sha256Hash from browser request:
51821 ) Open the Network panel and find query to https://web.np.playstation.com/api/graphql/v1/op
52832 ) Copy the full request URL and use urldecode
53843 ) sha256Hash is in the extensions parameter, example:
5485
5586```
5687https://web.np.playstation.com/api/graphql/v1//op?operationName=categoryGridRetrieve&variables={"id":"44d8bb20-653e-431e-8ad0-c0a365f68d2f","pageArgs":{"size":24,"offset":0},"sortBy":{"name":"productReleaseDate","isAscending":false},"filterBy":[],"facetOptions":[]}&extensions={"persistedQuery":{"version":1,"sha256Hash":"9845afc0dbaab4965f6563fffc703f588c8e76792000e8610843b8d3ee9c4c09"}}
5788```
89+ If default sha256Hash will be blocked, you can replace the base value:
90+ 1 ) Get new sha256Hash value
91+ 2 ) Replace the default value in `` PlaystationStoreApi\RequestLocatorService ``
92+ ``` php
93+ use PlaystationStoreApi\RequestLocatorService;
94+ use PlaystationStoreApi\Request\RequestPSPlusTier;
95+
96+ $customRequestLocatorService = RequestLocatorService::default();
97+ $customRequestLocatorService->set(RequestPSPlusTier::class, 'new sha256Hash value')
98+ ```
99+ 3 ) Give $customRequestLocatorService to client
100+ ``` php
101+ declare(strict_types=1);
102+
103+ use PlaystationStoreApi\Client;
104+ use GuzzleHttp\Client as HTTPClient;
105+ use PlaystationStoreApi\Enum\CategoryEnum;
106+ use PlaystationStoreApi\Enum\RegionEnum;
107+
108+ const API_URL = 'https://web.np.playstation.com/api/graphql/v1/';
109+
110+ $client = new Client(
111+ RegionEnum::UNITED_STATES,
112+ new HTTPClient(['base_uri' => API_URL, 'timeout' => 5]),
113+ $customRequestLocatorService
114+ );
115+ ```
116+
117+ ## 6. Custom request
118+
119+ If you need custom request:
120+ 1 ) Create new request class then implement `` PlaystationStoreApi\Request\BaseRequest ``
121+ 2 ) Append new request class with sha256Hash to `` PlaystationStoreApi\RequestLocatorService ``
122+ 3 ) Give new RequestLocatorService to client
123+ 4 ) Execute client `` get `` method with new request
124+
125+ ## 7. Postman collection
126+
127+ You can try playstation api with [ postman] ( https://www.postman.com/ ) .
128+
129+ For import collection download [ playstation api.postman_collection.json] ( ./postman_collection/playstation%20api.postman_collection.json )
0 commit comments