|
| 1 | +package io.ipinfo.api.model; |
| 2 | + |
| 3 | +import com.google.gson.annotations.SerializedName; |
| 4 | +import io.ipinfo.api.context.Context; |
| 5 | + |
| 6 | +public class IPResponseCore { |
| 7 | + private final String ip; |
| 8 | + private final Geo geo; |
| 9 | + @SerializedName("as") |
| 10 | + private final ASN asn; |
| 11 | + private final Boolean is_anonymous; |
| 12 | + private final Boolean is_anycast; |
| 13 | + private final Boolean is_hosting; |
| 14 | + private final Boolean is_mobile; |
| 15 | + private final Boolean is_satellite; |
| 16 | + private final boolean bogon; |
| 17 | + private transient Context context; |
| 18 | + |
| 19 | + public IPResponseCore( |
| 20 | + String ip, |
| 21 | + Geo geo, |
| 22 | + ASN asn, |
| 23 | + Boolean is_anonymous, |
| 24 | + Boolean is_anycast, |
| 25 | + Boolean is_hosting, |
| 26 | + Boolean is_mobile, |
| 27 | + Boolean is_satellite |
| 28 | + ) { |
| 29 | + this.ip = ip; |
| 30 | + this.geo = geo; |
| 31 | + this.asn = asn; |
| 32 | + this.is_anonymous = is_anonymous; |
| 33 | + this.is_anycast = is_anycast; |
| 34 | + this.is_hosting = is_hosting; |
| 35 | + this.is_mobile = is_mobile; |
| 36 | + this.is_satellite = is_satellite; |
| 37 | + this.bogon = false; |
| 38 | + } |
| 39 | + |
| 40 | + public IPResponseCore(String ip, boolean bogon) { |
| 41 | + this.ip = ip; |
| 42 | + this.bogon = bogon; |
| 43 | + this.geo = null; |
| 44 | + this.asn = null; |
| 45 | + this.is_anonymous = null; |
| 46 | + this.is_anycast = null; |
| 47 | + this.is_hosting = null; |
| 48 | + this.is_mobile = null; |
| 49 | + this.is_satellite = null; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Set by the library for extra utility functions |
| 54 | + * |
| 55 | + * @param context for country information |
| 56 | + */ |
| 57 | + public void setContext(Context context) { |
| 58 | + this.context = context; |
| 59 | + } |
| 60 | + |
| 61 | + public String getIp() { |
| 62 | + return ip; |
| 63 | + } |
| 64 | + |
| 65 | + public Geo getGeo() { |
| 66 | + return geo; |
| 67 | + } |
| 68 | + |
| 69 | + public ASN getAsn() { |
| 70 | + return asn; |
| 71 | + } |
| 72 | + |
| 73 | + public Boolean getIsAnonymous() { |
| 74 | + return is_anonymous; |
| 75 | + } |
| 76 | + |
| 77 | + public Boolean getIsAnycast() { |
| 78 | + return is_anycast; |
| 79 | + } |
| 80 | + |
| 81 | + public Boolean getIsHosting() { |
| 82 | + return is_hosting; |
| 83 | + } |
| 84 | + |
| 85 | + public Boolean getIsMobile() { |
| 86 | + return is_mobile; |
| 87 | + } |
| 88 | + |
| 89 | + public Boolean getIsSatellite() { |
| 90 | + return is_satellite; |
| 91 | + } |
| 92 | + |
| 93 | + public boolean getBogon() { |
| 94 | + return bogon; |
| 95 | + } |
| 96 | + |
| 97 | + public String getCountryName() { |
| 98 | + return context != null && geo != null ? context.getCountryName(geo.getCountryCode()) : (geo != null ? geo.getCountry() : null); |
| 99 | + } |
| 100 | + |
| 101 | + public Boolean isEU() { |
| 102 | + return context != null && geo != null ? context.isEU(geo.getCountryCode()) : null; |
| 103 | + } |
| 104 | + |
| 105 | + public CountryFlag getCountryFlag() { |
| 106 | + return context != null && geo != null ? context.getCountryFlag(geo.getCountryCode()) : null; |
| 107 | + } |
| 108 | + |
| 109 | + public String getCountryFlagURL() { |
| 110 | + return context != null && geo != null ? context.getCountryFlagURL(geo.getCountryCode()) : null; |
| 111 | + } |
| 112 | + |
| 113 | + public CountryCurrency getCountryCurrency() { |
| 114 | + return context != null && geo != null ? context.getCountryCurrency(geo.getCountryCode()) : null; |
| 115 | + } |
| 116 | + |
| 117 | + public Continent getContinentInfo() { |
| 118 | + return context != null && geo != null ? context.getContinent(geo.getCountryCode()) : null; |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public String toString() { |
| 123 | + if (bogon) { |
| 124 | + return "IPResponseCore{" + |
| 125 | + "ip='" + ip + '\'' + |
| 126 | + ", bogon=" + bogon + |
| 127 | + '}'; |
| 128 | + } |
| 129 | + return "IPResponseCore{" + |
| 130 | + "ip='" + ip + '\'' + |
| 131 | + ", geo=" + geo + |
| 132 | + ", asn=" + asn + |
| 133 | + ", is_anonymous=" + is_anonymous + |
| 134 | + ", is_anycast=" + is_anycast + |
| 135 | + ", is_hosting=" + is_hosting + |
| 136 | + ", is_mobile=" + is_mobile + |
| 137 | + ", is_satellite=" + is_satellite + |
| 138 | + '}'; |
| 139 | + } |
| 140 | +} |
0 commit comments