Class: Finlight::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/finlight/client.rb,
lib/finlight/client/version.rb

Overview

Entry point to the finlight API.

Examples:

client = Finlight::Client.new(api_key: ENV["FINLIGHT_API_KEY"])
response = client.articles.fetch_articles(query: "Nvidia", page_size: 20)
response.articles.each { |article| puts article.title }

Constant Summary collapse

VERSION =
"0.1.0"
CLIENT_VERSION =

Identifier sent as User-Agent (REST) and x-client-version (WebSocket).

"ruby/finlight-client@#{VERSION}".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, logger: Logging.default) ⇒ Client

Remaining keywords (+base_url:+, wss_url:, timeout: in seconds, retry_count:) are forwarded to Finlight::Config.

Parameters:

  • api_key (String)

    your finlight API key



32
33
34
35
36
37
38
# File 'lib/finlight/client.rb', line 32

def initialize(api_key:, logger: Logging.default, **)
  @config = Config.new(api_key: api_key, **)
  @logger = logger
  api_client = ApiClient.new(@config, logger: logger)
  @articles = ArticleService.new(api_client)
  @sources = SourceService.new(api_client)
end

Instance Attribute Details

#articlesObject (readonly)

Returns the value of attribute articles.



26
27
28
# File 'lib/finlight/client.rb', line 26

def articles
  @articles
end

#configObject (readonly)

Returns the value of attribute config.



26
27
28
# File 'lib/finlight/client.rb', line 26

def config
  @config
end

#sourcesObject (readonly)

Returns the value of attribute sources.



26
27
28
# File 'lib/finlight/client.rb', line 26

def sources
  @sources
end

Instance Method Details

#raw_websocketRawArticleWebSocketClient

A streaming client for raw articles (minimal latency, no enrichment).



51
52
53
# File 'lib/finlight/client.rb', line 51

def raw_websocket(**)
  RawArticleWebSocketClient.new(@config, logger: @logger, **)
end

#websocketArticleWebSocketClient

A streaming client for enriched articles — see BaseWebSocketClient#connect for options and usage.



44
45
46
# File 'lib/finlight/client.rb', line 44

def websocket(**)
  ArticleWebSocketClient.new(@config, logger: @logger, **)
end