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 " );
@@ -113,6 +116,42 @@ public function serverInfo($region = null)
113
116
114
117
}
115
118
119
+ /**
120
+ * @param string $search
121
+ * @param array|null $option
122
+ * @return array
123
+ * @throws Exception
124
+ */
125
+ public function searchClans ($ search , $ option = null )
126
+ {
127
+
128
+ if (strlen ($ search ) == 0 ) {
129
+
130
+ //Search not specified
131
+ throw new Exception ("SEARCH_NOT_SPECIFIED " , "402 " );
132
+ } else if (strlen ($ search ) < 3 ) {
133
+
134
+ //Search no enough
135
+ throw new Exception ("NOT_ENOUGH_SEARCH_LENGTH " , "407 " );
136
+ } else if (strlen ($ search ) >= 100 ) {
137
+
138
+ //Search as exceeded
139
+ throw new Exception ("SEARCH_LIST_LIMIT_EXCEEDED " , "407 " );
140
+ }
141
+
142
+ $ returned = $ this ->request ("clansSearch " , [
143
+ "search " => $ search ,
144
+ "limit " => !empty ($ options ['limit ' ]) ? $ options ['limit ' ] : 100 ,
145
+ "pagination " => !empty ($ options ['pagination ' ]) ? $ options ['pagination ' ] : 1
146
+ ]);
147
+
148
+ return [
149
+ "count " => $ returned ['meta ' ]['count ' ],
150
+ "total " => $ returned ['meta ' ]['total ' ],
151
+ "clans " => $ returned ['data ' ]
152
+ ];
153
+ }
154
+
116
155
/**
117
156
* @param string $ref
118
157
* @param array $options
@@ -138,6 +177,14 @@ private function request($ref, $options)
138
177
$ link = str_replace ("{accounts} " , $ options ['accounts ' ], $ link );
139
178
break ;
140
179
180
+ case "clansSearch " :
181
+
182
+ //Replace data of the link
183
+ $ link = str_replace ("{search} " , $ options ['search ' ], $ link );
184
+ $ link = str_replace ("{limit} " , $ options ['limit ' ], $ link );
185
+ $ link = str_replace ("{pagination} " , $ options ['pagination ' ], $ link );
186
+ break ;
187
+
141
188
case "serverInfo " :
142
189
143
190
//Replace data of the link
0 commit comments