<commit_before>class App < ActiveRecord::Base
  validates :name, :presence => true
  validates_attachment_content_type :logo, :content_type => /image/
  validates_attachment_presence :file

  has_attached_file :logo, :styles => {:medium => "300x300>", :thumb => "60x60#"}, :default_url => '/assets/no_logo_uploaded.png'
  has_attached_file :file

  has_many :app_ownerships
  has_many :owners, :through => :app_ownerships, :source => :user
  has_many :app_usages
  has_many :users, :through => :app_usages, :source => :user

  after_save :scan

  has_many :scan_results

  private

  def scan(force=false)
    # pass force if rescan
    return if !self.scan_results.empty? and !force
    # TODO limit when this scan occurs
    url = 'https://wwww.virustotal.com/vtapi/v2/file/scan'
    json = RestClient.post(url, :key => Settings.vtapi_key,
                          :file => File.new(self.file.path, 'rb'))
    res = JSON.parse(json)
    puts res
    if res['response_code'] == 1
      sr = self.scan_results.build
      sr.vtresource = res['resource']
      sr.vtscan_id = res['scan_id']
      sr.vtpermalink = res['permalink']
      sr.sha256 = res['sha256']
      sr.save
    end
  end
  handle_asynchronously :scan
end<commit_msg>fixed virustotal issue - was simply wwww instead of www<commit_after>class App < ActiveRecord::Base
  validates :name, :presence => true
  validates_attachment_content_type :logo, :content_type => /image/
  validates_attachment_presence :file

  has_attached_file :logo, :styles => {:medium => "300x300>", :thumb => "60x60#"}, :default_url => '/assets/no_logo_uploaded.png'
  has_attached_file :file

  has_many :app_ownerships
  has_many :owners, :through => :app_ownerships, :source => :user
  has_many :app_usages
  has_many :users, :through => :app_usages, :source => :user

  after_save :scan

  has_many :scan_results

  private

  def scan(force=false)
    # pass force if rescan
    return if !self.scan_results.empty? and !force
    # TODO limit when this scan occurs
    url = 'https://www.virustotal.com/vtapi/v2/file/scan'
    json = RestClient.post(url, :key => Settings.vtapi_key,
                          :file => File.new(self.file.path, 'rb'))
    res = JSON.parse(json)
    puts res
    if res['response_code'] == 1
      sr = self.scan_results.build
      sr.vtresource = res['resource']
      sr.vtscan_id = res['scan_id']
      sr.vtpermalink = res['permalink']
      sr.sha256 = res['sha256']
      sr.save
    end
  end
  handle_asynchronously :scan
end
{'fraction_non_alphanumeric': 0.12534818941504178, 'fraction_numerical': 0.01432550736171906, 'mean_word_length': 3.4182776801405974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '3910925', 'n_tokens_mistral': 902, 'n_tokens_neox': 855, 'n_words': 195}