11package io .ipinfo ;
22
33import io .ipinfo .cache .Cache ;
4+ import io .ipinfo .context .Context ;
45import io .ipinfo .errors .RateLimitedException ;
56import io .ipinfo .model .ASNResponse ;
67import io .ipinfo .model .IPResponse ;
78import io .ipinfo .request .ASNRequest ;
89import io .ipinfo .request .IPRequest ;
910import okhttp3 .OkHttpClient ;
1011
11- import java .util .Map ;
12-
1312public class IPInfo {
1413 private final OkHttpClient client ;
14+ private final Context context ;
1515 private final String token ;
16- private final Map <String , String > countryMap ;
1716 private final Cache cache ;
1817
19- IPInfo (OkHttpClient client , String token , Map < String , String > countryMap , Cache cache ) {
18+ IPInfo (OkHttpClient client , Context context , String token , Cache cache ) {
2019 this .client = client ;
20+ this .context = context ;
2121 this .token = token ;
22- this .countryMap = countryMap ;
2322 this .cache = cache ;
2423 }
2524
@@ -50,6 +49,8 @@ public IPResponse lookupIP(String ip) throws RateLimitedException {
5049 if (response != null ) return response ;
5150
5251 response = new IPRequest (client , token , ip ).handle ();
52+ response .setContext (context );
53+
5354 cache .setIp (ip , response );
5455 return response ;
5556 }
@@ -66,17 +67,9 @@ public ASNResponse lookupASN(String asn) throws RateLimitedException {
6667 if (response != null ) return response ;
6768
6869 response = new ASNRequest (client , token , asn ).handle ();
70+ response .setContext (context );
71+
6972 cache .setAsn (asn , response );
7073 return response ;
7174 }
72-
73- /**
74- * Looks up a country name.
75- *
76- * @param countryCode
77- * @return The name of the country.
78- */
79- public String lookupCountryName (String countryCode ) {
80- return countryMap .getOrDefault (countryCode , null );
81- }
8275}
0 commit comments