Class: VtApi::ApiV2::File

Inherits:
Object
  • Object
show all
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

See Also:

%w[scan_id resource_id md5 sha1 sha256].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_resp) ⇒ File

Note:

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.

Parameters:

  • api_resp (OpenStruct)

See Also:



101
102
103
104
105
# File 'lib/vt_api/api/v2/file.rb', line 101

def initialize(api_resp)
	load_ids! api_resp
	load_meta! api_resp
	load_scans! api_resp
end

Instance Attribute Details

Returns the value of attribute permalink.



90
91
92
# File 'lib/vt_api/api/v2/file.rb', line 90

def permalink
  @permalink
end

#scan_countObject (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_dateObject (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

#scansObject (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_countObject (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.

See Also:



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.

Parameters:

  • resource (String)

Returns:

  • (File)

    File report if present, nil otherwise.

See Also:



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.options.token, resource: resource
	from_response resp
end

.schedule_rescan(resource:) ⇒ String

Returns Scan ID.

Parameters:

  • resource (String)

Returns:

  • (String)

    Scan ID.

See Also:



48
49
50
51
# File 'lib/vt_api/api/v2/file.rb', line 48

def schedule_rescan(resource:)
	resp = ApiV2.provider.request 'file.rescan', apikey: VtApi.options.token, resource: resource
	resp.scan_id
end

.schedule_scan(file:) ⇒ String

Returns Scan ID.

Parameters:

  • file (String|Pathname|UploadIO)

Returns:

  • (String)

    Scan ID.

See Also:



57
58
59
60
61
62
# File 'lib/vt_api/api/v2/file.rb', line 57

def schedule_scan(file:)
	file = file_to_io file if file.is_a?(String) || file.is_a?(Pathname)

	resp = ApiV2.provider.request 'file.scan', apikey: VtApi.options.token, file: file
	resp.scan_id
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.

Parameters:

  • type (Symbol|String) (defaults to: :id)

Returns:

  • (String)

    ID string of specified type.

Raises:

  • (ArgumentError)

See Also:



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_levelFixnum

Returns:

  • (Fixnum)


108
109
110
# File 'lib/vt_api/api/v2/file.rb', line 108

def threat_level
	@trigger_count.to_f / @scan_count
end