Class: VtApi::Versions::ApiV2

Inherits:
ApiVersion show all
Defined in:
lib/vt_api/internal/versions/api_v2.rb

Overview

VirusTotal Public API 2.0 singleton interface. Describes all available API methods (endpoints).

Constant Summary collapse

BASE_URI =

Root URI for all endpoints.

'https://virustotal.com/vtapi/v2/'
ENDPOINTS =

VirusTotal Public API v2.0 interface description.

{
	'file.report':       Endpoint.new('file/report', :get,
	                                  apikey:   true,
	                                  resource: true),
	'file.scan':         Endpoint.new('file/scan', :post,
	                                  apikey: true,
	                                  file:   true),
	'file.rescan':       Endpoint.new('file/rescan', :post,
	                                  apikey:   true,
	                                  resource: true),
	'url.report':        Endpoint.new('url/report', :get,
	                                  apikey:        true,
	                                  resource:      true,
	                                  schedule_scan: false),
	'url.scan':          Endpoint.new('url/scan', :post,
	                                  apikey: true,
	                                  url:    true),
	'domain.report':     Endpoint.new('domain/report', :get,
	                                  apikey: true,
	                                  domain: true),
	'ip-address.report': Endpoint.new('ip-address/report', :get,
	                                  apikey: true,
	                                  domain: true),
	'comments.get':      Endpoint.new('comments/get', :get,
	                                  apikey:   true,
	                                  resource: true,
	                                  before:   false),
	'comments.put':      Endpoint.new('comments/put', :post,
	                                  apikey:   true,
	                                  resource: true,
	                                  comment:  true)
}.freeze
ERRORS =

List of possible HTTP error codes with descriptions

{
	204 => 'Request rate limit exceeded.',
	400 => 'Invalid arguments.',
	403 => 'Access denied.',
	404 => 'Endpoint not found.'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceVtApi::Versions::ApiV2

Get interface instance.



60
61
62
# File 'lib/vt_api/internal/versions/api_v2.rb', line 60

def instance
	@instance ||= new
end

Instance Method Details

#base_urlString

API base URL.

Returns:

  • (String)


100
101
102
# File 'lib/vt_api/internal/versions/api_v2.rb', line 100

def base_url
	BASE_URI
end

#endpoint(method) ⇒ VtApi::Endpoint

Get API method endpoint interface.

Parameters:

  • method (String)

    API method name to be called.

Returns:



69
70
71
# File 'lib/vt_api/internal/versions/api_v2.rb', line 69

def endpoint(method)
	ENDPOINTS[method.to_sym] unless ENDPOINTS[method.to_sym].nil?
end

#endpoint?(method) ⇒ Boolean

Check whether given method is defined in interface.

Parameters:

  • method (String)

    Method name.

Returns:

  • (Boolean)


77
78
79
# File 'lib/vt_api/internal/versions/api_v2.rb', line 77

def endpoint?(method)
	!endpoint(method).nil?
end

#error(http_code) ⇒ String

Get API HTTP-code description.

Parameters:

  • http_code (Integer)

Returns:

  • (String)

    Error description.



85
86
87
# File 'lib/vt_api/internal/versions/api_v2.rb', line 85

def error(http_code)
	ERRORS[http_code] unless ERRORS[http_code].nil?
end

#error?(http_code) ⇒ Boolean

Check whether API HTTP-code means error.

Parameters:

  • http_code (Integer)

Returns:

  • (Boolean)

    Error description.



93
94
95
# File 'lib/vt_api/internal/versions/api_v2.rb', line 93

def error?(http_code)
	!error(http_code).nil?
end

#versionString

API interface name/version.

Returns:

  • (String)


107
108
109
# File 'lib/vt_api/internal/versions/api_v2.rb', line 107

def version
	'VTAPI-2.0'
end