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