spitball 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'uri'
3
+ require 'digest/md5'
3
4
 
4
5
  class Spitball::Remote
5
6
 
@@ -11,6 +12,20 @@ class Spitball::Remote
11
12
  @host = opts[:host]
12
13
  @port = opts[:port]
13
14
  @without = (opts[:without] || []).map{|w| w.to_sym}
15
+ @cache_dir = '/tmp/spitball/client'
16
+ FileUtils.mkdir_p(@cache_dir)
17
+ use_cache_file
18
+ end
19
+
20
+ def use_cache_file
21
+ if File.exist?(cache_file)
22
+ @tarball_url = cache_file
23
+ end
24
+ end
25
+
26
+ def cache_file
27
+ hash = ::Digest::MD5.hexdigest(([@host, @port, @gemfile, @gemfile_lock, Spitball::PROTOCOL_VERSION] + @without).join('/'))
28
+ File.join(@cache_dir, hash)
14
29
  end
15
30
 
16
31
  def cached?
@@ -25,6 +40,7 @@ class Spitball::Remote
25
40
  req.form_data = {'gemfile' => @gemfile, 'gemfile_lock' => @gemfile_lock}
26
41
  req.add_field Spitball::PROTOCOL_HEADER, Spitball::PROTOCOL_VERSION
27
42
  req.add_field Spitball::WITHOUT_HEADER, @without.join(',')
43
+
28
44
  res = Net::HTTP.new(url.host, url.port).start do |http|
29
45
  http.read_timeout = 3000
30
46
  http.request(req) {|r| puts r.read_body }
@@ -53,13 +69,17 @@ class Spitball::Remote
53
69
  end
54
70
 
55
71
  def get_tarball_data(location)
56
- puts "location --> #{location.inspect}"
57
- uri = URI.parse(location)
58
-
59
- if (res = Net::HTTP.get_response(uri)).code == '200'
60
- return res.body
72
+ if File.exist?(location)
73
+ File.read(location)
61
74
  else
62
- raise Spitball::ServerFailure, "Spitball download failed."
75
+ uri = URI.parse(location)
76
+
77
+ if (res = Net::HTTP.get_response(uri)).code == '200'
78
+ File.open(cache_file, 'w') {|f| f << res.body}
79
+ return res.body
80
+ else
81
+ raise Spitball::ServerFailure, "Spitball download failed."
82
+ end
63
83
  end
64
84
  #rescue URI::InvalidURIError => e
65
85
  # raise Spitball::ClientError, e.message
@@ -1,3 +1,3 @@
1
1
  class Spitball
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spitball
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 2
10
- version: 0.4.2
9
+ - 3
10
+ version: 0.4.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Freels
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-11-15 00:00:00 -08:00
20
+ date: 2010-11-16 00:00:00 -08:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency