4c2f190bed
Remove HTTPParty from depends, gonna use the NET/HTTP library from the STDLib, even though it needs more coding to make work. Replace HTTPParty code with NET/HTTP code. Move opswat_client and virus_total_client into their own directories for organization
48 lines
1.4 KiB
Ruby
48 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'net/http'
|
|
require 'uri'
|
|
require 'json'
|
|
require 'yaml'
|
|
|
|
# main class for communication with the VirusTotal API v3
|
|
class VirusTotalClient
|
|
API_KEY = YAML.load_file(File.join(__dir__, '../../config/api_keys.yml'))['virus_total']
|
|
BASE_URL = 'https://www.virustotal.com/api/v3/'
|
|
|
|
# Method to scan URLs
|
|
def self.scan_url(url)
|
|
uri = URI("#{BASE_URL}urls")
|
|
request = Net::HTTP::Post.new(uri)
|
|
request['x-apikey'] = API_KEY
|
|
request['Content-Type'] = 'application/json'
|
|
request.body = { url: }.to_json
|
|
|
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
|
http.request(request)
|
|
end
|
|
|
|
# TODO: Implement proper response handling
|
|
JSON.parse(response.body)
|
|
end
|
|
|
|
# method to upload files to scan
|
|
def self.scan_file(file_path)
|
|
uri = URI("#{BASE_URL}files")
|
|
request = Net::HTTP::Post.new(uri)
|
|
request['x-apikey'] = API_KEY
|
|
request['accept'] = 'application/json'
|
|
request['Content-Type'] = 'multipart/form-data'
|
|
|
|
form_data = [['file', File.open(file_path)]]
|
|
request.set_form form_data, 'multipart/form-data'
|
|
|
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
|
http.request(request)
|
|
end
|
|
|
|
# TODO: Implement proper response handling
|
|
JSON.parse(response.body) # Simplified example; adjust based on actual needs
|
|
end
|
|
end
|