-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix ( Hiding weather forecast for country)
- Loading branch information
1 parent
2afef92
commit 4ea1c06
Showing
4 changed files
with
71 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/vodacom/falcon/service/CountryMetadataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.vodacom.falcon.service; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.vodacom.falcon.client.APICaller; | ||
import com.vodacom.falcon.util.JsonUtil; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.net.http.HttpResponse; | ||
import java.util.Map; | ||
|
||
import static com.vodacom.falcon.util.FalconDefaults.COUNTRY_API_BASE_URL; | ||
import static com.vodacom.falcon.util.JsonUtil.deserializeByTypeReference; | ||
|
||
@Service | ||
public class CountryMetadataService { | ||
public String getCountryCode(String term) { | ||
String url = String.format("%s/api/v0.1/countries/positions/q?country=%s", COUNTRY_API_BASE_URL, term.toLowerCase()); | ||
|
||
HttpResponse<String> response = APICaller.getData(url); | ||
if (response != null) { | ||
Map<Object, Object> data = deserializeByTypeReference(response.body(), new TypeReference<>() { | ||
}); | ||
if (data != null) { | ||
Map<Object, Object> currency = deserializeByTypeReference(JsonUtil.serialize(data.get("data")), new TypeReference<>() { | ||
}); | ||
if (currency != null) return currency.get("iso2").toString(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public String getCurrency(String countyCode) { | ||
String url = String.format("%s/api/v0.1/countries/currency/q?iso2=%s", COUNTRY_API_BASE_URL, countyCode); | ||
|
||
HttpResponse<String> response = APICaller.getData(url); | ||
if (response != null) { | ||
Map<Object, Object> data = deserializeByTypeReference(response.body(), new TypeReference<>() { | ||
}); | ||
if (data != null) { | ||
Map<Object, Object> currency = deserializeByTypeReference(JsonUtil.serialize(data.get("data")), new TypeReference<>() { | ||
}); | ||
if (currency != null) return currency.get("currency").toString(); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters