downer 0.3.1 → 0.3.2

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.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{downer}
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nate Miller"]
12
- s.date = %q{2010-08-08}
12
+ s.date = %q{2010-08-09}
13
13
  s.default_executable = %q{downer}
14
14
  s.description = %q{Downer is a tool used to download a list of urls from a website thorugh HTTP.}
15
15
  s.email = %q{nate@natemiller.org}
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'net/http'
3
+ require 'cgi'
3
4
  require 'nokogiri'
4
5
  require 'optparse'
5
6
  require 'open-uri'
@@ -10,15 +10,15 @@ module Downer
10
10
 
11
11
  def initialize(url, destination)
12
12
  @url, @destination = sanitize_url(url), destination
13
- @uri = URI.parse(url)
13
+ @uri = URI.parse(@url)
14
14
  end
15
15
 
16
16
  # Returns the name which this file will be saved as
17
17
  def get_save_filename
18
- file_name = @uri.to_s
18
+ file_name = CGI.unescape(@uri.to_s)
19
19
  file_name = file_name.gsub(/https?:\/\//,'').split('/').last
20
- file_name = file_name.gsub('%5B', '[')
21
- file_name = file_name.gsub('%5D', ']')
20
+ #file_name = file_name.gsub('%5B', '[')
21
+ #file_name = file_name.gsub('%5D', ']')
22
22
  file_name
23
23
  # TODO : refine to auto append file extentions based on content type
24
24
  end
@@ -52,12 +52,12 @@ module Downer
52
52
  fout.puts @content
53
53
  end
54
54
 
55
- def sanitize_url(unsafe_url)
56
- url = unsafe_url
57
- url.gsub!('[', '%5B')
58
- url.gsub!(']', '%5D')
59
- url.gsub!(',', '%2C')
60
- url
55
+ def sanitize_url(url)
56
+ unsafe_url = String.new(url)
57
+ scheme = unsafe_url.slice!(/(https?|ftp|smb):\/\//)
58
+ parts = unsafe_url.split('/')
59
+ parts.map! { |part| CGI::escape(part).gsub('+', '%20') }
60
+ scheme + parts.join('/')
61
61
  end
62
62
  end
63
63
  end
@@ -20,7 +20,7 @@ module Downer
20
20
  end
21
21
 
22
22
  @items.each { |item| try_download_item(item) }
23
- successful_downloads
23
+ @successful_downloads
24
24
  end
25
25
 
26
26
  private
@@ -39,4 +39,4 @@ module Downer
39
39
  end
40
40
  end
41
41
  end
42
- end
42
+ end
@@ -16,6 +16,10 @@ module Downer
16
16
  item.get_save_filename.should == 'mapsAndAtlases2.png'
17
17
  end
18
18
 
19
+ it "should successfully encode invalid chars into ASCII equivalents" do
20
+ item = DownloadItem.new('http://www.urbaninfluence.com/My File_Name With White space.png', '/tmp')
21
+ item.url.should == 'http://www.urbaninfluence.com/My%20File_Name%20With%20White%20space.png'
22
+ end
19
23
 
20
24
  it "should restore bad url tokens into valid ascii characters" do
21
25
  item = DownloadItem.new('http://www.urbaninfluence.com/my[place].html', '/tmp')
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 2
3
3
  :major: 0
4
4
  :build:
5
5
  :minor: 3
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: downer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nate Miller
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-08 00:00:00 -07:00
18
+ date: 2010-08-09 00:00:00 -07:00
19
19
  default_executable: downer
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency