Class: VtApi::ApiV2::URL

Inherits:
Object
  • Object
show all
Defined in:
lib/vt_api/api/v2/url.rb

Overview

Class that represents URL scan report.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_resp) ⇒ URL

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:



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

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

Instance Attribute Details

#filescan_idObject (readonly)

Returns the value of attribute filescan_id.



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

def filescan_id
  @filescan_id
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Returns the value of attribute permalink.



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

def permalink
  @permalink
end

#scan_dateObject (readonly)

Returns the value of attribute scan_date.



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

def scan_date
  @scan_date
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.from_response(api_resp) ⇒ Object

Shorthand for #initialize.

See Also:



38
39
40
41
42
43
44
45
46
# File 'lib/vt_api/api/v2/url.rb', line 38

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:, scan: false) ⇒ URL

Returns URL report object is present, nil otherwise.

Parameters:

  • resource (String)
  • scan (Boolean) (defaults to: false)

    Schedule URL scan if it is not present in system.

Returns:

  • (URL)

    URL report object is present, nil otherwise.

See Also:



16
17
18
19
20
21
22
23
# File 'lib/vt_api/api/v2/url.rb', line 16

def report(resource:, scan: false)
	resp = ApiV2.provider.request 'url.report',
	                              apikey:        VtApi.options.token,
	                              resource:      resource,
	                              schedule_scan: (scan ? 1 : 0)
	pp resp
	from_response resp
end

.schedule_scan(url:) ⇒ String

Returns Scheduled scan ID.

Parameters:

  • url (String)

Returns:

  • (String)

    Scheduled scan ID.

See Also:



29
30
31
32
# File 'lib/vt_api/api/v2/url.rb', line 29

def schedule_scan(url:)
	resp = ApiV2.provider.request 'url.report', apikey: VtApi.options.token, url: url
	resp.scan_id
end