Class: RedfishClient::Connector
- Inherits:
-
Object
- Object
- RedfishClient::Connector
- Defined in:
- lib/redfish_client/connector.rb
Overview
Connector serves as a low-level wrapper around HTTP calls that are used to retrieve data from the service API. It abstracts away implementation details such as sending the proper headers in request, which do not change between resource fetches.
Library users should treat this class as an implementation detail and use higer-level Resource instead.
Constant Summary collapse
- DEFAULT_HEADERS =
Default headers, as required by Redfish spec https://redfish.dmtf.org/schemas/DSP0266_1.4.0.html#request-headers
{ "Accept" => "application/json", "OData-Version" => "4.0" }.freeze
Instance Method Summary collapse
-
#add_headers(headers) ⇒ Object
Add HTTP headers to the requests made by the connector.
-
#delete(path) ⇒ Excon::Response
Issue DELETE requests to the service.
-
#get(path) ⇒ Excon::Response
Issue GET request to service.
-
#initialize(url, verify = true) ⇒ Connector
constructor
Create new connector.
-
#patch(path, body = nil) ⇒ Excon::Response
Issue PATCH requests to the service.
-
#post(path, body = nil) ⇒ Excon::Response
Issue POST requests to the service.
-
#remove_headers(headers) ⇒ Object
Remove HTTP headers from requests made by the connector.
Constructor Details
#initialize(url, verify = true) ⇒ Connector
Create new connector.
26 27 28 29 30 31 |
# File 'lib/redfish_client/connector.rb', line 26 def initialize(url, verify = true) @url = url @verify = verify @headers = DEFAULT_HEADERS.dup @connection = create_connection end |
Instance Method Details
#add_headers(headers) ⇒ Object
Add HTTP headers to the requests made by the connector.
36 37 38 39 |
# File 'lib/redfish_client/connector.rb', line 36 def add_headers(headers) @headers.merge!(headers) @connection = create_connection end |
#delete(path) ⇒ Excon::Response
Issue DELETE requests to the service.
86 87 88 |
# File 'lib/redfish_client/connector.rb', line 86 def delete(path) @connection.delete(path: path) end |
#get(path) ⇒ Excon::Response
Issue GET request to service.
56 57 58 |
# File 'lib/redfish_client/connector.rb', line 56 def get(path) @connection.get(path: path) end |
#patch(path, body = nil) ⇒ Excon::Response
Issue PATCH requests to the service.
76 77 78 79 80 |
# File 'lib/redfish_client/connector.rb', line 76 def patch(path, body = nil) params = { path: path } params[:body] = body if body @connection.patch(params) end |
#post(path, body = nil) ⇒ Excon::Response
Issue POST requests to the service.
65 66 67 68 69 |
# File 'lib/redfish_client/connector.rb', line 65 def post(path, body = nil) params = { path: path } params[:body] = body if body @connection.post(params) end |
#remove_headers(headers) ⇒ Object
Remove HTTP headers from requests made by the connector.
Headers that are not currently set are silently ignored and no error is raised.
47 48 49 50 |
# File 'lib/redfish_client/connector.rb', line 47 def remove_headers(headers) headers.each { |h| @headers.delete(h) } @connection = create_connection end |