Skip to content

Commit

Permalink
Add call radioBrowser.listCountryCodes() to embrace the deprecation o…
Browse files Browse the repository at this point in the history
…f country fields in favor of countrycode fields in HTTP API #123
  • Loading branch information
sfuhrm committed Aug 18, 2024
1 parent 43f64e0 commit e12b4ad
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,46 @@ private static String paths(final String...components) {
}

/** Retrieve a generic list containing a value/stationcount mapping.
* @param keyFieldName the API key name in the list of results. Usually 'name'.
* @param subPath the API sub path to use for the call.
* @return map of value and stationcount pairs.
* */
private Map<String, Integer> retrieveValueStationCountList(
final String keyFieldName,
final String subPath) {

List<Map<String, String>> map =
rest.postWithListOfMapOfString(subPath,
Collections.emptyMap());
return map.stream()
.collect(Collectors.toMap(
m -> m.get("name"),
m -> m.get(keyFieldName),
m -> Integer.parseInt(m.get("stationcount")),
(a, b) -> a));
}

/** List the known countries.
/** List the known clear-text countries.
* @return a list of countries (keys) and country usages (values).
* Example for key-value pair is @code{"Germany"} and @code{1}.
* @deprecated Since clear-text country names are deprecated in all parts of
* the HTTP API, please use the call {@link #listCountryCodes()}
* @see <a href="https://de1.api.radio-browser.info/#List_of_countries">
* API</a>
* */
@Deprecated
public Map<String, Integer> listCountries() {
return retrieveValueStationCountList("json/countries");
return retrieveValueStationCountList("name", "json/countries");
}

/** List the known country codes.
* @return a list of ISO-3166-1 country codes (keys) and country usages (values).
* Example for key-value pair is @code{"DE"} and @code{1}.
* @see <a href="https://de1.api.radio-browser.info/#List_of_countries">
* API</a>
* @see #listCountries()
* */
public Map<String, Integer> listCountryCodes() {
return retrieveValueStationCountList("iso_3166_1", "json/countries");
}

/** List the known codecs.
Expand All @@ -98,7 +115,7 @@ public Map<String, Integer> listCountries() {
* API</a>
* */
public Map<String, Integer> listCodecs() {
return retrieveValueStationCountList("json/codecs");
return retrieveValueStationCountList("name", "json/codecs");
}

/** List the known languages.
Expand All @@ -107,7 +124,7 @@ public Map<String, Integer> listCodecs() {
* API</a>
* */
public Map<String, Integer> listLanguages() {
return retrieveValueStationCountList("json/languages");
return retrieveValueStationCountList("name", "json/languages");
}

/** List the known tags.
Expand All @@ -116,7 +133,7 @@ public Map<String, Integer> listLanguages() {
* API</a>
* */
public Map<String, Integer> listTags() {
return retrieveValueStationCountList("json/tags");
return retrieveValueStationCountList("name", "json/tags");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public void testListCountries() throws IOException {
assertThat(countries.get("Germany"), Matchers.notNullValue());
}

@Test
public void testListCountryCodes() throws IOException {
Map<String, Integer> countries = radioBrowser.listCountryCodes();
assertThat(countries.size(), Matchers.greaterThan(0));
assertThat(countries.get("DE"), Matchers.notNullValue());
}

@Test
public void testListCodecs() throws IOException {
Map<String, Integer> codecs = radioBrowser.listCodecs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ public void listCountries() {
assertThat(countries.get("Germany"), is(not(0)));
}

@Test
public void listCountryCodes() {
Map<String, Integer> countries = browser.listCountryCodes();
assertThat(countries, notNullValue());
assertThat(countries.size(), is(not(0)));
assertThat(countries.get("DE"), is(not(0)));
}

@Test
public void listCodecs() {
Map<String, Integer> codecs = browser.listCodecs();
Expand Down

0 comments on commit e12b4ad

Please sign in to comment.