class VirustotalAPI::Base
The base class implementing the raw calls to Virustotal API V3.
Attributes
id[R]
report[R]
report_url[R]
Public Class Methods
api_uri()
click to toggle source
@return [String] string of API URI class method
# File lib/virustotal_api/base.rb, line 21 def self.api_uri VirustotalAPI::URI end
new(report)
click to toggle source
# 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
perform(path, api_key, method = :get, options = {})
click to toggle source
# 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 = {})
click to toggle source
# 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)
click to toggle source
Generate a URL
identifier. @see developers.virustotal.com/v3.0/reference#url
# File lib/virustotal_api/base.rb, line 74 def self.url_identifier(url) Base64.urlsafe_encode64(url).strip.gsub('=', '') end
Private Class Methods
base_perform(url, api_key, method = :get, options = {})
click to toggle source
The actual method performing a call to Virustotal
@param [String] url The url of the API @param [String] api_key The key for virustotal @param [String] method The HTTP method to use @param [Hash] options Options to pass as payload @return [VirustotalAPI::Domain] Report Search Result
# File lib/virustotal_api/base.rb, line 40 def self.base_perform(url, api_key, method = :get, options = {}) response = RestClient::Request.execute( method: method, url: url, headers: { 'x-apikey': api_key }, payload: options ) JSON.parse(response.body) rescue RestClient::NotFound, RestClient::BadRequest {} rescue RestClient::Unauthorized # Raise a custom exception not to expose the underlying # HTTP client. raise VirustotalAPI::Unauthorized rescue RestClient::TooManyRequests # Raise a custom exception not to expose the underlying # HTTP client. raise VirustotalAPI::RateLimitError end
Public Instance Methods
api_uri()
click to toggle source
@return [String] string of API URI instance method
# File lib/virustotal_api/base.rb, line 63 def api_uri self.class.api_uri end
exists?()
click to toggle source
@return [Boolean] if report for resource exists
# File lib/virustotal_api/base.rb, line 68 def exists? !report.empty? end