virustotal_api 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef4844e6f5a7e7be0cf7ed1aa7c7f25027bc5522
4
- data.tar.gz: 34c4dcb450256151376eb1486ca2b9fed3a9a3be
3
+ metadata.gz: 08639ee03219b15575d468fd157eda539bc3897e
4
+ data.tar.gz: 2c281969e78d7fbcf5d665b392ab16bf11c7abc8
5
5
  SHA512:
6
- metadata.gz: 2bb1845d91af6c8ed7fef6055ec3514aa86427d6e751877b5c3ac4630430b17beb1dc9138c8a5d3d71c33ef503a0da056f558fbe97605f0fd621cb09d585ab0d
7
- data.tar.gz: 2b73096b9aefc1aee739fb1bfb243f508a9e5b79118352dc34800c959ce1bb4ada3db7cfa2a8adccc834f65676c042ea4dfb1e5245adf480016d7212819e935c
6
+ metadata.gz: 63fb4449337880642ae44ce0c1fa483835fa21c7a8f5a38e456aae569322ab26b1e9f7a22362e9b1bef65503a4f652b5154594e2be01c947003d2dc441eefdfc
7
+ data.tar.gz: 365ba31b29a47e37f34565c97ce45a08105865ffd531bc5bfabfa305ab89b297b1aa9a465515d79f3fb96a2052e7e69e895d625b4ddadbae53439aa1399ea613
data/.travis.yml CHANGED
@@ -1,4 +1,8 @@
1
+ ---
1
2
  sudo: false
3
+ branches:
4
+ except:
5
+ - gh-pages
2
6
  cache: bundler
3
7
  language: ruby
4
8
  rvm:
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # VirusTotal API Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ * Check if the respone is 204 [#2](https://github.com/pwelch/virustotal_api/pull/2)
6
+ * Check if the respone is 204 (No Content) and raise an exception. [@postmodern](https://github.com/postmodern)
7
+
8
+ ## 0.1.0
9
+
10
+ * First Release
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Ruby Gem for [VirusTotal](https://www.virustotal.com) [V2 API](https://www.virustotal.com/en/documentation/public-api/)
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/virustotal_api.svg)](http://badge.fury.io/rb/virustotal_api)
5
6
  [![Build Status](https://secure.travis-ci.org/pwelch/virustotal_api.svg)](http://travis-ci.org/pwelch/virustotal_api)
6
7
 
7
8
  ## Installation
@@ -22,6 +23,10 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
26
+ VirusTotal only allows 4 queries per minute for their Public API. https://www.virustotal.com/en/faq/
27
+
28
+ You will need a Private API Key if you require more queries per minute.
29
+
25
30
  ### File Report
26
31
 
27
32
  ```ruby
@@ -1,3 +1,4 @@
1
+ require 'virustotal_api/exceptions'
1
2
  require 'rest-client'
2
3
  require 'json'
3
4
 
@@ -8,6 +9,16 @@ module VirustotalAPI
8
9
  VirustotalAPI::URI
9
10
  end
10
11
 
12
+ # @param [RestClient::Response] response
13
+ # @return [Hash] the parsed JSON.
14
+ def self.parse(response)
15
+ if response.code == 204
16
+ fail(RateLimitError, 'maximum number of 4 requests per minute reached')
17
+ end
18
+
19
+ JSON.parse(response.body)
20
+ end
21
+
11
22
  # @return [String] string of API URI instance method
12
23
  def api_uri
13
24
  self.class.api_uri
@@ -17,7 +17,7 @@ module VirustotalAPI
17
17
  api_uri + '/domain/report',
18
18
  { :params => params(domain, api_key) }
19
19
  )
20
- report = JSON.parse(response.body)
20
+ report = parse(response)
21
21
 
22
22
  new(report)
23
23
  end
@@ -0,0 +1,4 @@
1
+ module VirustotalAPI
2
+ class RateLimitError < RuntimeError
3
+ end
4
+ end
@@ -18,7 +18,7 @@ module VirustotalAPI
18
18
  api_uri + '/file/report',
19
19
  params(resource, api_key)
20
20
  )
21
- report = JSON.parse(response.body)
21
+ report = parse(response)
22
22
 
23
23
  new(report)
24
24
  end
@@ -17,7 +17,7 @@ module VirustotalAPI
17
17
  api_uri + '/ip-address/report',
18
18
  { :params => params(ip, api_key) }
19
19
  )
20
- report = JSON.parse(response.body)
20
+ report = parse(response)
21
21
 
22
22
  new(report)
23
23
  end
@@ -19,7 +19,7 @@ module VirustotalAPI
19
19
  api_uri + '/url/report',
20
20
  params(resource, api_key)
21
21
  )
22
- report = JSON.parse(response.body)
22
+ report = parse(response)
23
23
 
24
24
  new(report)
25
25
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module VirustotalAPI
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
data/test/base_test.rb CHANGED
@@ -13,7 +13,7 @@ class VirustotalAPIBaseTest < Minitest::Test
13
13
  end
14
14
 
15
15
  # Instance Method
16
- def test_api_uri
16
+ def test_api_uri_instance_method
17
17
  base_uri = 'https://www.virustotal.com/vtapi/v2'
18
18
  vt_base = VirustotalAPI::Base.new
19
19
 
@@ -22,13 +22,31 @@ class VirustotalAPIBaseTest < Minitest::Test
22
22
  end
23
23
 
24
24
  # Class Method
25
- def test_api_uri
25
+ def test_api_uri_class_method
26
26
  base_uri = 'https://www.virustotal.com/vtapi/v2'
27
27
 
28
28
  assert VirustotalAPI::Base.api_uri.is_a?(String)
29
29
  assert VirustotalAPI::Base.api_uri, base_uri
30
30
  end
31
31
 
32
+ def test_parse_code_200
33
+ mock_response_200 = Minitest::Mock.new
34
+ mock_response_200.expect(:code, 200)
35
+ mock_response_200.expect(:body, '{}')
36
+
37
+ assert VirustotalAPI::Base.parse(mock_response_200), {}
38
+ end
39
+
40
+ def test_parse_code_204
41
+ mock_response_204 = Minitest::Mock.new
42
+ mock_response_204.expect(:code, 204)
43
+ mock_response_204.expect(:body, '{}')
44
+
45
+ assert_raises VirustotalAPI::RateLimitError do
46
+ VirustotalAPI::Base.parse(mock_response_204)
47
+ end
48
+ end
49
+
32
50
  # Test using FileReport
33
51
  def test_exists?
34
52
  VCR.use_cassette('report') do
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ require './test/test_helper'
3
+
4
+ class RateLimitErrorTest < Minitest::Test
5
+ def test_class_exists
6
+ assert VirustotalAPI::RateLimitError
7
+ end
8
+ end
data/test/version_test.rb CHANGED
@@ -4,6 +4,6 @@ require './test/test_helper'
4
4
  class VirustotalAPIVTReportTest < Minitest::Test
5
5
  def test_version
6
6
  assert VirustotalAPI::VERSION.is_a?(String)
7
- assert VirustotalAPI::VERSION, '0.1.0'
7
+ assert VirustotalAPI::VERSION, '0.2.0'
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virustotal_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pwelch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-26 00:00:00.000000000 Z
11
+ date: 2015-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -160,6 +160,7 @@ files:
160
160
  - ".gitignore"
161
161
  - ".rubocop.yml"
162
162
  - ".travis.yml"
163
+ - CHANGELOG.md
163
164
  - Gemfile
164
165
  - LICENSE.txt
165
166
  - README.md
@@ -167,6 +168,7 @@ files:
167
168
  - lib/virustotal_api.rb
168
169
  - lib/virustotal_api/base.rb
169
170
  - lib/virustotal_api/domain_report.rb
171
+ - lib/virustotal_api/exceptions.rb
170
172
  - lib/virustotal_api/file_report.rb
171
173
  - lib/virustotal_api/file_scan.rb
172
174
  - lib/virustotal_api/ip_report.rb
@@ -175,6 +177,7 @@ files:
175
177
  - lib/virustotal_api/version.rb
176
178
  - test/base_test.rb
177
179
  - test/domain_report_test.rb
180
+ - test/exceptions_test.rb
178
181
  - test/file_report_test.rb
179
182
  - test/file_scan_test.rb
180
183
  - test/fixtures/domain_report.yml
@@ -211,13 +214,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
214
  version: '0'
212
215
  requirements: []
213
216
  rubyforge_project:
214
- rubygems_version: 2.4.3
217
+ rubygems_version: 2.5.1
215
218
  signing_key:
216
219
  specification_version: 4
217
220
  summary: Gem for VirusTotal.com API
218
221
  test_files:
219
222
  - test/base_test.rb
220
223
  - test/domain_report_test.rb
224
+ - test/exceptions_test.rb
221
225
  - test/file_report_test.rb
222
226
  - test/file_scan_test.rb
223
227
  - test/fixtures/domain_report.yml