<commit_before>require 'rest-client'
require 'tempfile'
require 'json'

class VtAPI
  # base URL of the VirusTotal Public API v2.0 
  BASE_URL = 'https://www.virustotal.com/vtapi/v2/'

  attr_reader :apikey

  def initialize(apikey)
    @apikey = apikey
  end

  def file_scan(data)
    # TODO: set filename or file path
    tmp = Tempfile.open('tmp')
    tmp.write data
    def tmp.content_type
      'application/octet-stream'
    end
    tmp.pos=0
    http_post('file/scan', file: tmp, multipart: true)
  end

  def file_rescan(resource)
    if resource.is_a? Array
      raise 'limit is up to 25 items' if resource.size > 25
      resource = resource.join(', ')
    end
    http_post('file/rescan', resource: resource)
  end

  def file_report(resource)
    if resource.is_a? Array
      raise 'limit is up to 4 items' if resource.size > 4
      resource = resource.join(', ')
    end
    http_post('file/report', resource: resource)
  end

  def url_scan(url)
    if url.is_a? Array
      raise 'limit is up to 4 items' if url.size > 4
      url = url.join("\n")
    end
    http_post('url/scan', url: url)
  end

  def url_report(url)
    if url.is_a? Array
      raise 'limit is up to 4 items' if url.size > 4
      url = url.join(", ")
    end
    http_post('url/report', resource: url)
  end

  def domain_report(domain)
    raise 'only one domain can be scanned at a time' if domain.is_a? Array
    http_get('domain/report', domain: domain)
  end

  def http_query(verb, path, params = { })
    uri = BASE_URL + path<commit_msg>Add support for IP address reports<commit_after>require 'rest-client'
require 'tempfile'
require 'json'

class VtAPI
  # base URL of the VirusTotal Public API v2.0 
  BASE_URL = 'https://www.virustotal.com/vtapi/v2/'

  attr_reader :apikey

  def initialize(apikey)
    @apikey = apikey
  end

  def file_scan(data)
    # TODO: set filename or file path
    tmp = Tempfile.open('tmp')
    tmp.write data
    def tmp.content_type
      'application/octet-stream'
    end
    tmp.pos=0
    http_post('file/scan', file: tmp, multipart: true)
  end

  def file_rescan(resource)
    if resource.is_a? Array
      raise 'limit is up to 25 items' if resource.size > 25
      resource = resource.join(', ')
    end
    http_post('file/rescan', resource: resource)
  end

  def file_report(resource)
    if resource.is_a? Array
      raise 'limit is up to 4 items' if resource.size > 4
      resource = resource.join(', ')
    end
    http_post('file/report', resource: resource)
  end

  def url_scan(url)
    if url.is_a? Array
      raise 'limit is up to 4 items' if url.size > 4
      url = url.join("\n")
    end
    http_post('url/scan', url: url)
  end

  def url_report(url)
    if url.is_a? Array
      raise 'limit is up to 4 items' if url.size > 4
      url = url.join(", ")
    end
    http_post('url/report', resource: url)
  end

  def ip_report(ip)
    raise 'only one IP address can be scanned at a time' if ip.is_a? Array
    http_get('ip-address/report', ip: ip)
  end

  def domain_report(domain)
    raise 'only one domain can be scanned at a time' if domain.is_a? Array
    http_get('domain/report', domain: domain)
  end

  def http_query(verb, path, params = { })
    uri = BASE_URL + path
{'fraction_non_alphanumeric': 0.10614008022215365, 'fraction_numerical': 0.008639308855291577, 'mean_word_length': 2.7610208816705337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1019095', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1098, 'n_words': 348}