Class: RedfishClient::Connector

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(url, verify = true) ⇒ Connector

Create new connector.

Parameters:

  • url (String)

    base url of the Redfish service

  • verify (Boolean) (defaults to: true)

    verify SSL certificate of the service



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.

Parameters:

  • headers (Hash<String, String>)

    headers to be added



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.

Parameters:

  • path (String)

    path to the resource, relative to the base

Returns:

  • (Excon::Response)

    response object



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.

Parameters:

  • path (String)

    path to the resource, relative to the base url

Returns:

  • (Excon::Response)

    response object



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.

Parameters:

  • path (String)

    path to the resource, relative to the base

  • body (String) (defaults to: nil)

    data to be sent over the socket

Returns:

  • (Excon::Response)

    response object



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.

Parameters:

  • path (String)

    path to the resource, relative to the base

  • body (String) (defaults to: nil)

    data to be sent over the socket

Returns:

  • (Excon::Response)

    response object



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.

Parameters:

  • headers (List<String>)

    headers to remove



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