tigre-client 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/tigre-client/common_params.rb +33 -0
- data/lib/tigre-client/sample.rb +85 -38
- data/lib/tigre-client/url.rb +28 -65
- data/lib/tigre-client/version.rb +1 -1
- data/lib/tigre-client.rb +1 -0
- metadata +3 -2
data/Gemfile.lock
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Tigre
|
2
|
+
module CommonParams
|
3
|
+
|
4
|
+
def common_params(params)
|
5
|
+
@page = params[:page] ||= 0
|
6
|
+
@per = params[:per] ||= 50
|
7
|
+
|
8
|
+
if params[:after]
|
9
|
+
if params[:after].is_a?(Time)
|
10
|
+
@after = params[:after].to_i
|
11
|
+
else
|
12
|
+
@after = params[:after]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
if params[:before]
|
16
|
+
if params[:before].is_a?(Time)
|
17
|
+
@before = params[:before].to_i
|
18
|
+
else
|
19
|
+
@before = params[:before]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def package_array_list(list)
|
25
|
+
if list.is_a?(Array)
|
26
|
+
list.map {|m| m.strip}.join(',')
|
27
|
+
else
|
28
|
+
list.split(',').map {|m| m.strip}.join(',')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/tigre-client/sample.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Tigre
|
2
2
|
class Sample
|
3
|
-
|
3
|
+
|
4
|
+
extend Tigre::CommonParams
|
5
|
+
|
4
6
|
# required params
|
5
7
|
# file_location => String path to the file
|
6
8
|
# md5 => String
|
@@ -14,13 +16,7 @@ module Tigre
|
|
14
16
|
raise ArguementError, "File_location or md5 parameter cannot be empty"
|
15
17
|
end
|
16
18
|
|
17
|
-
if options[:tags]
|
18
|
-
if options[:tags].is_a?(Array)
|
19
|
-
options[:tags] = options[:tags].map {|t| t.strip}.join(',')
|
20
|
-
else
|
21
|
-
options[:tags] = options[:tags].split(',').map {|t| t.strip}.join(',')
|
22
|
-
end
|
23
|
-
end
|
19
|
+
options[:tags] = package_array_list(options[:tags]) if options[:tags]
|
24
20
|
|
25
21
|
post_data = {:file => File.new(file_location), :md5 => md5}
|
26
22
|
Tigre.post_file_connection('/samples', post_data.merge(options))
|
@@ -31,9 +27,8 @@ module Tigre
|
|
31
27
|
# :page => Integer, :default => 0
|
32
28
|
# :per => Integer, :default => 50
|
33
29
|
def self.index(options={})
|
34
|
-
options
|
35
|
-
|
36
|
-
Tigre.get_connection("/samples?page=#{options[:page]}&per=#{options[:per]}")
|
30
|
+
common_params(options)
|
31
|
+
Tigre.get_connection("/samples?page=#{@page}&per=#{@per}")
|
37
32
|
end
|
38
33
|
|
39
34
|
# required params
|
@@ -44,22 +39,44 @@ module Tigre
|
|
44
39
|
Tigre.put_connection("/samples/#{md5}", update_data)
|
45
40
|
end
|
46
41
|
|
42
|
+
def self.get(params_hash)
|
43
|
+
unless params_hash[:digest] && params_hash[:value]
|
44
|
+
raise 'Missing parameter :digest or :value'
|
45
|
+
end
|
46
|
+
|
47
|
+
Tigre.get_connection("/samples/#{params_hash[:digest]}/value/#{params_hash[:value]}")
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# DEPRECATED => use Tigre::Sample.get(:digest => 'md5', :value => 'your-md5')
|
52
|
+
#
|
47
53
|
# required params
|
48
54
|
# md5 => String
|
49
55
|
def self.md5(md5)
|
50
|
-
Tigre.
|
56
|
+
Tigre.logger.warn "** DEPRECATED ** Use Tigre::Sample.get(:digest => 'md5', :value => 'your-md5')" if Tigre.logger
|
57
|
+
self.get(:digest => 'md5', :value => md5)
|
51
58
|
end
|
52
59
|
|
60
|
+
##
|
61
|
+
# DEPRECATED => use Tigre::Sample.get(:digest => 'sha1', :value => 'your-sha1')
|
62
|
+
#
|
53
63
|
# required params
|
54
64
|
# sha1 => String
|
55
65
|
def self.sha1(sha1)
|
56
|
-
Tigre.
|
66
|
+
Tigre.logger.warn "** DEPRECATED ** Use Tigre::Sample.get(:digest => 'sha1', :value => 'your-sha1')" if Tigre.logger
|
67
|
+
params_hash = {:digest => 'sha1', :value => sha1}
|
68
|
+
self.get(params_hash)
|
57
69
|
end
|
58
70
|
|
71
|
+
##
|
72
|
+
# DEPRECATED => use Tigre::Sample.get(:digest => 'sha256', :value => 'your-sha256')
|
73
|
+
#
|
59
74
|
# required params
|
60
75
|
# sha256 => String
|
61
76
|
def self.sha256(sha256)
|
62
|
-
Tigre.
|
77
|
+
Tigre.logger.warn "** DEPRECATED ** Use Tigre::Sample.get(:digest => 'sha256', :value => 'your-sha256')" if Tigre.logger
|
78
|
+
params_hash = {:digest => 'sha256', :value => sha256}
|
79
|
+
self.get(params_hash)
|
63
80
|
end
|
64
81
|
|
65
82
|
# required params
|
@@ -72,18 +89,12 @@ module Tigre
|
|
72
89
|
# :per => Integer, :default => 50
|
73
90
|
def self.tagged_with(tags, options={})
|
74
91
|
if tags == ''
|
75
|
-
raise
|
76
|
-
end
|
77
|
-
|
78
|
-
if tags.is_a?(Array)
|
79
|
-
tags = tags.map {|t| t.strip}.join(',')
|
80
|
-
else
|
81
|
-
tags = tags.split(',').map {|t| t.strip}.join(',')
|
92
|
+
raise "Missing tags parameter"
|
82
93
|
end
|
83
|
-
|
84
|
-
options
|
85
|
-
|
86
|
-
Tigre.get_connection("/samples/tagged_with?tags=#{tags}&page=#{
|
94
|
+
|
95
|
+
common_params(options)
|
96
|
+
tags = package_array_list(tags)
|
97
|
+
Tigre.get_connection("/samples/tagged_with?tags=#{tags}&page=#{@page}&per=#{@per}")
|
87
98
|
end
|
88
99
|
|
89
100
|
# required
|
@@ -96,13 +107,7 @@ module Tigre
|
|
96
107
|
raise ArguementError, "Missing tags parameter"
|
97
108
|
end
|
98
109
|
|
99
|
-
|
100
|
-
tags = tags.map {|t| t.strip}.join(',')
|
101
|
-
else
|
102
|
-
tags = tags.split(',').map {|t| t.strip}.join(',')
|
103
|
-
end
|
104
|
-
update_data = {"tag_list" => tags}
|
105
|
-
|
110
|
+
update_data = {"tag_list" => package_array_list(tags)}
|
106
111
|
Tigre.put_connection("/samples/#{md5}/add_tags", update_data)
|
107
112
|
end
|
108
113
|
|
@@ -116,15 +121,57 @@ module Tigre
|
|
116
121
|
unless hash[:digest] && hash[:value] && hash[:tag_list]
|
117
122
|
raise 'Missing parameter :digest or :value or :tag_list'
|
118
123
|
end
|
124
|
+
|
125
|
+
update_data = {"tag_list" => package_array_list(hash[:tag_list])}
|
126
|
+
Tigre.put_connection("/samples/#{hash[:digest]}/value/#{hash[:value]}/remove_tags", update_data)
|
127
|
+
end
|
128
|
+
|
129
|
+
# required params
|
130
|
+
# tags => String => I.E 'foo'
|
131
|
+
# tags => String (comma seperated) => I.E 'foo,bar,baz'
|
132
|
+
# tags => Array => ['foo', 'bar', 'baz']
|
133
|
+
# optional params
|
134
|
+
# options => Hash
|
135
|
+
# :page => Integer, :default => 0
|
136
|
+
# :per => Integer, :default => 50
|
137
|
+
def self.has_mime_type(mime_types, options={})
|
138
|
+
if mime_types == ''
|
139
|
+
raise "Missing tags parameter"
|
140
|
+
end
|
119
141
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
142
|
+
common_params(options)
|
143
|
+
mime_types = package_array_list(mime_types)
|
144
|
+
Tigre.get_connection("/samples/has_mime_type?mime_types=#{mime_types}&page=#{@page}&per=#{@per}")
|
145
|
+
end
|
146
|
+
|
147
|
+
# required params
|
148
|
+
# hash => Hash
|
149
|
+
# :digest => String, The digest type
|
150
|
+
# :value => String, The digest value
|
151
|
+
# :mime_type_list => String (comma seperated) => I.E 'foo,bar,baz'
|
152
|
+
# :mime_type_list => Array => ['foo', 'bar', 'baz']
|
153
|
+
def self.add_mime_type(hash)
|
154
|
+
unless hash[:digest] && hash[:value] && hash[:mime_type_list]
|
155
|
+
raise 'Missing parameter :digest or :value or :mime_type_list'
|
124
156
|
end
|
125
157
|
|
126
|
-
update_data = {"
|
127
|
-
Tigre.put_connection("/samples/#{hash[:digest]}/value/#{hash[:value]}/
|
158
|
+
update_data = {"mime_types" => package_array_list(hash[:mime_type_list])}
|
159
|
+
Tigre.put_connection("/samples/#{hash[:digest]}/value/#{hash[:value]}/add_mime_types", update_data)
|
160
|
+
end
|
161
|
+
|
162
|
+
# required params
|
163
|
+
# hash => Hash
|
164
|
+
# :digest => String, The digest type
|
165
|
+
# :value => String, The digest value
|
166
|
+
# :mime_type_list => String (comma seperated) => I.E 'foo,bar,baz'
|
167
|
+
# :mime_type_list => Array => ['foo', 'bar', 'baz']
|
168
|
+
def self.remove_mime_type(hash)
|
169
|
+
unless hash[:digest] && hash[:value] && hash[:mime_type_list]
|
170
|
+
raise 'Missing parameter :digest or :value or :mime_type_list'
|
171
|
+
end
|
172
|
+
|
173
|
+
update_data = {"mime_types" => package_array_list(hash[:mime_type_list])}
|
174
|
+
Tigre.put_connection("/samples/#{hash[:digest]}/value/#{hash[:value]}/remove_mime_types", update_data)
|
128
175
|
end
|
129
176
|
|
130
177
|
end
|
data/lib/tigre-client/url.rb
CHANGED
@@ -1,25 +1,7 @@
|
|
1
1
|
module Tigre
|
2
2
|
class Url
|
3
|
-
|
4
|
-
|
5
|
-
@page = params[:page] ||= 0
|
6
|
-
@per = params[:per] ||= 50
|
7
|
-
|
8
|
-
if params[:after]
|
9
|
-
if params[:after].is_a?(Time)
|
10
|
-
@after = params[:after].to_i
|
11
|
-
else
|
12
|
-
@after = params[:after]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
if params[:before]
|
16
|
-
if params[:before].is_a?(Time)
|
17
|
-
@before = params[:before].to_i
|
18
|
-
else
|
19
|
-
@before = params[:before]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
3
|
+
|
4
|
+
extend Tigre::CommonParams
|
23
5
|
|
24
6
|
# required params
|
25
7
|
# url => String
|
@@ -28,12 +10,15 @@ module Tigre
|
|
28
10
|
# optional params
|
29
11
|
# options => Hash
|
30
12
|
# :shareable => Boolean, :default => false
|
13
|
+
# :tags => String => I.E 'foo'
|
14
|
+
# :tags => String (comma seperated) => I.E 'foo,bar,baz'
|
15
|
+
# :tags => Array => ['foo', 'bar', 'baz']
|
31
16
|
def self.post(url, options={})
|
32
17
|
if url == ''
|
33
|
-
raise
|
18
|
+
raise "Missing url parameter"
|
34
19
|
end
|
35
20
|
unless options[:source_name]
|
36
|
-
raise
|
21
|
+
raise "Missing source_name parameter"
|
37
22
|
end
|
38
23
|
|
39
24
|
# prepare post data
|
@@ -43,14 +28,8 @@ module Tigre
|
|
43
28
|
"url[shareable]" => options[:shareable],
|
44
29
|
}
|
45
30
|
|
46
|
-
if options[:tags]
|
47
|
-
|
48
|
-
post_data["url[tags]"] = options[:tags].map {|t| t.strip}.join(',')
|
49
|
-
else
|
50
|
-
post_data["url[tags]"] = options[:tags].split(',').map {|t| t.strip}.join(',')
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
31
|
+
post_data["url[tags]"] = package_array_list(options[:tags]) if options[:tags]
|
32
|
+
|
54
33
|
Tigre.post_connection('/urls', post_data)
|
55
34
|
end
|
56
35
|
|
@@ -59,7 +38,7 @@ module Tigre
|
|
59
38
|
# params_hash => Hash
|
60
39
|
def self.update(sha256, params_hash)
|
61
40
|
if sha256 == '' || params_hash.empty?
|
62
|
-
raise
|
41
|
+
raise "Missing url parameter or params_hash is empty"
|
63
42
|
end
|
64
43
|
|
65
44
|
update_data = params_hash.map { |k, v| {"url[#{k.to_s}]" => v.to_s} }
|
@@ -70,18 +49,13 @@ module Tigre
|
|
70
49
|
# sha256 => String
|
71
50
|
# tags => String => I.E 'foo'
|
72
51
|
# tags => String (comma seperated) => I.E 'foo,bar,baz'
|
73
|
-
# tags => Array => ['foo', 'bar', 'baz']
|
52
|
+
# tags => Array => ['foo', 'bar', 'baz']
|
74
53
|
def self.add_tags(sha256, tags)
|
75
54
|
if sha256 == '' || tags == ''
|
76
55
|
raise ArguementError, "Missing tags parameter"
|
77
56
|
end
|
78
|
-
|
79
|
-
|
80
|
-
tags = tags.map {|t| t.strip}.join(',')
|
81
|
-
else
|
82
|
-
tags = tags.split(',').map {|t| t.strip}.join(',')
|
83
|
-
end
|
84
|
-
update_data = {"tag_list" => tags}
|
57
|
+
|
58
|
+
update_data = {"tag_list" => package_array_list(tags)}
|
85
59
|
|
86
60
|
Tigre.put_connection("/urls/#{sha256}/add_tags", update_data)
|
87
61
|
end
|
@@ -133,7 +107,7 @@ module Tigre
|
|
133
107
|
raise ArguementError, "Missing proper parameters (:start_date or :end_date required)"
|
134
108
|
end
|
135
109
|
|
136
|
-
|
110
|
+
common_params(options)
|
137
111
|
|
138
112
|
Tigre.get_connection("/urls/daterange?after=#{@after}&before=#{@before}&page=#{@page}&per=#{@per}")
|
139
113
|
end
|
@@ -151,16 +125,17 @@ module Tigre
|
|
151
125
|
raise ArguementError, "Missing domain parameter"
|
152
126
|
end
|
153
127
|
|
154
|
-
if options[:after] && options[:after].is_a?(Time)
|
155
|
-
|
156
|
-
end
|
157
|
-
if options[:before] && options[:before].is_a?(Time)
|
158
|
-
|
159
|
-
end
|
160
|
-
|
161
|
-
options[:page] ||= 0
|
162
|
-
options[:per] ||= 50
|
163
|
-
|
128
|
+
# if options[:after] && options[:after].is_a?(Time)
|
129
|
+
# options[:after] = options[:after].to_i
|
130
|
+
# end
|
131
|
+
# if options[:before] && options[:before].is_a?(Time)
|
132
|
+
# options[:before] = options[:before].to_i
|
133
|
+
# end
|
134
|
+
#
|
135
|
+
# options[:page] ||= 0
|
136
|
+
# options[:per] ||= 50
|
137
|
+
common_params(options)
|
138
|
+
Tigre.get_connection("/urls/domains?domain=#{domain}&after=#{@after}&before=#{@before}&page=#{@page}&per=#{@per}")
|
164
139
|
end
|
165
140
|
|
166
141
|
# required params
|
@@ -178,14 +153,8 @@ module Tigre
|
|
178
153
|
raise "Missing tags parameter"
|
179
154
|
end
|
180
155
|
|
181
|
-
|
182
|
-
|
183
|
-
else
|
184
|
-
tags = tags.split(',').map {|t| t.strip}.join(',')
|
185
|
-
end
|
186
|
-
|
187
|
-
self.common_params(options)
|
188
|
-
|
156
|
+
tags = package_array_list(tags)
|
157
|
+
common_params(options)
|
189
158
|
Tigre.get_connection("/urls/tagged_with?tags=#{tags}&after=#{@after}&before=#{@before}&page=#{@page}&per=#{@per}")
|
190
159
|
end
|
191
160
|
|
@@ -200,13 +169,7 @@ module Tigre
|
|
200
169
|
raise 'Missing parameter :digest or :value or :tag_list'
|
201
170
|
end
|
202
171
|
|
203
|
-
|
204
|
-
hash[:tag_list] = hash[:tag_list].map {|t| t.strip}.join(',')
|
205
|
-
else
|
206
|
-
hash[:tag_list] = hash[:tag_list].split(',').map {|t| t.strip}.join(',')
|
207
|
-
end
|
208
|
-
|
209
|
-
update_data = {"tag_list" => hash[:tag_list]}
|
172
|
+
update_data = {"tag_list" => package_array_list(hash[:tag_list])}
|
210
173
|
Tigre.put_connection("/urls/#{hash[:digest]}/value/#{hash[:value]}/remove_tags", update_data)
|
211
174
|
end
|
212
175
|
|
data/lib/tigre-client/version.rb
CHANGED
data/lib/tigre-client.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: tigre-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
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-
|
14
|
+
date: 2011-04-25 00:00:00 -04:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- Gemfile.lock
|
54
54
|
- Rakefile
|
55
55
|
- lib/tigre-client.rb
|
56
|
+
- lib/tigre-client/common_params.rb
|
56
57
|
- lib/tigre-client/multipart_with_file.rb
|
57
58
|
- lib/tigre-client/occurrence.rb
|
58
59
|
- lib/tigre-client/sample.rb
|