4
4
5
5
use Exception ;
6
6
use GuzzleHttp \Client ;
7
+ use function GuzzleHttp \Psr7 \str ;
7
8
8
9
9
10
/**
@@ -19,6 +20,8 @@ class WargamingApi
19
20
"accountSearch " => "api.worldoftanks.{region}/wgn/account/list/?application_id={key}&search={search}&limit={limit}&type={method} " ,
20
21
"accountId " => "api.worldoftanks.{region}/wgn/account/info/?application_id={key}&account_id={accounts} " ,
21
22
23
+ "clansSearch " => "api.worldoftanks.{region}/wgn/clans/list/?application_id={key}&search={search}&limit={limit}&page_no={pagination} " ,
24
+
22
25
"serverInfo " => "api.worldoftanks.{region}/wgn/servers/info/?application_id={key} "
23
26
];
24
27
@@ -46,7 +49,7 @@ public function searchPlayers($search, $options = null)
46
49
47
50
//Search not specified
48
51
throw new Exception ("SEARCH_NOT_SPECIFIED " , "402 " );
49
- } else if (strlen ($ search ) <= 3 ) {
52
+ } else if (strlen ($ search ) < 3 ) {
50
53
51
54
//Search no enough
52
55
throw new Exception ("NOT_ENOUGH_SEARCH_LENGTH " , "407 " );
@@ -59,7 +62,8 @@ public function searchPlayers($search, $options = null)
59
62
$ returned = $ this ->request ("accountSearch " , [
60
63
"search " => $ search ,
61
64
"limit " => !empty ($ options ['limit ' ]) ? $ options ['limit ' ] : 100 ,
62
- "method " => !empty ($ options ['method ' ]) ? $ options ['method ' ] : "startswith "
65
+ "method " => !empty ($ options ['method ' ]) ? $ options ['method ' ] : "startswith " ,
66
+ "region " => !empty ($ options ['region ' ]) ? $ options ['region ' ] : $ this ->region
63
67
]);
64
68
65
69
return [
@@ -82,7 +86,8 @@ public function searchPlayer($accounts_id = [])
82
86
}
83
87
84
88
$ returned = $ this ->request ("accountId " , [
85
- "accounts " => $ accounts
89
+ "accounts " => $ accounts ,
90
+ "region " => !empty ($ options ['region ' ]) ? $ options ['region ' ] : $ this ->region
86
91
]);
87
92
88
93
return [
@@ -99,20 +104,56 @@ public function searchPlayer($accounts_id = [])
99
104
*/
100
105
public function serverInfo ($ region = null )
101
106
{
102
- $ region = !empty ($ region ) ? $ region : $ this ->region ;
103
107
104
108
$ returned = $ this ->request ("serverInfo " , [
105
- "region " => $ region
106
- ])[ ' data ' ] ;
109
+ "region " => ! empty ( $ region ) ? $ region : $ this -> region
110
+ ]);
107
111
108
112
return [
109
- "wotb " => $ returned ['wotb ' ],
110
- "wot " => $ returned ['wot ' ],
111
- "wows " => $ returned ['wows ' ]
113
+ "wotb " => $ returned ['data ' ][ ' wotb ' ],
114
+ "wot " => $ returned ['data ' ][ ' wot ' ],
115
+ "wows " => $ returned ['data ' ][ ' wows ' ]
112
116
];
113
117
114
118
}
115
119
120
+ /**
121
+ * @param string $search
122
+ * @param array|null $options
123
+ * @return array
124
+ * @throws Exception
125
+ */
126
+ public function searchClans ($ search , $ options = null )
127
+ {
128
+
129
+ if (strlen ($ search ) == 0 ) {
130
+
131
+ //Search not specified
132
+ throw new Exception ("SEARCH_NOT_SPECIFIED " , "402 " );
133
+ } else if (strlen ($ search ) < 3 ) {
134
+
135
+ //Search no enough
136
+ throw new Exception ("NOT_ENOUGH_SEARCH_LENGTH " , "407 " );
137
+ } else if (strlen ($ search ) >= 100 ) {
138
+
139
+ //Search as exceeded
140
+ throw new Exception ("SEARCH_LIST_LIMIT_EXCEEDED " , "407 " );
141
+ }
142
+
143
+ $ returned = $ this ->request ("clansSearch " , [
144
+ "search " => $ search ,
145
+ "limit " => !empty ($ options ['limit ' ]) ? $ options ['limit ' ] : 100 ,
146
+ "pagination " => !empty ($ options ['pagination ' ]) ? $ options ['pagination ' ] : 1 ,
147
+ "region " => !empty ($ options ['region ' ]) ? $ options ['region ' ] : $ this ->region
148
+ ]);
149
+
150
+ return [
151
+ "count " => $ returned ['meta ' ]['count ' ],
152
+ "total " => $ returned ['meta ' ]['total ' ],
153
+ "clans " => $ returned ['data ' ]
154
+ ];
155
+ }
156
+
116
157
/**
117
158
* @param string $ref
118
159
* @param array $options
@@ -130,12 +171,23 @@ private function request($ref, $options)
130
171
$ link = str_replace ("{search} " , $ options ['search ' ], $ link );
131
172
$ link = str_replace ("{limit} " , $ options ['limit ' ], $ link );
132
173
$ link = str_replace ("{method} " , $ options ['method ' ], $ link );
174
+ $ link = str_replace ("{region} " , $ options ['region ' ], $ link );
133
175
break ;
134
176
135
177
case "accountId " :
136
178
137
179
//Replace data of the link
138
180
$ link = str_replace ("{accounts} " , $ options ['accounts ' ], $ link );
181
+ $ link = str_replace ("{region} " , $ options ['region ' ], $ link );
182
+ break ;
183
+
184
+ case "clansSearch " :
185
+
186
+ //Replace data of the link
187
+ $ link = str_replace ("{search} " , $ options ['search ' ], $ link );
188
+ $ link = str_replace ("{limit} " , $ options ['limit ' ], $ link );
189
+ $ link = str_replace ("{pagination} " , $ options ['pagination ' ], $ link );
190
+ $ link = str_replace ("{region} " , $ options ['region ' ], $ link );
139
191
break ;
140
192
141
193
case "serverInfo " :
0 commit comments