Class: VtApi::ApiV2::File
- Inherits:
-
Object
- Object
- VtApi::ApiV2::File
- Defined in:
- lib/vt_api/api/v2/file.rb
Overview
Class that represents VT Public API 2.0 for files.
Defined Under Namespace
Classes: AvResult
Constant Summary collapse
- ID_TYPES =
Existing ID types
%w[scan_id resource_id md5 sha1 sha256].freeze
Instance Attribute Summary collapse
-
#permalink ⇒ Object
readonly
Returns the value of attribute permalink.
-
#scan_count ⇒ Object
readonly
Returns the value of attribute scan_count.
-
#scan_date ⇒ Object
readonly
Returns the value of attribute scan_date.
-
#scans ⇒ Object
readonly
Returns the value of attribute scans.
-
#trigger_count ⇒ Object
readonly
Returns the value of attribute trigger_count.
Class Method Summary collapse
-
.from_response(api_resp) ⇒ Object
Shorthand for #initialize.
-
.report(resource:) ⇒ File
File report if present,
nil
otherwise. -
.schedule_rescan(resource:) ⇒ String
Scan ID.
-
.schedule_scan(file:) ⇒ String
Scan ID.
Instance Method Summary collapse
-
#id(type = :id) ⇒ String
Get file identifier.
-
#initialize(api_resp) ⇒ File
constructor
Initializes new object from VT API response.
- #threat_level ⇒ Fixnum
Constructor Details
#initialize(api_resp) ⇒ File
Direct creation of object cas cause errors since it doesn’t contain any validity checks. Use predefined API method bindings instead.
Initializes new object from VT API response.
101 102 103 104 105 |
# File 'lib/vt_api/api/v2/file.rb', line 101 def initialize(api_resp) load_ids! api_resp api_resp load_scans! api_resp end |
Instance Attribute Details
#permalink ⇒ Object (readonly)
Returns the value of attribute permalink.
90 91 92 |
# File 'lib/vt_api/api/v2/file.rb', line 90 def permalink @permalink end |
#scan_count ⇒ Object (readonly)
Returns the value of attribute scan_count.
90 91 92 |
# File 'lib/vt_api/api/v2/file.rb', line 90 def scan_count @scan_count end |
#scan_date ⇒ Object (readonly)
Returns the value of attribute scan_date.
90 91 92 |
# File 'lib/vt_api/api/v2/file.rb', line 90 def scan_date @scan_date end |
#scans ⇒ Object (readonly)
Returns the value of attribute scans.
90 91 92 |
# File 'lib/vt_api/api/v2/file.rb', line 90 def scans @scans end |
#trigger_count ⇒ Object (readonly)
Returns the value of attribute trigger_count.
90 91 92 |
# File 'lib/vt_api/api/v2/file.rb', line 90 def trigger_count @trigger_count end |
Class Method Details
.from_response(api_resp) ⇒ Object
Shorthand for #initialize.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vt_api/api/v2/file.rb', line 79 def self.from_response(api_resp) # noinspection RubyResolve if api_resp.response_code.nil? || (api_resp.response_code < 1) nil else report = new api_resp report end end |
.report(resource:) ⇒ File
Returns File report if present, nil
otherwise.
39 40 41 42 |
# File 'lib/vt_api/api/v2/file.rb', line 39 def report(resource:) resp = ApiV2.provider.request 'file.report', apikey: VtApi..token, resource: resource from_response resp end |
Instance Method Details
#id(type = :id) ⇒ String
Get file identifier. Since VT API offers many ways to identify the file, you can supply ID type to get specific file.
119 120 121 122 123 |
# File 'lib/vt_api/api/v2/file.rb', line 119 def id(type = :id) raise ArgumentError, "There is no such id type (#{type}) in VT API 2.0" unless ID_TYPES.include? type.to_sym @ids[type.to_sym] end |
#threat_level ⇒ Fixnum
108 109 110 |
# File 'lib/vt_api/api/v2/file.rb', line 108 def threat_level @trigger_count.to_f / @scan_count end |