Class: EUVD::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/euvd/client.rb

Overview

Client for the EUVD API.

All endpoints are GET-only and require no authentication. JSON responses are returned as rich Sawyer::Resource objects (or Array of them), so you can access fields as methods instead of hash keys.

Constant Summary collapse

BASE_URL =
'https://euvdservices.enisa.europa.eu/api'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

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

Options Hash (options):

  • :base_url (String)

    API base URL (default: EUVD::Client::BASE_URL)



34
35
36
37
# File 'lib/euvd/client.rb', line 34

def initialize(options = {})
  @base_url = options[:base_url] || BASE_URL
  @agent = build_agent
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



30
31
32
# File 'lib/euvd/client.rb', line 30

def agent
  @agent
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



30
31
32
# File 'lib/euvd/client.rb', line 30

def base_url
  @base_url
end

Instance Method Details

#downloadsEUVD::API::Downloads



62
63
64
# File 'lib/euvd/client.rb', line 62

def downloads
  API::Downloads.new(self)
end

#get(path, params = {}) ⇒ Sawyer::Resource, ...

Make a GET request and return parsed response data.

Parameters:

  • path (String)

    API path (e.g. 'lastvulnerabilities')

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

    Query parameters

Returns:

  • (Sawyer::Resource, Array, String)

    parsed data



44
45
46
47
48
49
# File 'lib/euvd/client.rb', line 44

def get(path, params = {})
  response = @agent.call(:get, path, nil, query: params)
  response = handle_status(response)
  validate_content_type!(response)
  response.data
end

#inspectObject



76
77
78
79
80
81
# File 'lib/euvd/client.rb', line 76

def inspect
  format('#<%<class_name>s:0x%<object_id>x %<url>s>',
         class_name: self.class,
         object_id: object_id * 2,
         url: @base_url)
end

#metaEUVD::API::Meta

Returns:



67
68
69
# File 'lib/euvd/client.rb', line 67

def meta
  API::Meta.new(self)
end

#observationsEUVD::API::Observations



72
73
74
# File 'lib/euvd/client.rb', line 72

def observations
  API::Observations.new(self)
end

#recordsEUVD::API::Records

Returns:



57
58
59
# File 'lib/euvd/client.rb', line 57

def records
  API::Records.new(self)
end

#vulnerabilitiesEUVD::API::Vulnerabilities



52
53
54
# File 'lib/euvd/client.rb', line 52

def vulnerabilities
  API::Vulnerabilities.new(self)
end