tigre-client 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tigre-client (0.2.4)
4
+ tigre-client (0.2.5)
5
5
  faraday (~> 0.6.0)
6
6
 
7
7
  GEM
data/lib/tigre-client.rb CHANGED
@@ -9,13 +9,17 @@ require 'tigre-client/url'
9
9
  module Tigre
10
10
 
11
11
  class << self
12
- attr_accessor :token, :server, :endpoint, :conn
12
+ attr_accessor :token, :server, :endpoint, :conn, :logger
13
13
 
14
14
  def configure
15
15
  yield self
16
16
  true
17
17
  end
18
18
 
19
+ def logger(level, message)
20
+ RAILS_DEFAULT_LOGGER.send(level.to_sym, message) if defined?(RAILS_DEFAULT_LOGGER)
21
+ end
22
+
19
23
  def build_get_connection
20
24
  @conn = Faraday.new(:url => "#{Tigre.server}") do |builder|
21
25
  builder.adapter :net_http
@@ -1,30 +1,61 @@
1
1
  module Tigre
2
2
  class Occurrence
3
3
 
4
+ ##
5
+ # DEPRECIATED
6
+ #
4
7
  # return all the occurrences for a given sha256 URL
5
8
  # required params
6
9
  # sha256 => String
7
10
  def self.for_sha(sha256)
8
- raise ArguementError, "Missing sha256 parameter" if sha256 == ''
9
- Tigre.get_connection("/urls/#{sha256}/occurrences")
11
+ Tigre.logger('warn', "** DEPRECIATED ** Use Tigre::Occurrence.all(:digest => 'sha256', :value => 'your-sha256')")
12
+
13
+ raise "Missing sha256 parameter" if sha256 == ''
14
+ self.all(:digest => 'sha256', :value => sha256)
15
+ end
16
+
17
+ # returns all the occurrences for a given URL
18
+ # required params
19
+ # hash => Hash
20
+ # :digest => String, the digest type you wish to use
21
+ # :value => String, the value of the URLs digest you are using
22
+ def self.all(hash)
23
+ unless hash[:digest] && hash[:value]
24
+ raise 'Missing parameter :digest, :value'
25
+ end
26
+
27
+ Tigre.get_connection("/urls/#{hash[:digest]}/value/#{hash[:value]}/occurrences")
10
28
  end
11
29
 
12
30
  # return an individual occurrence for a given sha256 URL
13
31
  # required params
14
- # sha256 => String
15
- # occurrence_id => String
16
- def self.get(sha256, occurrence_id)
17
- raise ArguementError, "Missing sha256 or occurrence_id parameter" if (sha256 == '' || occurrence_id == '')
18
- Tigre.get_connection("/urls/#{sha256}/occurrences/#{occurrence_id}")
32
+ # sha256 => String ** DEPRECIATED **
33
+ # occurrence_id => String ** DEPRECIATED **
34
+ # hash => Hash
35
+ # :digest => String, the digest type you wish to use
36
+ # :value => String, the value of the URLs digest you are using
37
+ # :occurrence_id => String, the ID of the specific occurrence
38
+ def self.get(hash, occurrence_id=nil)
39
+ if hash.is_a?(String)
40
+ Tigre.logger('warn', "** DEPRECIATED PARAMETERS ** Use Tigre::Occurrence.get(:digest => 'sha256', :value => 'your-sha256', :occurrence_id => 'id')")
41
+ hash = {:digest => 'sha256', :value => hash, :occurrence_id => occurrence_id}
42
+ end
43
+
44
+ unless hash[:digest] && hash[:value] && hash[:occurrence_id]
45
+ raise 'Missing parameter :digest, :value or :occurrence_id'
46
+ end
47
+
48
+ Tigre.get_connection("/urls/#{hash[:digest]}/value/#{hash[:value]}/occurrences/#{hash[:occurrence_id]}")
19
49
  end
20
50
 
51
+
21
52
  # updated an individual occurrence for a given sha256 URL
22
53
  # required params
23
54
  # sha256 => String
24
55
  # occurrence_id => String
25
56
  # params_hash => Hash
26
57
  def self.update(sha256, occurrence_id, params_hash={})
27
- raise ArguementError, "Missing sha256 parameter" if sha256 == ''
58
+ raise "Missing sha256 parameter" if sha256 == ''
28
59
 
29
60
  update_data = params_hash.map { |k, v| {"occurrence[#{k.to_s}]" => v.to_s} }
30
61
  Tigre.put_connection("/urls/#{sha256}/occurrences/#{occurrence_id}", update_data)
@@ -50,7 +50,7 @@ module Tigre
50
50
  def self.sha256(sha256)
51
51
  Tigre.get_connection("/samples/sha256/#{sha256}")
52
52
  end
53
-
53
+
54
54
  # required params
55
55
  # tags => String => I.E 'foo'
56
56
  # tags => String (comma seperated) => I.E 'foo,bar,baz'
@@ -58,21 +58,32 @@ module Tigre
58
58
  end
59
59
 
60
60
  # required params
61
- # sha256 => String
62
- def self.get(sha256)
63
- if sha256 == ''
64
- raise ArguementError, "Missing sha256 parameter"
61
+ # sha256 => String ** DEPRECIATED **
62
+ # hash => Hash
63
+ # :digest => String, The digest type
64
+ # :value => String, The digest value
65
+ def self.get(hash)
66
+ if hash.is_a?(String)
67
+ Tigre.logger('warn', "** DEPRECIATED PARAMETER ** Use Tigre::Url.get(:digest => 'sha256', :value => 'your-sha256')")
68
+ hash = {:digest => 'sha256', :value => hash}
69
+ end
70
+
71
+ unless hash[:digest] && hash[:value]
72
+ raise ArguementError, 'Missing parameter :digest or :value'
65
73
  end
66
- Tigre.get_connection("/urls/#{sha256}")
74
+
75
+ Tigre.get_connection("/urls/#{hash[:digest]}/value/#{hash[:value]}")
67
76
  end
68
77
 
78
+ ##
79
+ # DEPRECIATED
80
+ #
69
81
  # required params
70
82
  # md5 => String
71
83
  def self.get_md5(md5)
72
- if md5 == ''
73
- raise ArguementError, "Missing md5 parameter"
74
- end
75
- Tigre.get_connection("/urls/md5/#{md5}")
84
+ raise ArguementError, "Missing md5 parameter" if md5 == ''
85
+ Tigre.logger('warn', "** DEPRECIATED ** Use Tigre::Url.get(:digest => 'md5', :value => 'your-md5')")
86
+ self.get(:digest => 'md5', :value => md5)
76
87
  end
77
88
 
78
89
  # optional params
@@ -1,5 +1,5 @@
1
1
  module Tigre
2
2
  module Client
3
- VERSION = "0.2.5"
3
+ VERSION = "0.2.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tigre-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.5
5
+ version: 0.2.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marcio Castilho
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-12 00:00:00 -04:00
14
+ date: 2011-04-18 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency