fix(audible): emit external Audible URL with region domain (#2329)
This commit is contained in:
@@ -36,6 +36,19 @@ import java.util.stream.Collectors;
|
||||
public class AudibleParser implements BookParser, DetailedMetadataProvider {
|
||||
private static final String DEFAULT_TLD = "com";
|
||||
|
||||
private static final Map<String, String> EXTERNAL_BASE_URIS = Map.of(
|
||||
"com", "https://www.audible.com/",
|
||||
"co.uk", "https://www.audible.co.uk/",
|
||||
"de", "https://www.audible.de/",
|
||||
"fr", "https://www.audible.fr/",
|
||||
"it", "https://www.audible.it/",
|
||||
"es", "https://www.audible.es/",
|
||||
"ca", "https://www.audible.ca/",
|
||||
"com.au", "https://www.audible.com.au/",
|
||||
"co.jp", "https://www.audible.co.jp",
|
||||
"in", "https://www.audible.in/"
|
||||
);
|
||||
|
||||
private static final Map<String, String> BASE_URIS = Map.of(
|
||||
"com", "https://api.audible.com/",
|
||||
"co.uk", "https://api.audible.co.uk/",
|
||||
@@ -149,13 +162,32 @@ public class AudibleParser implements BookParser, DetailedMetadataProvider {
|
||||
List<AudibleProduct> products
|
||||
) {}
|
||||
|
||||
private String getBaseURI() {
|
||||
private String getTld() {
|
||||
var settings = appSettingService.getAppSettings().getMetadataProviderSettings();
|
||||
String tld = DEFAULT_TLD;
|
||||
if (settings != null && settings.getAudible() != null && settings.getAudible().getDomain() != null) {
|
||||
tld = settings.getAudible().getDomain();
|
||||
}
|
||||
return BASE_URIS.getOrDefault(tld, BASE_URIS.get(DEFAULT_TLD));
|
||||
return tld;
|
||||
}
|
||||
|
||||
private String getBaseURI() {
|
||||
return BASE_URIS.getOrDefault(getTld(), BASE_URIS.get(DEFAULT_TLD));
|
||||
}
|
||||
|
||||
private String getExternalBaseURI() {
|
||||
return EXTERNAL_BASE_URIS.getOrDefault(getTld(), EXTERNAL_BASE_URIS.get(DEFAULT_TLD));
|
||||
}
|
||||
|
||||
private String buildExternalURI(String asin) {
|
||||
if (asin == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return UriComponentsBuilder.fromUriString(getExternalBaseURI())
|
||||
.path("/dp/{asin}")
|
||||
.build(asin)
|
||||
.toString();
|
||||
}
|
||||
|
||||
private URI getURI(
|
||||
@@ -417,6 +449,7 @@ public class AudibleParser implements BookParser, DetailedMetadataProvider {
|
||||
|
||||
return BookMetadata.builder()
|
||||
.provider(MetadataProvider.Audible)
|
||||
.externalUrl(buildExternalURI(product.asin))
|
||||
.asin(product.asin)
|
||||
.audibleId(product.asin)
|
||||
.title(product.title)
|
||||
|
||||
@@ -149,6 +149,42 @@ public class AudibleParserTest {
|
||||
assertThat(actual).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetchTopMetadata_includesExternalURLWithDomain() throws Exception {
|
||||
mockHttpClientResponse(
|
||||
"https://api.audible.co.jp/1.0/catalog/products/EXAMPLESKU",
|
||||
200,
|
||||
readFixture("example-asin-lookup.json")
|
||||
);
|
||||
|
||||
when(mockAppSettingService.getAppSettings()).thenReturn(getAppSettings( "co.jp"));
|
||||
|
||||
Book book = getBook("EXAMPLESKU");
|
||||
FetchMetadataRequest fetchMetadataRequest = FetchMetadataRequest.builder().build();
|
||||
|
||||
BookMetadata actual = audibleParser.fetchTopMetadata(book, fetchMetadataRequest);
|
||||
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual.getExternalUrl()).isEqualTo("https://www.audible.co.jp/dp/1705047572");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetchTopMetadata_includesExternalURL() throws Exception {
|
||||
mockHttpClientResponse(
|
||||
"https://api.audible.com/1.0/catalog/products/EXAMPLESKU",
|
||||
200,
|
||||
readFixture("example-asin-lookup.json")
|
||||
);
|
||||
|
||||
Book book = getBook("EXAMPLESKU");
|
||||
FetchMetadataRequest fetchMetadataRequest = FetchMetadataRequest.builder().build();
|
||||
|
||||
BookMetadata actual = audibleParser.fetchTopMetadata(book, fetchMetadataRequest);
|
||||
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual.getExternalUrl()).isEqualTo("https://www.audible.com/dp/1705047572");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetchTopMetadata_removesExtraWhitespace() throws Exception {
|
||||
mockHttpClientResponse(
|
||||
|
||||
Reference in New Issue
Block a user