newsdataapi 0.3.0
newsdataapi: ^0.3.0 copied to clipboard
Official Dart/Flutter client for the Newsdata.io News API: real-time, historical, crypto & market news with retries, pagination and typed errors.
Changelog #
0.3.0 #
- Added
ArticleV2andresponse.articlesV2for v2's article layout, which renames and regroups the v1 fields:idforarticle_id,urlforlink,publishedAtforpubDate,metaDescriptionfordescription,keywordforkeywords,tickerforsymbol, and thesource,mediaandaigroups for the flatsource_*,image_url/video_urlandsentiment/ai_tag/ai_region/ai_orgfields. New in v2:ai.summary,fetchedAt,duplicate,coinandmarketId. The v2 endpoints and the real-time stream carry this layout;Articleandresponse.articlescontinue to model v1. A field your plan does not include arrives as the API's notice string in place of the data — decoding tolerates it, and the newisPlanNotice(value)tells it apart from real data. - Added the v2 endpoints:
newsV2,marketV2,cryptoV2,sourcesV2,countNewsV2,countMarketV2,countCryptoV2, each with typed named parameters for v2's filter vocabulary (sourceUrl/excludeSourceUrlreplace the four domain filters,sourcePriorityreplacespriorityDomain,contentreplacesfullContent).Endpoint.newsV2and friends work withscrollAll/paginate. There is no/2/archive—newsV2covers historical news throughfromDate/toDate. NewsdataResponsenow reads the v2 envelope'stotal_results/next_pageas well as v1'stotalResults/nextPage, sototalResultsandnextPageare populated whichever version answered.- Added the
excludeDomainUrlfilter to the v1 endpoints that accept it (everything butsources); it joins thedomainmutually-exclusive group. - A 429 whose body says the API credits are exhausted now throws
NewsdataApiLimitExceededException(the account's whole pool) orNewsdataApiKeyLimitExceededException(this one key's cap). Both extendNewsdataRateLimitException, so existing catches keep working. The newRegistrationLimitExceededcode — every real-time registration the plan allows is in use — is likewise never retried, but keeps the plainNewsdataRateLimitException, since it is about slots rather than credits. - Breaking: the real-time service moved to API v2. The management endpoints
are now
/2/websocket/{register,fetch,delete},news_typeisnewsrather thanlatest, andwebsocketRegistertakes the v2 filter vocabulary:sourceUrl/excludeSourceUrlreplacedomain,domainUrl,excludeDomainandexcludeDomainUrl,sourcePriorityreplacespriorityDomain, andcontentreplacesfullContent. Streamed responses andwebsocketFetchnow carrytotal_results, andwebsocketFetchanswers with a flatresultslist (one entry per query, each with a newlast_usedtimestamp) rather than nesting it underresults['queries']. Streamed articles use the v2 layout, soArticleandresponse.articles— which model v1 — no longer fit them; decode them withresponse.articlesV2. - Breaking:
baseUrlis now the API root without a version segment (https://newsdata.io/api/); the endpoint paths carry1/or2/. Drop the trailing1/if you override it.
0.0.2 #
- First release via automated tokenless OIDC publishing from GitHub Actions (Trusted Publisher configured on pub.dev). No source changes.
0.0.1 #
Initial release.
NewsDataApiClientwith typed named-parameter methods for all 8 endpoints (latest,archive,crypto,sources,market,count,cryptoCount,marketCount).- Client-side parameter validation (mutually-exclusive groups,
sentiment_scorerequiressentiment,size1–50,from_date/to_daterequired on count endpoints,rawQueryparsing). - Typed exception hierarchy:
NewsdataException→NewsdataValidationException,NewsdataApiException(→NewsdataAuthException,NewsdataRateLimitException,NewsdataServerException),NewsdataNetworkException. - Retries with exponential backoff and
Retry-Afterparsing (integer seconds + HTTP-date). - Two pagination helpers:
scrollAll(merged) andpaginate(Stream<NewsdataResponse>). - Configurable
http.Clientinjection, request timeout, and optional logger callback (API key is redacted in logged URLs). - Typed
Articledeserialization with all server fields including AI enrichments (aiTag,aiRegion,aiOrg,sentiment,sentimentStats). - 34 unit tests using
package:http/testingmocks — no network needed. - Compatible with Dart 3.0+ and Flutter 3.0+; works on iOS, Android, Web, and Desktop in pure Dart with no platform channels.