1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright (c) Ne-Lexa |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view |
9
|
|
|
* the LICENSE file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @see https://github.com/Ne-Lexa/google-play-scraper |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Nelexa\GPlay\Scraper; |
15
|
|
|
|
16
|
|
|
use Nelexa\GPlay\HttpClient\ParseHandlerInterface; |
17
|
|
|
use Nelexa\GPlay\Model\AppId; |
18
|
|
|
use Nelexa\GPlay\Scraper\Extractor\ReviewsExtractor; |
19
|
|
|
use Psr\Http\Message\RequestInterface; |
20
|
|
|
use Psr\Http\Message\ResponseInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @internal |
24
|
|
|
*/ |
25
|
|
|
class ReviewsScraper implements ParseHandlerInterface |
26
|
|
|
{ |
27
|
|
|
/** @var AppId */ |
28
|
|
|
private $requestApp; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* ReviewsScraper constructor. |
32
|
|
|
* |
33
|
|
|
* @param AppId $requestApp |
34
|
|
|
*/ |
35
|
1 |
|
public function __construct(AppId $requestApp) |
36
|
|
|
{ |
37
|
1 |
|
$this->requestApp = $requestApp; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param RequestInterface $request |
42
|
|
|
* @param ResponseInterface $response |
43
|
|
|
* @param array $options |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
1 |
|
public function __invoke(RequestInterface $request, ResponseInterface $response, array &$options = []): array |
48
|
|
|
{ |
49
|
1 |
|
$contents = substr($response->getBody()->getContents(), 5); |
50
|
1 |
|
$json = \GuzzleHttp\json_decode($contents, true); |
|
|
|
|
51
|
|
|
|
52
|
1 |
|
if (!isset($json[0][2])) { |
53
|
|
|
return [[], null]; |
54
|
|
|
} |
55
|
1 |
|
$json = \GuzzleHttp\json_decode($json[0][2], true); |
|
|
|
|
56
|
|
|
|
57
|
1 |
|
if (empty($json[0])) { |
58
|
|
|
return [[], null]; |
59
|
|
|
} |
60
|
1 |
|
$reviews = ReviewsExtractor::extractReviews($this->requestApp, $json[0]); |
61
|
1 |
|
$nextToken = $json[1][1] ?? null; |
62
|
|
|
|
63
|
1 |
|
return [$reviews, $nextToken]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.