Class: DhanHQ::BaseAPI
- Inherits:
-
Object
- Object
- DhanHQ::BaseAPI
- Includes:
- APIHelper, AttributeHelper
- Defined in:
- lib/DhanHQ/core/base_api.rb
Overview
Base class for all API resource classes. Delegates HTTP requests to Client and exposes helpers shared by resource wrappers.
Direct Known Subclasses
BaseResource, Resources::Edis, Resources::ExpiredOptionsData, Resources::ForeverOrders, Resources::Funds, Resources::HistoricalData, Resources::Holdings, Resources::IPSetup, Resources::IcebergOrders, Resources::Instruments, Resources::KillSwitch, Resources::MarginCalculator, Resources::MarketFeed, Resources::OptionChain, Resources::Orders, Resources::PnlExit, Resources::Positions, Resources::Profile, Resources::Statements, Resources::SuperOrders, Resources::TraderControl, Resources::Trades, Resources::TwapOrders
Constant Summary collapse
- API_TYPE =
Default API type used when a subclass does not override #initialize.
:non_trading_api- HTTP_PATH =
Root path prepended to each endpoint segment.
""
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#delete(endpoint) ⇒ Hash, Array
Perform a DELETE request via
Client. -
#get(endpoint, params: {}) ⇒ Hash, Array
Perform a GET request via
Client. -
#initialize(api_type: self.class::API_TYPE) ⇒ BaseAPI
constructor
Initializes the BaseAPI with the appropriate Client instance.
-
#post(endpoint, params: {}) ⇒ Hash, Array
Perform a POST request via
Client. -
#put(endpoint, params: {}) ⇒ Hash, Array
Perform a PUT request via
Client.
Methods included from AttributeHelper
#camelize_keys, #inspect, #normalize_keys, #snake_case, #titleize_keys
Methods included from APIHelper
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
16 17 18 |
# File 'lib/DhanHQ/core/base_api.rb', line 16 def client @client end |
Instance Method Details
#delete(endpoint) ⇒ Hash, Array
Perform a DELETE request via Client
59 60 61 62 |
# File 'lib/DhanHQ/core/base_api.rb', line 59 def delete(endpoint) formatted_params = format_params(endpoint, {}) handle_response(client.delete(build_path(endpoint), formatted_params)) end |
#get(endpoint, params: {}) ⇒ Hash, Array
Perform a GET request via Client
30 31 32 33 |
# File 'lib/DhanHQ/core/base_api.rb', line 30 def get(endpoint, params: {}) formatted_params = format_params(endpoint, params) handle_response(client.get(build_path(endpoint), formatted_params)) end |
#post(endpoint, params: {}) ⇒ Hash, Array
Perform a POST request via Client
40 41 42 43 |
# File 'lib/DhanHQ/core/base_api.rb', line 40 def post(endpoint, params: {}) formatted_params = format_params(endpoint, params) handle_response(client.post(build_path(endpoint), formatted_params)) end |
#put(endpoint, params: {}) ⇒ Hash, Array
Perform a PUT request via Client
50 51 52 53 |
# File 'lib/DhanHQ/core/base_api.rb', line 50 def put(endpoint, params: {}) formatted_params = format_params(endpoint, params) handle_response(client.put(build_path(endpoint), formatted_params)) end |