Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/io/newsdata/api/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ public record Article(
@JsonProperty("ai_org") List<String> aiOrg,
@JsonProperty("sentiment") String sentiment,
@JsonProperty("sentiment_stats") Map<String, Object> sentimentStats,
@JsonProperty("datatype") String dataType
@JsonProperty("datatype") String dataType,
@JsonProperty("symbol") List<String> symbol,
@JsonProperty("market_id") List<String> marketId
) {}
4 changes: 2 additions & 2 deletions src/main/java/io/newsdata/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private Constants() {}
"excludecountry", "domain", "domainurl", "excludedomain", "language",
"excludelanguage", "prioritydomain", "timezone", "timeframe", "size",
"full_content", "image", "video", "page", "tag", "sentiment",
"excludefield", "removeduplicate", "organization", "symbol", "id", "url",
"excludefield", "removeduplicate", "organization", "market_id", "id", "url",
"sort", "creator", "datatype", "sentiment_score"
)),
Map.entry("count", Set.of(
Expand All @@ -130,7 +130,7 @@ private Constants() {}
"from_date", "to_date", "q", "qintitle", "qinmeta", "country",
"excludecountry", "domain", "domainurl", "excludedomain", "language",
"excludelanguage", "full_content", "image", "video", "organization",
"symbol", "prioritydomain", "page", "sentiment", "removeduplicate", "size",
"market_id", "prioritydomain", "page", "sentiment", "removeduplicate", "size",
"sort", "tag", "interval", "creator", "datatype", "sentiment_score"
))
);
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/io/newsdata/api/NewsDataApiClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand Down Expand Up @@ -243,6 +244,31 @@ void articleFieldsDecodeFromSnakeCase() {
assertEquals(1, art.sourcePriority());
}

// Market results carry both `symbol` and `market_id`; the two are separate
// response fields and both decode onto Article.
@Test
void articleDecodesSymbolAndMarketId() {
handle("market", exchange -> respond(exchange, 200,
successBody("[{\"article_id\":\"m1\",\"symbol\":[\"AAPL\",\"MSFT\"],"
+ "\"market_id\":[\"NASDAQ:AAPL\",\"NASDAQ:MSFT\"]}]")));
var client = defaultBuilder().build();
var resp = client.market(Params.of().with("market_id", "AAPL"));
var art = resp.articles(client.objectMapper()).get(0);
assertEquals(List.of("AAPL", "MSFT"), art.symbol());
assertEquals(List.of("NASDAQ:AAPL", "NASDAQ:MSFT"), art.marketId());
}

@Test
void articleSymbolAndMarketIdAreNullWhenAbsent() {
handle("latest", exchange -> respond(exchange, 200,
successBody("[{\"article_id\":\"a1\",\"title\":\"t\"}]")));
var client = defaultBuilder().build();
var art = client.latest(Params.of().with("q", "x"))
.articles(client.objectMapper()).get(0);
assertNull(art.symbol());
assertNull(art.marketId());
}

@Test
void countReturnsAggregateMap() {
handle("count", exchange -> respond(exchange, 200,
Expand Down
Loading