Class: VtAPI::Response
- Inherits:
-
Object
- Object
- VtAPI::Response
- Defined in:
- lib/vtapi/response.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(json) ⇒ Response
constructor
A new instance of Response.
- #keys ⇒ Object
- #positive_brands ⇒ Object
- #positive_threats ⇒ Object
- #scan_results ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(json) ⇒ Response
Returns a new instance of Response.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vtapi/response.rb', line 15 def initialize(json) @json = json @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 |
Class Method Details
Instance Method Details
#[](key) ⇒ Object
43 44 45 |
# File 'lib/vtapi/response.rb', line 43 def [](key) @json.fetch(key.to_s) # raise KeyError when key doesn't exist. end |
#keys ⇒ Object
27 28 29 |
# File 'lib/vtapi/response.rb', line 27 def keys @json.keys end |
#positive_brands ⇒ Object
35 36 37 |
# File 'lib/vtapi/response.rb', line 35 def positive_brands @json.fetch('scans', {}).select{|k,v| v['detected'] }.keys end |
#positive_threats ⇒ Object
31 32 33 |
# File 'lib/vtapi/response.rb', line 31 def positive_threats Hash[@json.fetch('scans', {}).select{|k,v| v['detected'] }.map{|k,v| [k, v['result']] }] end |
#scan_results ⇒ Object
39 40 41 |
# File 'lib/vtapi/response.rb', line 39 def scan_results Hash[@json.fetch('scans', {}).map{|k,v| [k, v['result']] }] end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/vtapi/response.rb', line 47 def to_s @json.to_json end |