class Intel

Constants

URL_INTEL_DOMAIN
URL_INTEL_DOWNLOAD_REPORT
URL_INTEL_IP
URL_INTEL_SEARCH_ADVANCED

Public Instance Methods

domain_info(api_key, domain, filters = nil) click to toggle source
# File lib/deepviz/intel.rb, line 43
def domain_info(api_key, domain, filters = nil)
  if api_key.nil? or api_key == ''
    return Result.new(status=INPUT_ERROR, msg='API key cannot be null or empty String')
  end


  if domain.nil? or domain == ''
    msg = 'Parameters missing or invalid. You must specify an domain.'
    return Result.new(status=INPUT_ERROR, msg=msg)
  end

  if filters != nil and !filters.kind_of?(Array)
    msg = 'You must provide one or more output filters in a list'
    return Result.new(status=INPUT_ERROR, msg=msg)
  end

  if filters != nil
    body = {
        :output_filters => filters,
        :api_key => api_key,
        :domain => domain,
    }
  else
    body = {
        :api_key => api_key,
        :domain => domain,
    }
  end

  return do_post(body, URL_INTEL_DOMAIN)
end
ip_info(api_key, ip, filters=nil) click to toggle source
# File lib/deepviz/intel.rb, line 11
def ip_info(api_key, ip, filters=nil)
  if api_key == nil or api_key == ''
    return Result.new(status=INPUT_ERROR, msg='API key cannot be null or empty String')
  end

  if ip.nil? or ip == ''
    msg = 'Parameters missing or invalid. You must specify an IP.'
    return Result.new(status=INPUT_ERROR, msg=msg)
  end

  if filters != nil and !filters.kind_of?(Array)
    msg = 'You must provide one or more output filters in a list'
    return Result.new(status=INPUT_ERROR, msg=msg)
  end

  if filters != nil
    body = {
      :output_filters => filters,
      :api_key => api_key,
      :ip => ip,
    }
  else
    body = {
        :api_key => api_key,
        :ip => ip,
    }
  end

  return do_post(body, URL_INTEL_IP)
end
sample_info(api_key, md5, filters) click to toggle source
# File lib/deepviz/intel.rb, line 228
def sample_info(api_key, md5, filters)
  if api_key == nil or api_key == ''
    return Result.new(status=INPUT_ERROR, msg='API key cannot be null or empty String')
  end

  if md5 == nil or md5 == ''
    return Result.new(status=INPUT_ERROR, msg='MD5 cannot be null or empty String')
  end

  if filters != nil
    if 0 < filters.length > 10
      return Result.new(status=INPUT_ERROR, msg='Parameter \'output_filters\' takes at least 1 value and at most 10 values (%s given)' % [filters.length])
    end

    body = {:api_key => api_key, :md5 => md5, :output_filters => filters}
  else
    return Result.new(status=INPUT_ERROR, msg='Output filters cannot be null or empty')
  end

  return do_post(body, URL_INTEL_DOWNLOAD_REPORT)
end
sample_result(api_key, md5) click to toggle source
# File lib/deepviz/intel.rb, line 223
def sample_result(api_key, md5)
  return sample_info(api_key, md5, ['classification'])
end

Private Instance Methods

do_post(body, api_uri) click to toggle source
# File lib/deepviz/intel.rb, line 203
def do_post(body, api_uri)
  begin
    response = Unirest.post(api_uri,
                            headers:{ 'Content-Type' => 'application/json' },
                            parameters:body.to_json)
  rescue Exception
    return Result.new(status=NETWORK_ERROR, msg='%s - Error while connecting to Deepviz: %s' % [response.code, response.body['errmsg']])
  end

  if response.code == 200
    return Result.new(status=SUCCESS, msg=response.body['data'])
  else
    if response.code >= 500
      return Result.new(status=SERVER_ERROR, msg='%s - Error while connecting to Deepviz: %s' % [response.code, response.body['errmsg']])
    else
      return Result.new(status=CLIENT_ERROR, msg='%s - Error while connecting to Deepviz: %s' % [response.code, response.body['errmsg']])
    end
  end
end