tigre-client 0.2.8 → 0.2.9

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.
@@ -2,13 +2,13 @@ module Tigre
2
2
  class Occurrence
3
3
 
4
4
  ##
5
- # DEPRECIATED
5
+ # DEPRECATED => Use Tigre::Occurrence.all(hash)
6
6
  #
7
7
  # return all the occurrences for a given sha256 URL
8
8
  # required params
9
9
  # sha256 => String
10
10
  def self.for_sha(sha256)
11
- Tigre.logger.warn "** DEPRECIATED ** Use Tigre::Occurrence.all(:digest => 'sha256', :value => 'your-sha256')" if Tigre.logger
11
+ Tigre.logger.warn "** DEPRECATED ** Use Tigre::Occurrence.all(:digest => 'sha256', :value => 'your-sha256')" if Tigre.logger
12
12
 
13
13
  raise "Missing sha256 parameter" if sha256 == ''
14
14
  self.all(:digest => 'sha256', :value => sha256)
@@ -29,15 +29,15 @@ module Tigre
29
29
 
30
30
  # return an individual occurrence for a given sha256 URL
31
31
  # required params
32
- # sha256 => String ** DEPRECIATED **
33
- # occurrence_id => String ** DEPRECIATED **
32
+ # sha256 => String ** DEPRECATED **
33
+ # occurrence_id => String ** DEPRECATED **
34
34
  # hash => Hash
35
35
  # :digest => String, the digest type you wish to use
36
36
  # :value => String, the value of the URLs digest you are using
37
37
  # :occurrence_id => String, the ID of the specific occurrence
38
38
  def self.get(hash, occurrence_id=nil)
39
39
  if hash.is_a?(String)
40
- Tigre.logger.warn "** DEPRECIATED PARAMETERS ** Use Tigre::Occurrence.get(:digest => 'sha256', :value => 'your-sha256', :occurrence_id => 'id')" if Tigre.logger
40
+ Tigre.logger.warn "** DEPRECATED PARAMETERS ** Use Tigre::Occurrence.get(:digest => 'sha256', :value => 'your-sha256', :occurrence_id => 'id')" if Tigre.logger
41
41
  hash = {:digest => 'sha256', :value => hash, :occurrence_id => occurrence_id}
42
42
  end
43
43
 
@@ -5,12 +5,23 @@ module Tigre
5
5
  # file_location => String path to the file
6
6
  # md5 => String
7
7
  # optional params
8
- # options => Hash (reserved for future use)
8
+ # options => Hash
9
+ # :tags => String => I.E 'foo'
10
+ # :tags => String (comma seperated) => I.E 'foo,bar,baz'
11
+ # :tags => Array => ['foo', 'bar', 'baz']
9
12
  def self.post(file_location, md5, options={})
10
13
  if file_location == ''|| md5 == ''
11
14
  raise ArguementError, "File_location or md5 parameter cannot be empty"
12
15
  end
13
-
16
+
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
24
+
14
25
  post_data = {:file => File.new(file_location), :md5 => md5}
15
26
  Tigre.post_file_connection('/samples', post_data.merge(options))
16
27
  end
@@ -95,5 +106,26 @@ module Tigre
95
106
  Tigre.put_connection("/samples/#{md5}/add_tags", update_data)
96
107
  end
97
108
 
109
+ # required params
110
+ # hash => Hash
111
+ # :digest => String, The digest type
112
+ # :value => String, The digest value
113
+ # :tag_list => String (comma seperated) => I.E 'foo,bar,baz'
114
+ # :tag_list => Array => ['foo', 'bar', 'baz']
115
+ def self.remove_tags(hash)
116
+ unless hash[:digest] && hash[:value] && hash[:tag_list]
117
+ raise 'Missing parameter :digest or :value or :tag_list'
118
+ end
119
+
120
+ if hash[:tag_list].is_a?(Array)
121
+ hash[:tag_list] = hash[:tag_list].map {|t| t.strip}.join(',')
122
+ else
123
+ hash[:tag_list] = hash[:tag_list].split(',').map {|t| t.strip}.join(',')
124
+ end
125
+
126
+ update_data = {"tag_list" => hash[:tag_list]}
127
+ Tigre.put_connection("/samples/#{hash[:digest]}/value/#{hash[:value]}/remove_tags", update_data)
128
+ end
129
+
98
130
  end
99
131
  end
@@ -1,6 +1,26 @@
1
1
  module Tigre
2
2
  class Url
3
3
 
4
+ def self.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
+
4
24
  # required params
5
25
  # url => String
6
26
  # options => Hash
@@ -20,8 +40,17 @@ module Tigre
20
40
  post_data = {
21
41
  "url[original_url]" => url,
22
42
  "url[source_name]" => options[:source_name],
23
- "url[shareable]" => options[:shareable]
43
+ "url[shareable]" => options[:shareable],
24
44
  }
45
+
46
+ if options[:tags]
47
+ if options[:tags].is_a?(Array)
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
+
25
54
  Tigre.post_connection('/urls', post_data)
26
55
  end
27
56
 
@@ -58,13 +87,13 @@ module Tigre
58
87
  end
59
88
 
60
89
  # required params
61
- # sha256 => String ** DEPRECIATED **
90
+ # sha256 => String ** DEPRECATED ** => use Tigre::Url.get(:digest => 'sha256', :value => 'your-sha256')
62
91
  # hash => Hash
63
92
  # :digest => String, The digest type
64
93
  # :value => String, The digest value
65
94
  def self.get(hash)
66
95
  if hash.is_a?(String)
67
- Tigre.logger.warn "** DEPRECIATED PARAMETER ** Use Tigre::Url.get(:digest => 'sha256', :value => 'your-sha256')" if Tigre.logger
96
+ Tigre.logger.warn "** DEPRECATED PARAMETER ** Use Tigre::Url.get(:digest => 'sha256', :value => 'your-sha256')" if Tigre.logger
68
97
  hash = {:digest => 'sha256', :value => hash}
69
98
  end
70
99
 
@@ -76,13 +105,13 @@ module Tigre
76
105
  end
77
106
 
78
107
  ##
79
- # DEPRECIATED
108
+ # DEPRECATED => use Tigre::Url.get(:digest => 'md5', :value => 'your-md5')
80
109
  #
81
110
  # required params
82
111
  # md5 => String
83
112
  def self.get_md5(md5)
84
113
  raise ArguementError, "Missing md5 parameter" if md5 == ''
85
- Tigre.logger.warn "** DEPRECIATED ** Use Tigre::Url.get(:digest => 'md5', :value => 'your-md5')" if Tigre.logger
114
+ Tigre.logger.warn "** DEPRECATED ** Use Tigre::Url.get(:digest => 'md5', :value => 'your-md5')" if Tigre.logger
86
115
  self.get(:digest => 'md5', :value => md5)
87
116
  end
88
117
 
@@ -91,9 +120,8 @@ module Tigre
91
120
  # :page => Integer, :default => 0
92
121
  # :per => Integer, :default => 50
93
122
  def self.index(options={})
94
- options[:page] ||= 0
95
- options[:per] ||= 50
96
- Tigre.get_connection("/urls?page=#{options[:page]}&per=#{options[:per]}")
123
+ self.common_params(options)
124
+ Tigre.get_connection("/urls?page=#{@page}&per=#{@per}")
97
125
  end
98
126
 
99
127
  # required params
@@ -105,16 +133,9 @@ module Tigre
105
133
  raise ArguementError, "Missing proper parameters (:start_date or :end_date required)"
106
134
  end
107
135
 
108
- if options[:after] && options[:after].is_a?(Time)
109
- options[:after] = options[:after].to_i
110
- end
111
- if options[:before] && options[:before].is_a?(Time)
112
- options[:before] = options[:before].to_i
113
- end
136
+ self.common_params(options)
114
137
 
115
- options[:page] ||= 0
116
- options[:per] ||= 50
117
- Tigre.get_connection("/urls/daterange?after=#{options[:after]}&before=#{options[:before]}&page=#{options[:page]}&per=#{options[:per]}")
138
+ Tigre.get_connection("/urls/daterange?after=#{@after}&before=#{@before}&page=#{@page}&per=#{@per}")
118
139
  end
119
140
 
120
141
  # required params
@@ -154,7 +175,7 @@ module Tigre
154
175
  # :per => Integer, :default => 50
155
176
  def self.tagged_with(tags, options={})
156
177
  if tags == ''
157
- raise ArguementError, "Missing tags parameter"
178
+ raise "Missing tags parameter"
158
179
  end
159
180
 
160
181
  if tags.is_a?(Array)
@@ -163,16 +184,30 @@ module Tigre
163
184
  tags = tags.split(',').map {|t| t.strip}.join(',')
164
185
  end
165
186
 
166
- if options[:after] && options[:after].is_a?(Time)
167
- options[:after] = options[:after].to_i
168
- end
169
- if options[:before] && options[:before].is_a?(Time)
170
- options[:before] = options[:before].to_i
187
+ self.common_params(options)
188
+
189
+ Tigre.get_connection("/urls/tagged_with?tags=#{tags}&after=#{@after}&before=#{@before}&page=#{@page}&per=#{@per}")
190
+ end
191
+
192
+ # required params
193
+ # hash => Hash
194
+ # :digest => String, The digest type
195
+ # :value => String, The digest value
196
+ # :tag_list => String (comma seperated) => I.E 'foo,bar,baz'
197
+ # :tag_list => Array => ['foo', 'bar', 'baz']
198
+ def self.remove_tags(hash)
199
+ unless hash[:digest] && hash[:value] && hash[:tag_list]
200
+ raise 'Missing parameter :digest or :value or :tag_list'
171
201
  end
172
202
 
173
- options[:page] ||= 0
174
- options[:per] ||= 50
175
- Tigre.get_connection("/urls/tagged_with?tags=#{tags}&after=#{options[:after]}&before=#{options[:before]}&page=#{options[:page]}&per=#{options[:per]}")
203
+ if hash[:tag_list].is_a?(Array)
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]}
210
+ Tigre.put_connection("/urls/#{hash[:digest]}/value/#{hash[:value]}/remove_tags", update_data)
176
211
  end
177
212
 
178
213
  end
@@ -1,5 +1,5 @@
1
1
  module Tigre
2
2
  module Client
3
- VERSION = "0.2.8"
3
+ VERSION = "0.2.9"
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.8
5
+ version: 0.2.9
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-19 00:00:00 -04:00
14
+ date: 2011-04-20 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency