cherrypicker 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/cherrypicker.gemspec CHANGED
@@ -18,4 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('progressbar', '~> 0.9')
21
23
  end
@@ -2,26 +2,34 @@
2
2
  #
3
3
  # Download.new(hostname, url, username, password)
4
4
  require 'net/http'
5
+ require 'progressbar'
5
6
 
6
7
  class Download
7
- attr_accessor :hostname, :url, :filename
8
+ attr_accessor :hostname, :url, :filename, :size, :progress
8
9
 
9
- def initialize(hostname, url, filename)
10
- @hostname = hostname
11
- @url = url
12
- @filename = filename
10
+ def initialize(hostname, url, filename, size = nil)
11
+ @hostname = hostname
12
+ @url = url
13
+ @filename = filename
14
+ @size = size
15
+ @progress = 0
13
16
 
14
- download
17
+ download_file
15
18
  end
16
19
 
17
20
  private
18
-
19
- def download
20
- Net::HTTP.start("#{self.hostname}") { |http|
21
- resp = http.get("#{self.url}")
22
- open("#{self.filename}", "wb") { |file|
23
- file.write(resp.body)
24
- }
25
- }
21
+
22
+ def download_file
23
+ http = Net::HTTP.new("#{self.hostname}")
24
+ http.request_get("#{self.url}") do |response|
25
+ bar = ProgressBar.new("#{self.url}", self.size.to_i)
26
+ File.open("#{self.filename}", "wb") do |file|
27
+ response.read_body do |segment|
28
+ self.progress += segment.length
29
+ bar.set(self.progress)
30
+ file.write(segment)
31
+ end
32
+ end
33
+ end
26
34
  end
27
35
  end
@@ -5,9 +5,9 @@
5
5
  # puts hotfile.hostname
6
6
  # hotfile.download
7
7
  class Hotfile
8
- attr_accessor :link, :hostname, :filename, :username, :password
8
+ attr_accessor :link, :hostname, :filename, :username, :password, :size
9
9
 
10
- def initialize(link, username, password)
10
+ def initialize(link, username, password, size = nil)
11
11
  if link =~ /hotfile.com\/dl\/\d*\/[0-9a-f]*\/.*.*\.html/
12
12
  @link = link[/(.*)\.html/, 1]
13
13
  else
@@ -17,10 +17,11 @@ class Hotfile
17
17
  @password = password
18
18
  @hostname = hostname
19
19
  @filename = filename
20
+ @size = size
20
21
  end
21
22
 
22
23
  def download
23
- Download.new(self.hostname, remote_url, self.filename)
24
+ Download.new(self.hostname, remote_url, self.filename, self.size)
24
25
  end
25
26
 
26
27
  def filename
@@ -7,19 +7,20 @@
7
7
  # puts rapid.host
8
8
  # rapid.download
9
9
  class Rapidshare
10
- attr_accessor :link, :fileid, :filename, :hostname, :username, :password
10
+ attr_accessor :link, :fileid, :filename, :hostname, :username, :password, :size
11
11
 
12
- def initialize(link, username, password)
12
+ def initialize(link, username, password, size = nil)
13
13
  @link = link
14
14
  @fileid = fileid
15
15
  @filename = filename
16
16
  @hostname = hostname
17
17
  @username = username
18
18
  @password = password
19
+ @size = size
19
20
  end
20
21
 
21
22
  def download
22
- Download.new(self.hostname, remote_url, self.filename)
23
+ Download.new(self.hostname, remote_url, self.filename, self.size)
23
24
  end
24
25
 
25
26
  def fileid
@@ -1,3 +1,3 @@
1
1
  module Cherrypicker
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -5,7 +5,7 @@ class RapidshareTest < Test::Unit::TestCase
5
5
  context "Information request" do
6
6
 
7
7
  should "return response" do
8
- response = Rapidshare.new("http://rapidshare.com/files/453165880/test_file.txt", "username", "password")
8
+ response = Rapidshare.new("http://rapidshare.com/files/453165880/test_file.txt", "6160038", "PXVA62ZY")
9
9
  assert response.fileid =~ /\d*/
10
10
  assert response.filename.length > 0
11
11
  assert response.hostname.length > 0
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cherrypicker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Karl Entwistle
@@ -12,8 +12,18 @@ cert_chain: []
12
12
 
13
13
  date: 2011-03-21 00:00:00 +00:00
14
14
  default_executable:
15
- dependencies: []
16
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: progressbar
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "0.9"
25
+ type: :runtime
26
+ version_requirements: *id001
17
27
  description:
18
28
  email:
19
29
  - Karl@Entwistle.com