Class: VirustotalAPI::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/virustotal_api/base.rb

Overview

The base class implementing the raw calls to Virustotal API V3.

Direct Known Subclasses

Analysis, Domain, File, Group, IP, URL, User

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
# File 'lib/virustotal_api/base.rb', line 14

def initialize(report)
  @report     = report
  @report_url = report&.dig('data', 'links', 'self')
  @id         = report&.dig('data', 'id')
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/virustotal_api/base.rb', line 12

def id
  @id
end

#reportObject (readonly)

Returns the value of attribute report.



12
13
14
# File 'lib/virustotal_api/base.rb', line 12

def report
  @report
end

#report_urlObject (readonly)

Returns the value of attribute report_url.



12
13
14
# File 'lib/virustotal_api/base.rb', line 12

def report_url
  @report_url
end

Class Method Details

.api_uriString

Returns string of API URI class method.

Returns:

  • (String)

    string of API URI class method



21
22
23
# File 'lib/virustotal_api/base.rb', line 21

def self.api_uri
  VirustotalAPI::URI
end

.perform(path, api_key, method = :get, options = {}) ⇒ Object



25
26
27
# File 'lib/virustotal_api/base.rb', line 25

def self.perform(path, api_key, method = :get, options = {})
  base_perform(api_uri + path, api_key, method, options)
end

.perform_absolute(url, api_key, method = :get, options = {}) ⇒ Object



29
30
31
# File 'lib/virustotal_api/base.rb', line 29

def self.perform_absolute(url, api_key, method = :get, options = {})
  base_perform(url, api_key, method, options)
end

.url_identifier(url) ⇒ Object

Generate a URL identifier.



74
75
76
# File 'lib/virustotal_api/base.rb', line 74

def self.url_identifier(url)
  Base64.urlsafe_encode64(url).strip.gsub('=', '')
end

Instance Method Details

#api_uriString

Returns string of API URI instance method.

Returns:

  • (String)

    string of API URI instance method



63
64
65
# File 'lib/virustotal_api/base.rb', line 63

def api_uri
  self.class.api_uri
end

#exists?Boolean

Returns if report for resource exists.

Returns:

  • (Boolean)

    if report for resource exists



68
69
70
# File 'lib/virustotal_api/base.rb', line 68

def exists?
  !report.empty?
end