You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

com.github.fedeoasi:news-api-client_2.12

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.fedeoasi:news-api-client_2.12

News API Client


Version published
Maintainers
1

Readme

Source

News API Client

Maven Central Build Status

An HTTP client written in Scala for the News API.

Setup

Add the following line to your SBT build definition:

libraryDependencies += "com.github.fedeoasi" %% "news-api-client" % "0.4"

You can get an API key by registering at News API.

Both a synchronous and an asynchronous version of the client are provided.

Synchronous client:

import com.github.fedeoasi.newsapi._
val client = NewsApiClient("<NEWS_API_KEY>")

Asynchronous client:

import com.github.fedeoasi.newsapi._
import scala.concurrent.ExecutionContext.Implicits.global
val client = AsyncNewsApiClient("<NEWS_API_KEY>")

The asynchronous client requires an ExecutionContext at construction time. You can choose whether you want to provide your own execution context or bring the default one into scope.

Usage

All responses returned by the client are wrapped in an Either object. You can retrieve the response using pattern matching as follows:

client.topHeadlines() match {
  case Right(response) => //do something with response
  case Left(message) => //Something went wrong
}

The asynchronous client wraps the above result type into a scala Future. Other than that the method names and parameters are identical.

Top Headlines

Provides live top and breaking headlines as described in its News API documentation.

The following code fragment fetches all headlines from US news sources:

import com.neovisionaries.i18n.CountryCode
client.topHeadlines(country = Some(CountryCode.US))

See all the supported parameters here.

Everything

Search through millions of articles as described in its News API documentation.

You can find all articles about BitCoin from the Wall Street Journal as follows:

client.everything(
  query = Some("bitcoin"),
  sources = Seq("the-wall-street-journal")
)

See all the supported parameters here.

Sources

Returns a subset of the news publishers that top headlines are available from as described in its News API documentation.

You can find all sources as follows:

client.sources()

See all the supported parameters here.

Examples

  • Synchronous client example
  • Asynchronous client example

FAQs

Package last updated on 07 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc