Skip to content

Commit 0f4e13c

Browse files
author
awaismslm
committed
Inlined JSON files
1 parent 10bf68e commit 0f4e13c

File tree

9 files changed

+1031
-1134
lines changed

9 files changed

+1031
-1134
lines changed

README.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ public class Main {
140140
This library provides a system to lookup country names through ISO2 country
141141
codes.
142142

143-
By default, this translation exists for English (United States). If you wish to
144-
provide a different language mapping, just use the following system in the
145-
builder:
146-
147143
```java
148144
import io.ipinfo.api.IPinfo;
149145
import io.ipinfo.api.errors.RateLimitedException;
@@ -153,7 +149,6 @@ public class Main {
153149
public static void main(String... args) {
154150
IPinfo ipInfo = new IPinfo.Builder()
155151
.setToken("YOUR TOKEN")
156-
.setCountryFile(new File("path/to/file.json"))
157152
.build();
158153

159154
try {
@@ -171,18 +166,11 @@ public class Main {
171166
}
172167
```
173168

174-
This file must follow the same layout as seen [here](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/en_US.json)
175-
176-
More language files can be found [here](https://country.io/data)
177-
178169
#### EU Country Lookup
179170

180171
This library provides a system to lookup if a country is a member of the European Union (EU) through
181172
ISO2 country codes.
182173

183-
By default, [here](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/eu.json) is the file containing all the EU members.
184-
If you wish to provide a different file, just use the following system in the builder:
185-
186174
```java
187175
import io.ipinfo.api.IPinfo;
188176
import io.ipinfo.api.errors.RateLimitedException;
@@ -192,7 +180,6 @@ public class Main {
192180
public static void main(String... args) {
193181
IPinfo ipInfo = new IPinfo.Builder()
194182
.setToken("YOUR TOKEN")
195-
.setEUCountryFile(new File("path/to/file.json"))
196183
.build();
197184

198185
try {
@@ -211,14 +198,6 @@ public class Main {
211198

212199
This library provides a system to lookup if a country is a member of the European Union (EU), emoji and unicode of the country's flag, code and symbol of the country's currency, and public link to the country's flag image as an SVG and continent code and name through ISO2 country codes.
213200

214-
Following are the file that are loaded by default:
215-
- [eu.json](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/eu.json)
216-
- [flags.json](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/flags.json)
217-
- [currency.json](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/currency.json)
218-
- [continent.json](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/continent.json)
219-
220-
If you wish to provide a different file, just use the following system in the builder:
221-
222201
```java
223202
import io.ipinfo.api.IPinfo;
224203
import io.ipinfo.api.errors.RateLimitedException;
@@ -228,10 +207,6 @@ public class Main {
228207
public static void main(String... args) {
229208
IPinfo ipInfo = new IPinfo.Builder()
230209
.setToken("YOUR TOKEN")
231-
.setEUCountryFile(new File("path/to/file.json"))
232-
.setCountryFlagFile(new File("path/to/file.json"))
233-
.setCountryCurrencyFile(new File("path/to/file.json"))
234-
.setContinentFile(new File("path/to/file.json"))
235210
.build();
236211

237212
try {
@@ -258,12 +233,6 @@ public class Main {
258233
}
259234
```
260235

261-
The files must follow the same layout as seen at:
262-
- [eu.json](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/eu.json)
263-
- [flags.json](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/flags.json)
264-
- [currency.json](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/currency.json)
265-
- [continent.json](https://github.com/ipinfo/java-ipinfo/blob/master/src/main/resources/continent.json)
266-
267236
#### Location Information
268237

269238
This library provides an easy way to get the latitude and longitude of an IP Address:
@@ -277,7 +246,6 @@ public class Main {
277246
public static void main(String... args) {
278247
IPinfo ipInfo = new IPinfo.Builder()
279248
.setToken("YOUR TOKEN")
280-
.setCountryFile(new File("path/to/file.json"))
281249
.build();
282250

283251
try {

pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@
103103
<outputDirectory>target/classes</outputDirectory>
104104

105105
<finalName>${project.name}-${project.version}</finalName>
106-
<resources>
107-
<resource>
108-
<directory>${project.basedir}/src/main/resources</directory>
109-
<includes>
110-
<include>*.json</include>
111-
</includes>
112-
</resource>
113-
</resources>
114106

115107
<plugins>
116108
<plugin>

src/main/java/io/ipinfo/api/IPinfo.java

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
import io.ipinfo.api.context.Context;
99
import io.ipinfo.api.errors.RateLimitedException;
1010
import io.ipinfo.api.model.ASNResponse;
11-
import io.ipinfo.api.model.Continent;
12-
import io.ipinfo.api.model.CountryCurrency;
13-
import io.ipinfo.api.model.CountryFlag;
1411
import io.ipinfo.api.model.IPResponse;
1512
import io.ipinfo.api.model.MapResponse;
1613
import io.ipinfo.api.request.ASNRequest;
@@ -19,15 +16,11 @@
1916
import okhttp3.*;
2017

2118
import javax.annotation.ParametersAreNonnullByDefault;
22-
import java.io.File;
23-
import java.io.FileReader;
2419
import java.io.IOException;
2520
import java.lang.reflect.Type;
2621
import java.time.Duration;
2722
import java.util.ArrayList;
28-
import java.util.Collections;
2923
import java.util.HashMap;
30-
import java.util.Map;
3124
import java.util.List;
3225
import java.util.concurrent.ConcurrentHashMap;
3326
import java.util.concurrent.CountDownLatch;
@@ -361,16 +354,6 @@ public static String cacheKey(String k) {
361354
}
362355

363356
public static class Builder {
364-
private File countryFile =
365-
new File(this.getClass().getClassLoader().getResource("en_US.json").getFile());
366-
private File euCountryFile =
367-
new File(this.getClass().getClassLoader().getResource("eu.json").getFile());
368-
private File countryFlagFile =
369-
new File(this.getClass().getClassLoader().getResource("flags.json").getFile());
370-
private File countryCurrencyFile =
371-
new File(this.getClass().getClassLoader().getResource("currency.json").getFile());
372-
private File continentFile =
373-
new File(this.getClass().getClassLoader().getResource("continent.json").getFile());
374357
private OkHttpClient client = new OkHttpClient.Builder().build();
375358
private String token = "";
376359
private Cache cache = new SimpleCache(Duration.ofDays(1));
@@ -385,64 +368,13 @@ public Builder setToken(String token) {
385368
return this;
386369
}
387370

388-
public Builder setCountryFile(File file) {
389-
this.countryFile = file;
390-
return this;
391-
}
392-
393-
public Builder setEUCountryFile(File file) {
394-
this.euCountryFile = file;
395-
return this;
396-
}
397-
398-
public Builder setCountryFlagFile(File file) {
399-
this.countryFlagFile = file;
400-
return this;
401-
}
402-
403-
public Builder setCountryCurrencyFile(File file) {
404-
this.countryCurrencyFile = file;
405-
return this;
406-
}
407-
408-
public Builder setContinentFile(File file) {
409-
this.continentFile = file;
410-
return this;
411-
}
412-
413371
public Builder setCache(Cache cache) {
414372
this.cache = cache;
415373
return this;
416374
}
417375

418376
public IPinfo build() {
419-
Type type = new TypeToken<Map<String, String>>(){}.getType();
420-
Type euCountriesType = new TypeToken<List<String>>(){}.getType();
421-
Type countriesFlagsType = new TypeToken<Map<String, CountryFlag>>(){}.getType();
422-
Type countriesCurrencyType = new TypeToken<Map<String, CountryCurrency>>(){}.getType();
423-
Type continentType = new TypeToken<Map<String, Continent>>(){}.getType();
424-
Gson gson = new Gson();
425-
Map<String, String> map;
426-
Map<String, CountryFlag> countriesFlags;
427-
Map<String, CountryCurrency> countriesCurrencies;
428-
Map<String, Continent> continents;
429-
List<String> euList;
430-
431-
try {
432-
map = Collections.unmodifiableMap(gson.fromJson(new FileReader(countryFile), type));
433-
countriesFlags = Collections.unmodifiableMap(gson.fromJson(new FileReader(countryFlagFile), countriesFlagsType));
434-
countriesCurrencies = Collections.unmodifiableMap(gson.fromJson(new FileReader(countryCurrencyFile), countriesCurrencyType));
435-
continents = Collections.unmodifiableMap(gson.fromJson(new FileReader(continentFile), continentType));
436-
euList = Collections.unmodifiableList(gson.fromJson(new FileReader(euCountryFile), euCountriesType));
437-
} catch (Exception e) {
438-
map = Collections.unmodifiableMap(new HashMap<>());
439-
countriesFlags = Collections.unmodifiableMap(new HashMap<>());
440-
countriesCurrencies = Collections.unmodifiableMap(new HashMap<>());
441-
continents = Collections.unmodifiableMap(new HashMap<>());
442-
euList = Collections.unmodifiableList(new ArrayList<>());
443-
}
444-
445-
return new IPinfo(client, new Context(map, euList, countriesFlags, countriesCurrencies, continents), token, cache);
377+
return new IPinfo(client, new Context(), token, cache);
446378
}
447379
}
448380

0 commit comments

Comments
 (0)