Class: VtAPI::Response
- Inherits:
-
Object
- Object
- VtAPI::Response
- Defined in:
- lib/vtapi/response.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(response_body) ⇒ Response
constructor
A new instance of Response.
- #keys ⇒ Object
- #positive_brands ⇒ Object
- #positive_threats ⇒ Object
- #scan_results ⇒ Object
Constructor Details
#initialize(response_body) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/vtapi/response.rb', line 6 def initialize(response_body) @json = JSON.parse(response_body) @json.keys.each do |key| Response.class_eval { define_method key.to_s do |*args| @json[key] end } end @json['scan_date'] = Time.parse(@json['scan_date'] + "UTC") if @json.has_key? 'scan_date' end |
Instance Method Details
#[](key) ⇒ Object
34 35 36 |
# File 'lib/vtapi/response.rb', line 34 def [](key) @json.fetch(key.to_s) # raise KeyError when key doesn't exist. end |
#keys ⇒ Object
18 19 20 |
# File 'lib/vtapi/response.rb', line 18 def keys @json.keys end |
#positive_brands ⇒ Object
26 27 28 |
# File 'lib/vtapi/response.rb', line 26 def positive_brands @json.fetch('scans', {}).select{|k,v| v['detected'] }.keys end |
#positive_threats ⇒ Object
22 23 24 |
# File 'lib/vtapi/response.rb', line 22 def positive_threats Hash[@json.fetch('scans', {}).select{|k,v| v['detected'] }.map{|k,v| [k, v['result']] }] end |
#scan_results ⇒ Object
30 31 32 |
# File 'lib/vtapi/response.rb', line 30 def scan_results Hash[@json.fetch('scans', {}).map{|k,v| [k, v['result']] }] end |