backup_foundation 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c1dedfde54756382a8678d0fb8fdda1376a665f
4
- data.tar.gz: 4e4381ee71169524edc990cd4e02d6c583e8dcde
3
+ metadata.gz: e551a2d3dc0da1b02e9aeac46bf78a2d1c8a4a9c
4
+ data.tar.gz: 20d5efee61d05ffc931bf90bb6ca2cd67b914d10
5
5
  SHA512:
6
- metadata.gz: b03a254a1788bd5a6bdc016773597bbc65fedb017a0b281f8b83778c30313f937083fae5838fda0651ce229736515fa2c359f8cbdf25ef292145ad60e71c7e0e
7
- data.tar.gz: 51d771eed61045cd7dfea260d24adf9d6048725b521e025ee2346b7c4da49babd48030f33b09fda42563fc0d14037cd0bfa016f83df78720c1451eda017d27df
6
+ metadata.gz: dac1c3cc89dc62c847758ff79531a04994e692d8b8c8e0aa62394da655f8c0134308784973dd9cd91aa95308b95014f8b4b54ea7374a3d98d770955f98404892
7
+ data.tar.gz: ffaf1f2ed65ff213fcaebff6b2dcf92c36818ecce7e15ad9f4833d5bf54274084518641051537c2dcbbc3a3860c11469f804d8bc3ea27f3c2ad4cf38c9c52a99
@@ -65,23 +65,39 @@ module BackupFoundation
65
65
  end
66
66
  end
67
67
 
68
- def download_db_dump(tmpdir, db)
68
+ def download_db_dump(tmpdir, db, limit = 10)
69
69
  file_path = nil
70
- url = URI.parse "#{BackupFoundation::HOST}/api/file?key=#{@params[:key]}&name=#{db[:name] || db[:type]}"
71
- http = Net::HTTP.new url.host, url.port
72
- if url.is_a? URI::HTTPS
73
- http.use_ssl = true
74
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
70
+ url = URI.parse case db
71
+ when Hash
72
+ "#{BackupFoundation::HOST}/api/file?key=#{@params[:key]}&name=#{db[:name] || db[:type]}"
73
+ when String
74
+ db
75
75
  end
76
- http.request_get(url.request_uri) do |response|
77
- file_path = "#{tmpdir}/#{response['Content-Disposition'][/"(.*)"/, 1]}"
78
- File.open file_path, 'wb' do |file|
79
- response.read_body do |str|
80
- file.write str
81
- end
76
+ http_download_request(url).request_get(url.request_uri) do |response|
77
+ case response
78
+ when Net::HTTPSuccess
79
+ file_path = "#{tmpdir}/#{(response['Content-Disposition'] || "\"#{url.path.split('/').last}\"")[/"(.*)"/, 1]}"
80
+ File.open file_path, 'wb' do |file|
81
+ response.read_body do |str|
82
+ file.write str
83
+ end
84
+ end
85
+ when Net::HTTPRedirection
86
+ file_path = download_db_dump(tmpdir, response['Location'], limit - 1)
87
+ else
88
+ response.error!
82
89
  end
83
90
  end
84
91
  file_path
85
92
  end
93
+
94
+ def http_download_request(url)
95
+ Net::HTTP.new(url.host, url.port).tap do |http|
96
+ if url.is_a? URI::HTTPS
97
+ http.use_ssl = true
98
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
99
+ end
100
+ end
101
+ end
86
102
  end
87
103
  end
@@ -1,3 +1,3 @@
1
1
  module BackupFoundation
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup_foundation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Shaydurov