Module: NseData

Defined in:
lib/nse_data.rb,
lib/nse_data/version.rb,
lib/nse_data/api_manager.rb,
lib/nse_data/config/base.rb,
lib/nse_data/config/logger.rb,
lib/nse_data/cache/cache_store.rb,
lib/nse_data/cache/cache_policy.rb,
lib/nse_data/http_client/base_client.rb,
lib/nse_data/http_client/faraday_client.rb

Overview

The NseData module serves as the namespace for the NSE Data gem, which provides an interface to interact with and retrieve stock market data from the National Stock Exchange of India.

Defined Under Namespace

Modules: Cache, Config, HttpClient Classes: APIManager, Error

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.configure {|config| ... } ⇒ Object

Configure the logger for the NseData gem.

This method allows users to customize the logger used throughout the library. To use it, call ‘NseData.configure` and provide a block to set up the logger.

Example:

NseData.configure do |config|

custom_logger = Logger.new('nse_data.log')
custom_logger.level = Logger::DEBUG
config.logger = custom_logger

end

Yield Parameters:



45
46
47
48
# File 'lib/nse_data.rb', line 45

def configure
  @logger_config ||= Config::Logger.new
  yield(@logger_config) if block_given?
end

.define_api_methodsObject

This module provides functionality for accessing NSE data.



15
16
17
18
19
20
21
22
# File 'lib/nse_data.rb', line 15

def define_api_methods
  api_manager = APIManager.new
  api_manager.endpoints.each_key do |method_name|
    define_singleton_method("fetch_#{method_name}") do
      api_manager.fetch_data(method_name).body
    end
  end
end

.list_all_endpointsArray

Returns a list of all available endpoints.

Returns:

  • (Array)

    An array of endpoint names.



27
28
29
# File 'lib/nse_data.rb', line 27

def list_all_endpoints
  @list_all_endpoints ||= APIManager.new.load_endpoints
end

.loggerLogger

Access the configured logger.

This method returns the Logger instance configured through ‘NseData.configure`.

Returns:

  • (Logger)

    The configured Logger instance.

Raises:

  • (RuntimeError)

    If the logger has not been configured.



56
57
58
# File 'lib/nse_data.rb', line 56

def logger
  @logger_config&.logger || (raise 'Logger not configured. Please call NseData.configure first.')
end