Class: Finlight::ArticleService

Inherits:
Object
  • Object
show all
Defined in:
lib/finlight/article_service.rb

Overview

Fetches financial news articles.

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ ArticleService

Returns a new instance of ArticleService.



6
7
8
# File 'lib/finlight/article_service.rb', line 6

def initialize(api_client)
  @api_client = api_client
end

Instance Method Details

#fetch_article_by_link(link:, **params) ⇒ Article

Fetches a single article by its URL.

Examples:

article = client.articles.fetch_article_by_link(
  link: "https://www.reuters.com/technology/example", include_content: true
)

Parameters:

  • link (String)

    the URL of the article to fetch

  • params (Hash)

    optional include_content: and include_entities:

Returns:

Raises:

  • (ApiError)

    if the API request fails or the article is not found



43
44
45
46
47
48
# File 'lib/finlight/article_service.rb', line 43

def fetch_article_by_link(link:, **params)
  query = Params.normalize(params.merge(link: link))
  query = query.transform_values { |v| [true, false].include?(v) ? v.to_s : v }
  response = @api_client.get("/v2/articles/by-link", query)
  Article.from_h(response.fetch("article"))
end

#fetch_articles(**params) ⇒ ArticleResponse

Searches articles with advanced filtering by query, tickers, sources, dates, countries and categories.

Examples:

response = client.articles.fetch_articles(
  query: "Nvidia", tickers: ["NVDA"], include_content: true, page_size: 20
)
response.articles.each { |a| puts a.title }

Parameters:

  • params (Hash)

    snake_case keywords, e.g. query:, sources:, exclude_sources:, from:, to:, language:, tickers:, include_entities:, exclude_empty_content:, include_content:, order_by: ("publishDate"|"createdAt"|"revisedDate"), order: ("ASC"|"DESC"), page_size: (1-1000), page:, countries:, categories:

Returns:

Raises:

  • (ApiError)

    if the API request fails



27
28
29
30
# File 'lib/finlight/article_service.rb', line 27

def fetch_articles(**params)
  response = @api_client.post("/v2/articles", Params.normalize(params))
  ArticleResponse.from_h(response)
end