virus_total 0.0.2 → 0.0.3

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: 4cd640a88172cb1d3cd160a5be4ef045d36f4125
4
- data.tar.gz: 0074bf1f636a55c21c8bdab4300ba496cbadbda1
3
+ metadata.gz: 308097c5810248bccc4c3e783656b80fc22ba05d
4
+ data.tar.gz: 95daa10ff9a9263248c8c664a63ffbc766af731f
5
5
  SHA512:
6
- metadata.gz: 1b9ea12c003845bb2c1922c67cae1c8fa18a1951073360706da6f86167ff9ea01c20e5bf455ef360f8dbfbe917ebf585398439f8a98b75c2d8e2f29d8c1d4f69
7
- data.tar.gz: 505752f17dae22f2a85128bd27fb177b282a32f45f700d85acfe9c876dd2f7d2f67439197cd024a2db0bef480b8b687d70f58317fb4ced50bfc9215175461094
6
+ metadata.gz: 19a0ea7eab3ebc523f4e71a78c97487d6e443b382ef676ab192e10f8a537d54a1049fdf9a6ee82d532bacc7d2cef0603515f4cc44b3fa6241104105a864f3622
7
+ data.tar.gz: 5e74412cd54ccf0471b422f4d0c376cc2cc9a4f1142f4a864570c1443b93a87b475ad5954ce55dddfc9a0e88c5118fb6cb8e52a59d8019823919205f6d878881
@@ -0,0 +1,7 @@
1
+ class Hash
2
+ def method_missing(name, *args)
3
+ name = name.to_s
4
+ name.gsub!("_", " ")
5
+ self[name]
6
+ end
7
+ end
@@ -11,6 +11,12 @@ module VirusTotal
11
11
  @apikey = apikey
12
12
  end
13
13
 
14
+ def resource(separator = ", ")
15
+ return @resource.join(separator) if @resource.is_a?(Array)
16
+
17
+ @resource
18
+ end
19
+
14
20
  def api_response(url, params = {})
15
21
  full_url = BASE_URL + url
16
22
  params = default_params.merge(params)
@@ -2,7 +2,7 @@ module VirusTotal
2
2
  # to use this feature you must have a private apikey!
3
3
  class Domain < Base
4
4
  def report
5
- api_response('domain/report', resource: @resource.to_str, method: :get)
5
+ api_response('domain/report', resource: @resource.to_s, method: :get)
6
6
  end
7
7
  end
8
8
  end
@@ -5,18 +5,18 @@ module VirusTotal
5
5
  end
6
6
 
7
7
  def rescan
8
- api_response('file/rescan', resource: @resource.to_str)
8
+ api_response('file/rescan', resource: resource)
9
9
  end
10
10
 
11
11
  def report
12
- api_response('file/report', resource: @resource.to_str)
12
+ api_response('file/report', resource: resource)
13
13
  end
14
14
 
15
15
  private
16
16
 
17
17
  def get_file
18
18
  tmp = Tempfile.open('tmp')
19
- tmp.write(IO::File.read(@resource.to_str))
19
+ tmp.write(IO::File.read(resource))
20
20
  tmp
21
21
  end
22
22
  end
@@ -2,7 +2,7 @@ module VirusTotal
2
2
  # to use this feature you must have a private apikey!
3
3
  class Ip < Base
4
4
  def report
5
- api_response('ip-address/report', resource: @resource.to_str, method: :get)
5
+ api_response('ip-address/report', resource: resource, method: :get)
6
6
  end
7
7
  end
8
8
  end
@@ -10,16 +10,17 @@ module VirusTotal
10
10
  end
11
11
 
12
12
  def info
13
- @response.except_key("scans")
13
+ return unless @response
14
+
15
+ @response.tap { |hash| hash.delete("scans") }
14
16
  end
15
17
 
16
18
  def dangers
17
- scans = @response.scans
18
19
  return {} unless scans
19
20
 
20
21
  dangers = {}
21
22
  scans.each_pair do |key, hash|
22
- next unless hash.detected
23
+ next unless hash["detected"]
23
24
 
24
25
  dangers.merge!({ key => hash })
25
26
  end
@@ -1,11 +1,11 @@
1
1
  module VirusTotal
2
2
  class Url < Base
3
3
  def scan
4
- api_response("url/scan", url: @resource.to_str("\n"))
4
+ api_response("url/scan", url: resource("\n"))
5
5
  end
6
6
 
7
7
  def report
8
- api_response("url/report", resource: @resource.to_str)
8
+ api_response("url/report", resource: resource)
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module VirusTotal
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/virus_total.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "core_extensions"
1
+ require "core_extentions"
2
2
  require "virus_total/base"
3
3
  require "virus_total/url"
4
4
  require "virus_total/file"
@@ -2,7 +2,6 @@ require "virus_total"
2
2
 
3
3
  describe VirusTotal::Base do
4
4
  let(:resource_param) { "first, second" }
5
- let(:resource) { base.instance_variable_get("@resource") }
6
5
  let(:base) { VirusTotal::Base.new(resource_param, "invalid_key") }
7
6
 
8
7
  it "raises AuthError "\
@@ -13,14 +12,14 @@ describe VirusTotal::Base do
13
12
 
14
13
  context "for resource parameter" do
15
14
  it "returns resource correctly" do
16
- resource.to_str.should == "first, second"
15
+ base.resource.should == "first, second"
17
16
  end
18
17
 
19
18
  let(:resource_param) { ["first", "second"] }
20
19
 
21
20
  it "split resources array correctly" do
22
- resource.to_str.should == "first, second"
23
- resource.to_str("\n").should == "first\nsecond"
21
+ base.resource.should == "first, second"
22
+ base.resource("\n").should == "first\nsecond"
24
23
  end
25
24
  end
26
25
  end
@@ -42,8 +42,4 @@ describe Hash do
42
42
  "if hash key with a space" do
43
43
  hash.key2.key_3.should == "val3"
44
44
  end
45
-
46
- it "returns hash w/o key correctly" do
47
- hash.except_key("key2").should == {"key1"=>"val1"}
48
- end
49
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virus_total
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rubycop
@@ -78,7 +78,7 @@ files:
78
78
  - LICENSE.txt
79
79
  - README.md
80
80
  - Rakefile
81
- - lib/core_extensions.rb
81
+ - lib/core_extentions.rb
82
82
  - lib/virus_total.rb
83
83
  - lib/virus_total/base.rb
84
84
  - lib/virus_total/domain.rb
@@ -1,23 +0,0 @@
1
- class Array
2
- def to_str(spliter = ", ")
3
- join(spliter)
4
- end
5
- end
6
-
7
- class String
8
- def to_str(*args)
9
- self
10
- end
11
- end
12
-
13
- class Hash
14
- def except_key(hash_key)
15
- tap { |hash| hash.delete(hash_key) }
16
- end
17
-
18
- def method_missing(name, *args)
19
- name = name.to_s
20
- name.gsub!("_", " ")
21
- self[name]
22
- end
23
- end