fetcher 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95db80b36d0be7460c96648620191047913fcec3
4
+ data.tar.gz: 4b6fa34c25e625ca71860da03a7831f26404d6d2
5
+ SHA512:
6
+ metadata.gz: 7fc927c713af888ef8049619fe0e368d3039119b57596091c6c8e02de21ae7800d741dd96df4da180807e1ad0df600f3a4fe1bc10ea31d0ca0a67540a7c8e2a0
7
+ data.tar.gz: 705e042295b9ca6bf8b8379145da4860f4e823f92ff0569573ba73959eea5dacc280db37f24389ecd7423e0ac2412e79b0640c9c9be06ce4c5219db2cc0a66e1
@@ -25,22 +25,12 @@ require 'logutils'
25
25
 
26
26
  # our own code
27
27
 
28
- require 'fetcher/version'
28
+ require 'fetcher/version' # let version always go first
29
29
  require 'fetcher/worker'
30
30
 
31
31
 
32
32
  module Fetcher
33
33
 
34
- # version string for generator meta tag (includes ruby version)
35
- def self.banner
36
- "fetcher/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
37
- end
38
-
39
- def self.root
40
- "#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
41
- end
42
-
43
-
44
34
  def self.main
45
35
 
46
36
  ## NB: only load (require) cli code if called
@@ -58,11 +48,12 @@ module Fetcher
58
48
  Runner.new.run(args)
59
49
  end
60
50
 
51
+
61
52
  #############################
62
53
  # convenience shortcuts
63
54
 
64
- def self.copy( src, dest )
65
- Worker.new.copy( src, dest )
55
+ def self.copy( src, dest, opts={} )
56
+ Worker.new.copy( src, dest, opts )
66
57
  end
67
58
 
68
59
  def self.read( src )
@@ -79,6 +70,5 @@ end # module Fetcher
79
70
  if __FILE__ == $0
80
71
  Fetcher.main
81
72
  else
82
- # say hello
83
- puts Fetcher.banner
73
+ puts Fetcher.banner # say hello
84
74
  end
@@ -1,7 +1,23 @@
1
1
 
2
2
  module Fetcher
3
3
 
4
- VERSION = '0.4.3'
4
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
5
+ MINOR = 4
6
+ PATCH = 4
7
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
8
+
9
+ def self.version
10
+ VERSION
11
+ end
12
+
13
+ # version string for generator meta tag (includes ruby version)
14
+ def self.banner
15
+ "fetcher/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
16
+ end
17
+
18
+ def self.root
19
+ "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
20
+ end
5
21
 
6
22
  end # module Fetcher
7
23
 
@@ -2,6 +2,27 @@
2
2
 
3
3
  module Fetcher
4
4
 
5
+ class Error < StandardError
6
+ end
7
+
8
+ ####
9
+ # todo/check:
10
+ # rename to HttpRequestError or similar??
11
+ # use "common" error class - why? why not?
12
+
13
+ class HttpError < Error
14
+ attr_reader :code, :message
15
+
16
+ def initialize( code, message )
17
+ @code, @message = code, message
18
+ end
19
+
20
+ def to_s
21
+ "HTTP request failed (NOK) => #{@code} #{@message}"
22
+ end
23
+ end
24
+
25
+
5
26
  class Worker
6
27
 
7
28
  include LogUtils::Logging
@@ -49,7 +70,7 @@ module Fetcher
49
70
  end
50
71
 
51
72
 
52
- def copy( src, dest )
73
+ def copy( src, dest, opts={} )
53
74
  ### fix: return true - success or
54
75
  # false - error!!!
55
76
 
@@ -59,18 +80,28 @@ module Fetcher
59
80
 
60
81
  response = get_response( src )
61
82
 
62
- # on error return; do NOT copy file; sorry
63
- return if response.code != '200'
83
+ # NOTE: on error (NOK) raise exception; do NOT copy file; sorry
84
+ if response.code != '200'
85
+ raise HttpError.new( response.code, response.message )
86
+ end
87
+
88
+ ### check:
89
+ ## why not always use wb???
90
+ ## how is it differet for text files?
91
+ ## will convert newlines (from windows to unix) ???
64
92
 
65
93
  # check for content type; use 'wb' for images
66
- if response.content_type =~ /image/
94
+ if response.content_type =~ /image/ ||
95
+ response.content_type =~ /zip/ ## use application/zip or something - why? why not??
67
96
  logger.debug ' switching to binary'
68
- flags = 'wb'
97
+ mode = 'wb'
69
98
  else
70
- flags = 'w'
99
+ mode = 'w'
71
100
  end
72
101
 
73
- File.open( dest, flags ) do |f|
102
+ mode = opts[:mode] if opts[:mode] # if mode flags passed in -take precedence
103
+
104
+ File.open( dest, mode ) do |f|
74
105
  f.write( response.body )
75
106
  end
76
107
  end
@@ -3,11 +3,8 @@
3
3
 
4
4
  ## minitest setup
5
5
 
6
- # require 'minitest/unit'
7
6
  require 'minitest/autorun'
8
7
 
9
- # include MiniTest::Unit # lets us use TestCase instead of MiniTest::Unit::TestCase
10
-
11
8
 
12
9
  ## our own code
13
10
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'helper'
4
4
 
5
- class TestGet < MiniTest::Unit::TestCase
5
+ class TestGet < MiniTest::Test
6
6
 
7
7
  def test_get
8
8
  url = 'https://raw.github.com/rubylibs/fetcher/master/README.md'
metadata CHANGED
@@ -1,57 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
5
- prerelease:
4
+ version: 0.4.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gerald Bauer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-28 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: logutils
16
- requirement: &81882710 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0.6'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *81882710
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rdoc
27
- requirement: &81882450 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
- version: '3.10'
33
+ version: '4.0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *81882450
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: hoe
38
- requirement: &81882190 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ~>
45
+ - - "~>"
42
46
  - !ruby/object:Gem::Version
43
- version: '3.3'
47
+ version: '3.13'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *81882190
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.13'
47
55
  description: fetcher - Fetch Text Documents or Binary Blobs via HTTP, HTTPS
48
56
  email: webslideshow@googlegroups.com
49
57
  executables:
50
58
  - fetch
51
59
  extensions: []
52
60
  extra_rdoc_files:
61
+ - HISTORY.md
53
62
  - Manifest.txt
63
+ - README.md
54
64
  files:
65
+ - ".gemtest"
55
66
  - HISTORY.md
56
67
  - Manifest.txt
57
68
  - README.md
@@ -64,33 +75,31 @@ files:
64
75
  - lib/fetcher/worker.rb
65
76
  - test/helper.rb
66
77
  - test/test_get.rb
67
- - .gemtest
68
78
  homepage: https://github.com/rubylibs/fetcher
69
79
  licenses:
70
80
  - Public Domain
81
+ metadata: {}
71
82
  post_install_message:
72
83
  rdoc_options:
73
- - --main
84
+ - "--main"
74
85
  - README.md
75
86
  require_paths:
76
87
  - lib
77
88
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
89
  requirements:
80
- - - ! '>='
90
+ - - ">="
81
91
  - !ruby/object:Gem::Version
82
92
  version: 1.9.2
83
93
  required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
94
  requirements:
86
- - - ! '>='
95
+ - - ">="
87
96
  - !ruby/object:Gem::Version
88
97
  version: '0'
89
98
  requirements: []
90
- rubyforge_project: fetcher
91
- rubygems_version: 1.8.17
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.2
92
101
  signing_key:
93
- specification_version: 3
102
+ specification_version: 4
94
103
  summary: fetcher - Fetch Text Documents or Binary Blobs via HTTP, HTTPS
95
104
  test_files:
96
105
  - test/test_get.rb