Class: VtAPI
- Inherits:
-
Object
- Object
- VtAPI
- Defined in:
- lib/vtapi/api.rb,
lib/vtapi/response.rb,
lib/vtapi/exception.rb
Defined Under Namespace
Classes: AuthError, ExceedAPILimit, Response
Constant Summary collapse
- BASE_URL =
base URL of the VirusTotal Public API v2.0
'https://www.virustotal.com/vtapi/v2/'
Instance Attribute Summary collapse
-
#apikey ⇒ Object
readonly
Returns the value of attribute apikey.
Instance Method Summary collapse
- #file_report(resource) ⇒ Object
- #file_rescan(resource) ⇒ Object
- #file_scan(data) ⇒ Object
- #http_post(path, params = {}) ⇒ Object
-
#initialize(apikey) ⇒ VtAPI
constructor
A new instance of VtAPI.
Constructor Details
#initialize(apikey) ⇒ VtAPI
Returns a new instance of VtAPI.
11 12 13 |
# File 'lib/vtapi/api.rb', line 11 def initialize(apikey) @apikey = apikey end |
Instance Attribute Details
#apikey ⇒ Object (readonly)
Returns the value of attribute apikey.
9 10 11 |
# File 'lib/vtapi/api.rb', line 9 def apikey @apikey end |
Instance Method Details
#file_report(resource) ⇒ Object
30 31 32 |
# File 'lib/vtapi/api.rb', line 30 def file_report(resource) http_post('file/report', resource: resource) end |
#file_rescan(resource) ⇒ Object
26 27 28 |
# File 'lib/vtapi/api.rb', line 26 def file_rescan(resource) http_post('file/rescan', resource: resource) end |
#file_scan(data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vtapi/api.rb', line 15 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 |
#http_post(path, params = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vtapi/api.rb', line 35 def http_post(path, params = {}) uri = BASE_URL + path params['apikey'] = @apikey resp = RestClient.post(uri, params) do |resp, req, result, &block| case resp.code when 204 raise ExceedAPILimit, "you exceed the public API request rate limit: key[#{@apikey}]" when 403 raise AuthError, "you do not have the required priviledges: key[#{@apikey}]" else resp.return!(req, result, &block) end end Response.new(resp.body) end |