diff --git a/lib/cocoapods-downloader/remote_file.rb b/lib/cocoapods-downloader/remote_file.rb index 2721cc3..a6d5ff0 100644 --- a/lib/cocoapods-downloader/remote_file.rb +++ b/lib/cocoapods-downloader/remote_file.rb @@ -9,7 +9,8 @@ def self.options [:type, :flatten, :sha1, :sha256, :headers] end - class UnsupportedFileTypeError < StandardError; end + class UnsupportedFileTypeError < StandardError + end private @@ -57,7 +58,16 @@ def should_flatten? end def type_with_url(url) - case URI.parse(url).path + url_path = URI.parse(url).path + if type_from_url_path(url_path).nil? + type_with_url_query(url) + else + type_from_url_path(url_path) + end + end + + def type_from_url_path(url_path) + case url_path when /\.zip$/ :zip when /\.(tgz|tar\.gz)$/ @@ -73,6 +83,12 @@ def type_with_url(url) end end + def type_with_url_query(url) + query = URI.parse(url).query.to_s + query_params = Hash[URI.decode_www_form(query)] + type_from_url_path(query_params['file_path']) + end + def filename_with_type(type = :zip) case type when :zip, :tgz, :tar, :tbz, :txz, :dmg diff --git a/spec/fixtures/remote_file/download_file b/spec/fixtures/remote_file/download_file new file mode 100644 index 0000000..81b9692 Binary files /dev/null and b/spec/fixtures/remote_file/download_file differ diff --git a/spec/remote_file_spec.rb b/spec/remote_file_spec.rb index eca4eab..6e1591a 100644 --- a/spec/remote_file_spec.rb +++ b/spec/remote_file_spec.rb @@ -39,6 +39,14 @@ def download_file(full_filename) tmp_folder_with_quotes('lib/file.txt').read.strip.should =~ /This is a fixture/ end + it 'should download file and unzip it when the target url contains file_path query param' do + options = { :http => "#{@fixtures_url}/download_file?file_path=lib.zip" } + downloader = Downloader.for_target(tmp_folder, options) + downloader.download + tmp_folder('lib/file.txt').should.exist + tmp_folder('lib/file.txt').read.strip.should =~ /This is a fixture/ + end + it 'should flatten zip archives, when the spec explicitly demands it' do options = { :flatten => true } downloader = MockRemoteFile.new(tmp_folder, "#{@fixtures_url}/lib.zip", options)