Class: NseData::NseApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/nse_data/nse_api_client.rb

Overview

Handles API interactions with the NSE using ApiWrapper.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_configuration_path: nil, cache_store: nil) ⇒ NseApiClient

Initializes with optional custom settings.

Parameters:

  • api_configuration_path (String) (defaults to: nil)

    Path to the API configuration file.

  • cache_store (Object) (defaults to: nil)

    Custom cache store for caching responses.



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

def initialize(api_configuration_path: nil, cache_store: nil)
  @api_configuration_path = api_configuration_path || default_configuration_path
  @cache_store = cache_store
  configure_api_wrapper
end

Instance Attribute Details

#api_configuration_pathObject (readonly)

Returns the value of attribute api_configuration_path.



8
9
10
# File 'lib/nse_data/nse_api_client.rb', line 8

def api_configuration_path
  @api_configuration_path
end

#cache_storeObject (readonly)

Returns the value of attribute cache_store.



8
9
10
# File 'lib/nse_data/nse_api_client.rb', line 8

def cache_store
  @cache_store
end

Instance Method Details

#endpointsHash

Returns all API endpoints available in the configuration.

Returns:

  • (Hash)

    List of endpoints.



33
34
35
# File 'lib/nse_data/nse_api_client.rb', line 33

def endpoints
  @endpoints ||= ApiWrapper::ApiManager.new(api_configuration_path).endpoints
end

#fetch_data(endpoint_key, force_refresh: false) ⇒ Hash, String

Fetches data from the specified API endpoint.

Parameters:

  • endpoint_key (String)

    Key for the API endpoint.

  • force_refresh (Boolean) (defaults to: false)

    Skip cache if true.

Returns:

  • (Hash, String)

    Response data or raises an error if unsuccessful.



25
26
27
28
# File 'lib/nse_data/nse_api_client.rb', line 25

def fetch_data(endpoint_key, force_refresh: false)
  response = ApiWrapper.fetch_data(endpoint_key, force_refresh:)
  handle_response(response)
end