tigre-client 0.4.1 → 0.5.0

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.4.0)
4
+ tigre-client (0.4.1)
5
5
  faraday (~> 0.6.0)
6
6
  right_aws (~> 2.1.0)
7
7
 
@@ -44,8 +44,52 @@ module Tigre
44
44
  raise "Missing analysis_id, file_location, or file_type parameter"
45
45
  end
46
46
 
47
- update_data = {:file => File.new(file_location), :file_type => file_type}
48
- Tigre.put_connection("/analyses/#{analysis_id}/upload", update_data)
47
+ if Tigre.s3_analysis_enabled?
48
+ Tigre.logger.info 'Uploading file directly to S3' if Tigre.logger
49
+ bucket = S3Bucket.new(Tigre.s3_analysis_bucket)
50
+ bucket.send_file(file_location, "analysis/#{id.to_s}/#{file[:filename]}")
51
+
52
+ f = File.new(file, 'r')
53
+ update_data = {:file_hash => {'name' => File.basename(f),
54
+ 'size' => File.size(f),
55
+ 'file_type' => file_type}}
56
+ Tigre.put_connection("/analyses/#{analysis_id}", update_data)
57
+ else
58
+ update_data = {:file => File.new(file_location), :file_type => file_type}
59
+ Tigre.put_connection("/analyses/#{analysis_id}/upload", update_data)
60
+ end
61
+ end
62
+
63
+ # required
64
+ # mutex_name_list => String (comma seperated) => I.E 'foo,bar,baz'
65
+ # mutex_name_list => Array => ['foo', 'bar', 'baz']
66
+ def self.get_urls_with_mutex(mutex_name_list)
67
+ raise 'Missing mutex_name_list' if mutex_name_list == ''
68
+ Tigre.get_connection("/analyses/urls/mutex_name?mutex_name_list=#{package_array_list(mutex_name_list)}")
69
+ end
70
+
71
+ # required
72
+ # mutex_name_list => String (comma seperated) => I.E 'foo,bar,baz'
73
+ # mutex_name_list => Array => ['foo', 'bar', 'baz']
74
+ def self.get_samples_with_mutex(mutex_name_list)
75
+ raise 'Missing mutex_name_list' if mutex_name_list == ''
76
+ Tigre.get_connection("/analyses/samples/mutex_name?mutex_name_list=#{package_array_list(mutex_name_list)}")
77
+ end
78
+
79
+ # required
80
+ # dbts_name_list => Hash => I.E {'key1' => 1, 'key2 => 0}
81
+ def self.get_urls_with_dbts(dbts_name_list)
82
+ raise 'Missing dbts_name_list' if dbts_name_list == ''
83
+ search = {:dbts_name_list => dbts_name_list}
84
+ Tigre.put_connection("/analyses/urls/dbts_name", search)
85
+ end
86
+
87
+ # required
88
+ # dbts_name_list => Hash => I.E {'key1' => 1, 'key2 => 0}
89
+ def self.get_samples_with_dbts(dbts_name_list)
90
+ raise 'Missing dbts_name_list' if dbts_name_list == ''
91
+ search = {:dbts_name_list => dbts_name_list}
92
+ Tigre.put_connection("/analyses/samples/dbts_name", search)
49
93
  end
50
94
 
51
95
  end
@@ -32,7 +32,7 @@ module Tigre
32
32
  # hash => Hash
33
33
  # :digest => String, The digest type
34
34
  # :value => String, The digest value
35
- def self.get_analyses(hash)
35
+ def get_analyses(hash)
36
36
  unless hash[:digest] && hash[:value]
37
37
  raise 'Missing parameter :digest or :value'
38
38
  end
@@ -0,0 +1,13 @@
1
+ class S3Bucket
2
+
3
+ def initialize(bucket)
4
+ @s3 = RightAws::S3.new(Tigre::FogConfig::AWS_KEY, Tigre::FogConfig::AWS_SECRET)
5
+ @bucket = @s3.bucket(bucket)
6
+ end
7
+
8
+ def send_file(file, file_name=nil)
9
+ file_name ||= file[:filename]
10
+ @bucket.put(file_name, IO.binread(file[:tempfile]))
11
+ end
12
+
13
+ end
@@ -31,7 +31,9 @@ module Tigre
31
31
 
32
32
  Tigre.post_connection('/urls', post_data)
33
33
  end
34
-
34
+
35
+ # required params
36
+ # urls => Array of hashes {:original_url => url, :source => source, :shareable => shareable}
35
37
  def self.post_many(urls=[])
36
38
  raise "Missing URLS parameter" if urls == []
37
39
  raise 'Too many!! Limit urls to 100 plesae!' if urls.size > 100
@@ -111,7 +113,6 @@ module Tigre
111
113
  # end
112
114
 
113
115
  Tigre.logger.warn "** DEPRECATED ** Use Tigre::Url.index(options) " if Tigre.logger
114
-
115
116
  self.index(options)
116
117
  # common_params(options)
117
118
  #
@@ -1,5 +1,5 @@
1
1
  module Tigre
2
2
  module Client
3
- VERSION = "0.4.1"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
data/lib/tigre-client.rb CHANGED
@@ -18,7 +18,8 @@ require 'tigre-client/url'
18
18
  module Tigre
19
19
 
20
20
  class << self
21
- attr_accessor :token, :server, :endpoint, :conn, :logger, :s3_key, :s3_secret, :s3_bucket
21
+ attr_accessor :token, :server, :endpoint, :conn, :logger
22
+ attr_accessor :s3_key, :s3_secret, :s3_bucket, :s3_analysis_bucket
22
23
 
23
24
  def configure
24
25
  yield self
@@ -29,6 +30,10 @@ module Tigre
29
30
  !Tigre.s3_key.nil? && !Tigre.s3_secret.nil? && !Tigre.s3_bucket.nil?
30
31
  end
31
32
 
33
+ def s3_analysis_enabled?
34
+ !Tigre.s3_key.nil? && !Tigre.s3_secret.nil? && !Tigre.s3_analysis_bucket.nil?
35
+ end
36
+
32
37
  def build_get_connection
33
38
  @conn = Faraday.new(:url => "#{Tigre.server}") do |builder|
34
39
  builder.adapter :net_http
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tigre-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.1
5
+ version: 0.5.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-05-10 00:00:00 -04:00
14
+ date: 2011-05-23 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -93,6 +93,7 @@ files:
93
93
  - lib/tigre-client/common/tag_components.rb
94
94
  - lib/tigre-client/multipart_with_file.rb
95
95
  - lib/tigre-client/occurrence.rb
96
+ - lib/tigre-client/s3_bucket.rb
96
97
  - lib/tigre-client/sample.rb
97
98
  - lib/tigre-client/scan.rb
98
99
  - lib/tigre-client/url.rb