Skip to content

Commit bc87127

Browse files
author
Ishmukhametov Timur
authored
Merge pull request #2 from mrt1m/rc-2.0.0
2.0.0 - 2023-04-30
2 parents b03a7a6 + 323e438 commit bc87127

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1860
-647
lines changed

.gitattributes

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
/examples/ export-ignore
2-
/docker-compose.yaml export-ignore
2+
/response/ export-ignore
3+
/postman_collection/ export-ignore
4+
/docker-compose.yaml export-ignore
5+
/Dockerfile export-ignore
6+
/.gitignore export-ignore
7+
/Makefile export-ignore

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/vendor/
2+
/composer.lock
3+
/response

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM php:8.2-zts-alpine3.17
2+
3+
RUN curl -sS https://getcomposer.org/installer | php \
4+
&& mv composer.phar /usr/local/bin/composer \
5+
&& composer clear-cache \
6+
&& composer -V
7+
8+
RUN apk add bash
9+
10+
WORKDIR /app

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.PHONY: build get_catalog_ps4 get_catalog_ps5 ps_plus_deluxe ps_plus_extra ps_plus_essential get_product_by_id get_concept_by_id get_concept_by_product_id run_example
2+
3+
build:
4+
docker compose build php\
5+
&& docker compose run --rm php composer install -n
6+
7+
get_catalog_ps4:
8+
make run_example name=get_catalog_ps4
9+
10+
get_catalog_ps5:
11+
make run_example name=get_catalog_ps5
12+
13+
ps_plus_deluxe:
14+
make run_example name=ps_plus_deluxe
15+
16+
ps_plus_extra:
17+
make run_example name=ps_plus_extra
18+
19+
ps_plus_essential:
20+
make run_example name=ps_plus_extra
21+
22+
get_product_by_id:
23+
make run_example name=get_product_by_id
24+
25+
get_concept_by_id:
26+
make run_example name=get_concept_by_id
27+
28+
get_concept_by_product_id:
29+
make run_example name=get_concept_by_product_id
30+
31+
get_pricing_data_by_concept_id:
32+
make run_example name=get_pricing_data_by_concept_id
33+
34+
get_add_ons_by_title_id:
35+
make run_example name=get_add_ons_by_title_id
36+
37+
run_example:
38+
docker compose run --rm php -f examples/${name}.php > response/${name}.json
39+
40+

README.md

Lines changed: 87 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
1717
Create Client object using the following code:
1818

1919
```php
20+
<?php
21+
declare(strict_types=1);
22+
2023
use 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:
5182
1) Open the Network panel and find query to https://web.np.playstation.com/api/graphql/v1/op
5283
2) Copy the full request URL and use urldecode
5384
3) sha256Hash is in the extensions parameter, example:
5485

5586
```
5687
https://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)

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=7.4",
14-
"myclabs/php-enum": "1.8.0",
15-
"guzzlehttp/guzzle": "7.3.0",
16-
"ext-json": "*"
13+
"ext-json": "*",
14+
"php": ">=8.1",
15+
"guzzlehttp/guzzle": "7.3.0"
1716
},
1817
"autoload": {
1918
"psr-4": {
2019
"PlaystationStoreApi\\": "src/"
2120
}
2221
}
23-
}
22+
}

docker-compose.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
version: "3.8"
22
services:
33
php:
4-
image: php:7.4.0alpha1-alpine
4+
build:
5+
context: .
56
volumes:
67
- ./:/app:z
7-
working_dir: /app
8+
working_dir: /app
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use PlaystationStoreApi\Client;
5+
use GuzzleHttp\Client as HTTPClient;
6+
use PlaystationStoreApi\Enum\RegionEnum;
7+
use PlaystationStoreApi\Request\RequestAddOnsByTitleId;
8+
9+
require_once __DIR__ . '/../vendor/autoload.php';
10+
11+
const API_URL = 'https://web.np.playstation.com/api/graphql/v1/';
12+
13+
$client = new Client(RegionEnum::UNITED_STATES, new HTTPClient(['base_uri' => API_URL, 'timeout' => 5]));
14+
15+
/**
16+
* You can find value "npTitleId" param in the product or concept response
17+
*/
18+
$result = $client->get(new RequestAddOnsByTitleId('CUSA09311_00'));
19+
20+
echo json_encode($result, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

examples/get_catalog_ps4.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<?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;
29

310
require_once __DIR__ . '/../vendor/autoload.php';
411

5-
use PlaystationStoreApi\Client;
6-
use PlaystationStoreApi\Enum\Region;
7-
use GuzzleHttp\Client as HttpClient;
8-
use PlaystationStoreApi\Query\CatalogProducts;
9-
use PlaystationStoreApi\Enum\Category;
12+
const API_URL = 'https://web.np.playstation.com/api/graphql/v1/';
1013

11-
$clientApi = new Client(new Region(Region::UKRAINE_RUSSIAN), new HttpClient());
14+
$client = new Client(RegionEnum::UNITED_STATES, new HTTPClient(['base_uri' => API_URL, 'timeout' => 5]));
1215

13-
$sha256Hash = '<insert-your-sha256Hash>';
14-
$result = $clientApi->catalog()->products(new CatalogProducts(new Category(Category::PS4_GAMES), $sha256Hash));
16+
$result = $client->get(RequestProductList::createFromCategory(CategoryEnum::PS4_GAMES));
1517

16-
var_dump($result);
18+
echo json_encode($result, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

examples/get_catalog_ps5.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<?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;
29

310
require_once __DIR__ . '/../vendor/autoload.php';
411

5-
use PlaystationStoreApi\Client;
6-
use PlaystationStoreApi\Enum\Region;
7-
use GuzzleHttp\Client as HttpClient;
8-
use PlaystationStoreApi\Query\CatalogProducts;
9-
use PlaystationStoreApi\Enum\Category;
12+
const API_URL = 'https://web.np.playstation.com/api/graphql/v1/';
1013

11-
$clientApi = new Client(new Region(Region::UKRAINE_RUSSIAN), new HttpClient());
14+
$client = new Client(RegionEnum::UNITED_STATES, new HTTPClient(['base_uri' => API_URL, 'timeout' => 5]));
1215

13-
$sha256Hash = '<insert-your-sha256Hash>';
14-
$result = $clientApi->catalog()->products(new CatalogProducts(new Category(Category::PS5_GAMES), $sha256Hash));
16+
$result = $client->get(RequestProductList::createFromCategory(CategoryEnum::PS5_GAMES));
1517

16-
var_dump($result);
18+
echo json_encode($result, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

0 commit comments

Comments
 (0)