Class: NessusClient::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/nessus_client/request.rb

Overview

Abstract http request class for NessusClient. Provides some helper methods for perform HTTP requests.

Constant Summary collapse

DEFAULT_HEADERS =

Default HTTP header to be used on the requests.

{
  'User-Agent' => 'NessusClient::Request - rubygems.org nessus_client',
  'Content-Type' => 'application/json'
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Request

Returns a new instance of Request.

Parameters:

  • params (Hash) (defaults to: {})

    the options to create a NessusClient::Request with.

Options Hash (params):

  • :uri (String) — default: 'https://localhost:8834/'

    Nessus server to connect with

  • :ssl_verify_peer (String) — default: true

    Whether should check valid SSL certificate



22
23
24
25
26
# File 'lib/nessus_client/request.rb', line 22

def initialize(params = {})
  params = { uri: nil }.merge(params)
  @ssl_verify_peer = params[:ssl_verify_peer] ? true : false
  @url = NessusClient::Request.uri_parse(params.fetch(:uri))
end

Instance Attribute Details

#urlString (readonly)

Returns The base url of the API.

Returns:

  • (String)

    The base url of the API.



11
12
13
# File 'lib/nessus_client/request.rb', line 11

def url
  @url
end

Class Method Details

.uri_parse(uri) ⇒ String

Parse a receiveid string against the URI stantard.

Parameters:

  • uri (String)

    A string to be validate URI.

Returns:

  • (String)

    A string uri.

Raises:

  • (URI::InvalidURIError)


71
72
73
74
75
76
# File 'lib/nessus_client/request.rb', line 71

def self.uri_parse(uri)
  url = URI.parse(uri)
  raise URI::InvalidURIError unless url.scheme

  url.to_s
end

Instance Method Details

#delete(opts = {}) ⇒ Hash, String

Perform a HTTP DELETE request.

Parameters:

  • opts (Hash) (defaults to: {})

    to use in the request.

Options Hash (opts):

  • path (String)

    The URI path to perform the request.

  • payload (String)

    The HTTP body to send.

  • query (String)

    The URI query to send.

Returns:

  • (Hash, String)

    The body of the resposnse if there is any.



64
65
66
# File 'lib/nessus_client/request.rb', line 64

def delete(opts = {})
  http_request(opts, :delete)
end

#get(opts = {}) ⇒ Hash, String

Perform a HTTP GET request.

Parameters:

  • opts (Hash) (defaults to: {})

    to use in the request.

Options Hash (opts):

  • path (String)

    The URI path to perform the request.

  • payload (String)

    The HTTP body to send.

  • query (String)

    The URI query to send.

Returns:

  • (Hash, String)

    The body of the resposnse if there is any.



34
35
36
# File 'lib/nessus_client/request.rb', line 34

def get(opts = {})
  http_request(opts, :get)
end

#post(opts = {}) ⇒ Hash, String

Perform a HTTP POST request.

Parameters:

  • opts (Hash) (defaults to: {})

    to use in the request.

Options Hash (opts):

  • path (String)

    The URI path to perform the request.

  • payload (String)

    The HTTP body to send.

  • query (String)

    The URI query to send.

Returns:

  • (Hash, String)

    The body of the resposnse if there is any.



44
45
46
# File 'lib/nessus_client/request.rb', line 44

def post(opts = {})
  http_request(opts, :post)
end

#put(opts = {}) ⇒ Hash, String

Perform a HTTP PUT request.

Parameters:

  • opts (Hash) (defaults to: {})

    to use in the request.

Options Hash (opts):

  • path (String)

    The URI path to perform the request.

  • payload (String)

    The HTTP body to send.

  • query (String)

    The URI query to send.

Returns:

  • (Hash, String)

    The body of the resposnse if there is any.



54
55
56
# File 'lib/nessus_client/request.rb', line 54

def put(opts = {})
  http_request(opts, :put)
end