Class: Hrw::API
- Inherits:
-
Object
- Object
- Hrw::API
- Defined in:
- lib/hrw/api.rb
Overview
Used to interact with Horus server
Defined Under Namespace
Classes: HTTPCodeError
Instance Method Summary collapse
-
#initialize(url) ⇒ API
constructor
Class constructor.
-
#retrieve(hash) ⇒ Hash
Used to retrieve scan results.
-
#submit(dependencies, pkg_manager) ⇒ String
Submit dependencies to server.
Constructor Details
#initialize(url) ⇒ API
Class constructor
24 25 26 27 |
# File 'lib/hrw/api.rb', line 24 def initialize(url) @submit_url = url.chomp('/') + '/dependency' @retrieve_url = url.chomp('/') + '/ancestry' end |
Instance Method Details
#retrieve(hash) ⇒ Hash
Used to retrieve scan results
53 54 55 56 57 58 |
# File 'lib/hrw/api.rb', line 53 def retrieve(hash) res = HTTP.get(@retrieve_url + "/#{hash}") raise HTTPCodeError, "#{res.code}: #{res.body}" if res.code != 200 res.parse end |
#submit(dependencies, pkg_manager) ⇒ String
Submit dependencies to server
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hrw/api.rb', line 34 def submit(dependencies, pkg_manager) body = { hash: _calc_hash(dependencies), pkg_manager: { name: pkg_manager }, packages: dependencies } res = HTTP.post(@submit_url, json: body) raise HTTPCodeError, "#{res.code}: #{res.body}" if res.code != 200 body[:hash] end |