Module: NseData

Defined in:
lib/nse_data.rb,
lib/nse_data/version.rb,
lib/nse_data/nse_api_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

Classes: ApiError, Error, NseApiClient

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.define_api_methodsObject

Dynamically define fetch methods for each API endpoint.



19
20
21
22
23
24
25
# File 'lib/nse_data.rb', line 19

def define_api_methods
  nse_api_client.endpoints.each_key do |method_name|
    define_singleton_method("fetch_#{method_name}") do |force_refresh: false|
      nse_api_client.fetch_data(method_name, force_refresh:)
    end
  end
end

.fetch_data(endpoint, force_refresh: false) ⇒ Hash, String

Fetches data from a specific API endpoint.

Parameters:

  • endpoint (String)

    The endpoint key.

  • force_refresh (Boolean) (defaults to: false)

    Skip cache if true.

Returns:

  • (Hash, String)

    The API response.



39
40
41
# File 'lib/nse_data.rb', line 39

def fetch_data(endpoint, force_refresh: false)
  nse_api_client.fetch_data(endpoint, force_refresh:)
end

.list_all_endpointsArray

Returns a list of all available endpoints.

Returns:

  • (Array)

    An array of endpoint names.



30
31
32
# File 'lib/nse_data.rb', line 30

def list_all_endpoints
  nse_api_client.endpoints
end

.nse_api_clientObject

Caches the instance of NseApiClient.



14
15
16
# File 'lib/nse_data.rb', line 14

def nse_api_client
  @nse_api_client ||= NseApiClient.new
end