77import com .fasterxml .jackson .annotation .PropertyAccessor ;
88import com .fasterxml .jackson .databind .DeserializationFeature ;
99import com .fasterxml .jackson .databind .ObjectMapper ;
10+ import com .google .common .io .CharStreams ;
1011import io .ipdata .client .service .IpdataField ;
1112import io .ipdata .client .service .IpdataService ;
13+ import java .io .InputStreamReader ;
1214import java .net .URL ;
15+ import java .util .Arrays ;
1316import lombok .SneakyThrows ;
1417import lombok .extern .slf4j .Slf4j ;
1518import org .apache .log4j .Level ;
1619import org .apache .log4j .LogManager ;
20+ import org .junit .Test ;
1721
1822@ Slf4j
1923public class IpdataTest {
2024
2125 private static final String KEY = System .getenv ("IPDATACO_KEY" );
2226
27+
28+ @ Test
29+ @ SneakyThrows
30+ public void testBulk (){
31+ System .out .println (CharStreams .toString (new InputStreamReader (getClass ().getResourceAsStream ("/VERSION" ))));
32+ URL url = new URL ("https://api.ipdata.co" );
33+
34+ IpdataService ipdataService = Ipdata .builder ()
35+ .url (url )
36+ .withDefaultCache ()
37+ .key ("" )
38+ .get ();
39+ //ipdataService.asn("8.8.8.8");
40+ //System.out.println(ipdataService.bulkIpdata(Arrays.asList("8.8.8.8", "41.125.44.251")));
41+ }
42+
2343 @ SneakyThrows
2444 public static void main (String [] args ) {
2545
@@ -35,27 +55,33 @@ public static void main(String[] args) {
3555 .withDefaultCache ()
3656 .key (KEY )
3757 .get ();
38-
58+ String [] addresses = args [ 0 ]. split ( "," );
3959 LogManager .resetConfiguration ();
4060 LogManager .getLogger ("io" ).setLevel (Level .OFF );
4161 System .out .println ("##################### Asking for a full response #############################" );
4262 long duration = System .currentTimeMillis ();
43- String result = mapper .writeValueAsString (ipdataService .ipdata (args [0 ]));
63+ String result = mapper .writeValueAsString (ipdataService .ipdata (addresses [0 ]));
4464 duration = System .currentTimeMillis () - duration ;
4565 System .out .println (String .format ("Got response : %s \n Latency: %s milliseconds" , result , duration ));
4666 System .out .println ("################### Asking for ASN field ########################" );
4767 duration = System .currentTimeMillis ();
48- result = mapper .writeValueAsString (ipdataService .asn (args [0 ]));
68+ result = mapper .writeValueAsString (ipdataService .asn (addresses [0 ]));
4969 duration = System .currentTimeMillis () - duration ;
5070 System .out .println (String .format ("Got response : %s \n Latency: %s milliseconds" , result , duration ));
5171 System .out .println ("################## Asking for ip, city, and currency field ##########################" );
5272 duration = System .currentTimeMillis ();
53- result = mapper .writeValueAsString (ipdataService .getFields (args [0 ], IpdataField .IP , IpdataField .CITY , IpdataField .CURRENCY ));
73+ result = mapper .writeValueAsString (ipdataService .getFields (addresses [0 ], IpdataField .IP , IpdataField .CITY , IpdataField .CURRENCY ));
5474 duration = System .currentTimeMillis () - duration ;
5575 System .out .println (String .format ("Got response : %s \n Latency: %s milliseconds" , result , duration ));
5676 System .out .println ("################## Asking for full response that should hit the cache ##########################" );
5777 duration = System .currentTimeMillis ();
58- result = mapper .writeValueAsString (ipdataService .ipdata (args [0 ]));
78+ result = mapper .writeValueAsString (ipdataService .ipdata (addresses [0 ]));
79+ duration = System .currentTimeMillis () - duration ;
80+ System .out .println (String .format ("Got response : %s \n Latency: %s milliseconds" , result , duration ));
81+
82+ System .out .println ("##################### Asking for a bulk response #############################" );
83+ duration = System .currentTimeMillis ();
84+ result = mapper .writeValueAsString (ipdataService .bulkIpdata (Arrays .asList (addresses )));
5985 duration = System .currentTimeMillis () - duration ;
6086 System .out .println (String .format ("Got response : %s \n Latency: %s milliseconds" , result , duration ));
6187
0 commit comments