|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Ne-Lexa |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
* |
|
9
|
|
|
* @see https://github.com/Ne-Lexa/google-play-scraper |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Nelexa\GPlay\Model; |
|
13
|
|
|
|
|
14
|
|
|
use Nelexa\GPlay\GPlayApps; |
|
15
|
|
|
use Nelexa\GPlay\Util\LocaleHelper; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Contains the application ID, as well as the locale and country for which the information was or will be obtained. |
|
19
|
|
|
* |
|
20
|
|
|
* This class is the base class for {@see App} and {@see AppInfo}. |
|
21
|
|
|
* |
|
22
|
|
|
* @see App Contains basic information about the application |
|
23
|
|
|
* from the Google Play store. |
|
24
|
|
|
* @see AppInfo Contains detailed information about the |
|
25
|
|
|
* application from the Google Play store. |
|
26
|
|
|
*/ |
|
27
|
|
|
class AppId |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var string Application ID (Android package name) */ |
|
30
|
|
|
private $id; |
|
31
|
|
|
|
|
32
|
|
|
/** @var string Locale (site language) */ |
|
33
|
|
|
private $locale; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string the country of the request for information about the |
|
37
|
|
|
* application (affects the price and currency of paid applications |
|
38
|
|
|
* and possibly their availability on the Google Play store) |
|
39
|
|
|
*/ |
|
40
|
|
|
private $country; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Creates an \Nelexa\GPlay\Model\AppId object. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $id application ID (Android package name) |
|
46
|
|
|
* @param string $locale Locale (ex. en_US, en-CA or en). Default is 'en_US'. |
|
47
|
|
|
* @param string $country Country (affects prices). Default is 'us'. |
|
48
|
|
|
*/ |
|
49
|
67 |
|
public function __construct( |
|
50
|
|
|
string $id, |
|
51
|
|
|
string $locale = GPlayApps::DEFAULT_LOCALE, |
|
52
|
|
|
string $country = GPlayApps::DEFAULT_COUNTRY |
|
53
|
|
|
) { |
|
54
|
67 |
|
if (empty($id)) { |
|
55
|
3 |
|
throw new \InvalidArgumentException('Application ID cannot be empty'); |
|
56
|
|
|
} |
|
57
|
64 |
|
$this->id = $id; |
|
58
|
64 |
|
$this->locale = LocaleHelper::getNormalizeLocale($locale); |
|
59
|
64 |
|
$this->country = $country; |
|
60
|
64 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns the application ID (android package name). |
|
64
|
|
|
* |
|
65
|
|
|
* @return string application ID (android package name) |
|
66
|
|
|
*/ |
|
67
|
50 |
|
public function getId(): string |
|
68
|
|
|
{ |
|
69
|
50 |
|
return $this->id; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Returns the locale (site language) for which the information was received. |
|
74
|
|
|
* |
|
75
|
|
|
* @return string Locale (ex. en_US, en-CA or en). Default is 'en_US'. |
|
76
|
|
|
*/ |
|
77
|
18 |
|
public function getLocale(): string |
|
78
|
|
|
{ |
|
79
|
18 |
|
return $this->locale; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Returns the country of the request for information about the application. |
|
84
|
|
|
* |
|
85
|
|
|
* This parameter affects the price and currency of paid applications |
|
86
|
|
|
* and, possibly, the presence of an application in the Google Play store). |
|
87
|
|
|
* |
|
88
|
|
|
* @return string Country (affects prices). Default is 'us'. |
|
89
|
|
|
*/ |
|
90
|
17 |
|
public function getCountry(): string |
|
91
|
|
|
{ |
|
92
|
17 |
|
return $this->country; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns the URL of the application page in the Google Play store. |
|
97
|
|
|
* |
|
98
|
|
|
* @return string url of the app page in Google Play |
|
99
|
|
|
*/ |
|
100
|
21 |
|
public function getUrl(): string |
|
101
|
|
|
{ |
|
102
|
21 |
|
return GPlayApps::GOOGLE_PLAY_APPS_URL . '/details?' . http_build_query( |
|
103
|
|
|
[ |
|
104
|
21 |
|
GPlayApps::REQ_PARAM_ID => $this->id, |
|
105
|
|
|
] |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Returns the full URL of the app's page on Google Play, specifying |
|
111
|
|
|
* the locale and country of the request. |
|
112
|
|
|
* |
|
113
|
|
|
* @return string URL of the app's page on Google Play, specifying the |
|
114
|
|
|
* locale and country of the request |
|
115
|
|
|
*/ |
|
116
|
30 |
|
public function getFullUrl(): string |
|
117
|
|
|
{ |
|
118
|
30 |
|
return GPlayApps::GOOGLE_PLAY_APPS_URL . '/details?' . http_build_query( |
|
119
|
|
|
[ |
|
120
|
30 |
|
GPlayApps::REQ_PARAM_ID => $this->id, |
|
121
|
30 |
|
GPlayApps::REQ_PARAM_LOCALE => $this->locale, |
|
122
|
30 |
|
GPlayApps::REQ_PARAM_COUNTRY => $this->country, |
|
123
|
|
|
] |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|