Class: NseData::NseApiClient
- Inherits:
-
Object
- Object
- NseData::NseApiClient
- Defined in:
- lib/nse_data/nse_api_client.rb
Overview
Handles API interactions with the NSE using ApiWrapper.
Instance Attribute Summary collapse
-
#api_configuration_path ⇒ Object
readonly
Returns the value of attribute api_configuration_path.
-
#cache_store ⇒ Object
readonly
Returns the value of attribute cache_store.
Instance Method Summary collapse
-
#endpoints ⇒ Hash
Returns all API endpoints available in the configuration.
-
#fetch_data(endpoint_key, force_refresh: false) ⇒ Hash, String
Fetches data from the specified API endpoint.
-
#initialize(api_configuration_path: nil, cache_store: nil) ⇒ NseApiClient
constructor
Initializes with optional custom settings.
Constructor Details
#initialize(api_configuration_path: nil, cache_store: nil) ⇒ NseApiClient
Initializes with optional custom settings.
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_path ⇒ Object (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_store ⇒ Object (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
#endpoints ⇒ Hash
Returns all API endpoints available in the configuration.
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.
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 |