fetcher 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +42 -3
- data/bin/fetch +0 -0
- data/lib/fetcher.rb +5 -1
- data/lib/fetcher/cli/opts.rb +3 -7
- data/lib/fetcher/cli/runner.rb +7 -10
- data/lib/fetcher/version.rb +1 -1
- data/lib/fetcher/worker.rb +17 -11
- metadata +18 -25
- checksums.yaml +0 -7
data/README.markdown
CHANGED
@@ -7,9 +7,6 @@
|
|
7
7
|
* forum :: [groups.google.com/group/webslideshow](https://groups.google.com/group/webslideshow)
|
8
8
|
|
9
9
|
|
10
|
-
## Description
|
11
|
-
|
12
|
-
|
13
10
|
## Usage
|
14
11
|
|
15
12
|
### Copy (to File)
|
@@ -31,6 +28,45 @@ or
|
|
31
28
|
worker = Fetcher::Worker.new
|
32
29
|
txt = worker.read( 'https://raw.github.com/openfootball/at-austria/master/2013_14/bl.txt' )
|
33
30
|
|
31
|
+
Note: The method `read` will return a string.
|
32
|
+
|
33
|
+
|
34
|
+
### Get (HTTP Response)
|
35
|
+
|
36
|
+
response = Fetcher.get( 'https://raw.github.com/openfootball/at-austria/master/2013_14/bl.txt' )
|
37
|
+
|
38
|
+
or
|
39
|
+
|
40
|
+
worker = Fetcher::Worker.new
|
41
|
+
response = worker.get( 'https://raw.github.com/openfootball/at-austria/master/2013_14/bl.txt' )
|
42
|
+
|
43
|
+
Note: The method `get` will return a `Net::HTTPResponse` object
|
44
|
+
(lets you use code, headers, body, etc.).
|
45
|
+
|
46
|
+
puts response.code # => '404'
|
47
|
+
# Note: Returned (status) code is a string e.g. '404'
|
48
|
+
puts response.message # => 'Not Found'
|
49
|
+
puts response.body
|
50
|
+
puts response.content_type # => 'text/html; charset=UTF-8'
|
51
|
+
puts response['content-type'] # => 'text/html; charset=UTF-8'
|
52
|
+
# Note: Headers are always downcased
|
53
|
+
# e.g. use 'content-type' not 'Content-Type'
|
54
|
+
|
55
|
+
|
56
|
+
## Command Line
|
57
|
+
|
58
|
+
~~~
|
59
|
+
fetch version 0.7.0 - Lets you fetch text documents or binary blobs via HTTP, HTTPS.
|
60
|
+
|
61
|
+
Usage: fetch [options] URI
|
62
|
+
-o, --output PATH Output Path (default is '.')
|
63
|
+
-v, --verbose Show debug trace
|
64
|
+
|
65
|
+
|
66
|
+
Examples:
|
67
|
+
fetch https://raw.github.com/openfootball/at-austria/master/2013_14/bl.txt
|
68
|
+
fetch -o downloads https://raw.github.com/openfootball/at-austria/master/2013_14/bl.txt
|
69
|
+
~~~
|
34
70
|
|
35
71
|
|
36
72
|
## Install
|
@@ -51,6 +87,9 @@ The [`sportdb`](https://github.com/geraldb/sport.db.ruby) gem that lets you read
|
|
51
87
|
and more in plain text
|
52
88
|
ships with the `fetcher` gem.
|
53
89
|
|
90
|
+
The [`pluto`](https://github.com/geraldb/pluto) gem that lets you build web pages
|
91
|
+
from published web feeds
|
92
|
+
ships with the `fetcher` gem.
|
54
93
|
|
55
94
|
|
56
95
|
## License
|
data/bin/fetch
CHANGED
File without changes
|
data/lib/fetcher.rb
CHANGED
@@ -54,7 +54,7 @@ module Fetcher
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# convenience shortcuts
|
57
|
-
|
57
|
+
|
58
58
|
def self.copy( src, dest )
|
59
59
|
Worker.new.copy( src, dest )
|
60
60
|
end
|
@@ -63,6 +63,10 @@ module Fetcher
|
|
63
63
|
Worker.new.read( src )
|
64
64
|
end
|
65
65
|
|
66
|
+
def self.get( src )
|
67
|
+
Worker.new.get( src )
|
68
|
+
end
|
69
|
+
|
66
70
|
end # module Fetcher
|
67
71
|
|
68
72
|
|
data/lib/fetcher/cli/opts.rb
CHANGED
data/lib/fetcher/cli/runner.rb
CHANGED
@@ -25,15 +25,13 @@ module Fetcher
|
|
25
25
|
def run( args )
|
26
26
|
opt=OptionParser.new do |cmd|
|
27
27
|
|
28
|
-
cmd.banner = "Usage: fetch [options]
|
28
|
+
cmd.banner = "Usage: fetch [options] URI"
|
29
29
|
|
30
30
|
cmd.on( '-o', '--output PATH', "Output Path (default is '#{opts.output_path}')" ) { |s| opts.output_path = s }
|
31
31
|
|
32
32
|
# todo: find different letter for debug trace switch (use v for version?)
|
33
33
|
cmd.on( '-v', '--verbose', 'Show debug trace' ) do
|
34
|
-
|
35
|
-
# logger.datetime_format = "%H:%H:%S"
|
36
|
-
# logger.level = Logger::DEBUG
|
34
|
+
LogUtils::Logger.root.level = :debug
|
37
35
|
end
|
38
36
|
|
39
37
|
usage =<<EOS
|
@@ -50,7 +48,8 @@ Further information:
|
|
50
48
|
https://github.com/geraldb/fetcher
|
51
49
|
|
52
50
|
EOS
|
53
|
-
|
51
|
+
|
52
|
+
## todo: also add -? if possible as alternative
|
54
53
|
cmd.on_tail( '-h', '--help', 'Show this message' ) do
|
55
54
|
puts usage
|
56
55
|
exit
|
@@ -69,13 +68,11 @@ EOS
|
|
69
68
|
logger.debug "uri.host=<#{uri.host}>, uri.path=<#{uri.path}>"
|
70
69
|
|
71
70
|
if uri.path == '/' || uri.path == ''
|
72
|
-
dest = "#{uri.host}"
|
71
|
+
dest = "#{opts.output_path}/#{uri.host}"
|
73
72
|
else
|
74
|
-
dest = "#{uri.host}@#{uri.path.gsub( /[ \-]/, '_').gsub( /[\/\\]/, '-')}"
|
73
|
+
dest = "#{opts.output_path}/#{uri.host}@#{uri.path.gsub( /[ \-]/, '_').gsub( /[\/\\]/, '-')}"
|
75
74
|
end
|
76
|
-
|
77
|
-
## todo: use output path option
|
78
|
-
|
75
|
+
|
79
76
|
Worker.new.copy( src, dest )
|
80
77
|
|
81
78
|
end # each arg
|
data/lib/fetcher/version.rb
CHANGED
data/lib/fetcher/worker.rb
CHANGED
@@ -17,14 +17,22 @@ module Fetcher
|
|
17
17
|
end
|
18
18
|
|
19
19
|
|
20
|
+
def get( src )
|
21
|
+
# return HTTPResponse (code,message,body,etc.)
|
22
|
+
logger.debug "fetch - get(_response) src: #{src}"
|
23
|
+
|
24
|
+
get_response( src )
|
25
|
+
end
|
26
|
+
|
27
|
+
|
20
28
|
def read( src )
|
21
29
|
# return contents (response body) a string
|
22
30
|
logger.debug "fetch - copy src: #{src} into string"
|
23
31
|
|
24
32
|
response = get_response( src )
|
25
33
|
|
26
|
-
# on error return empty string
|
27
|
-
return '' if response.
|
34
|
+
# on error return empty string; - check: better return nil- why? why not??
|
35
|
+
return '' if response.code != '200'
|
28
36
|
|
29
37
|
response.body.dup # return string copy
|
30
38
|
end
|
@@ -34,9 +42,9 @@ module Fetcher
|
|
34
42
|
logger.debug "fetch - copy src: #{src} to dest: #{dest}"
|
35
43
|
|
36
44
|
response = get_response( src )
|
37
|
-
|
45
|
+
|
38
46
|
# on error return; do NOT copy file; sorry
|
39
|
-
return if response.
|
47
|
+
return if response.code != '200'
|
40
48
|
|
41
49
|
# check for content type; use 'wb' for images
|
42
50
|
if response.content_type =~ /image/
|
@@ -97,7 +105,8 @@ module Fetcher
|
|
97
105
|
|
98
106
|
if response.code == '200'
|
99
107
|
logger.debug "#{response.code} #{response.message}"
|
100
|
-
|
108
|
+
logger.debug " content_type: #{response.content_type}, content_length: #{response.content_length}"
|
109
|
+
break # will return response
|
101
110
|
elsif (response.code == '301' || response.code == '302' || response.code == '303' || response.code == '307' )
|
102
111
|
# 301 = moved permanently
|
103
112
|
# 302 = found
|
@@ -111,15 +120,12 @@ module Fetcher
|
|
111
120
|
end
|
112
121
|
uri = newuri
|
113
122
|
else
|
114
|
-
|
115
|
-
|
116
|
-
return nil # todo: throw StandardException?
|
123
|
+
puts "*** error - fetch HTTP - #{response.code} #{response.message}"
|
124
|
+
break # will return response
|
117
125
|
end
|
118
126
|
end
|
119
127
|
|
120
|
-
|
121
|
-
|
122
|
-
response # return respone or nil if error
|
128
|
+
response
|
123
129
|
end # method copy
|
124
130
|
|
125
131
|
end # class Worker
|
metadata
CHANGED
@@ -1,57 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Gerald Bauer
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-09-14 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: logutils
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &75519830 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0.6'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
|
-
version_requirements:
|
23
|
-
requirements:
|
24
|
-
- - ! '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.6'
|
24
|
+
version_requirements: *75519830
|
27
25
|
- !ruby/object:Gem::Dependency
|
28
26
|
name: rdoc
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &75537890 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
30
29
|
requirements:
|
31
30
|
- - ~>
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
32
|
+
version: '3.10'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '4.0'
|
35
|
+
version_requirements: *75537890
|
41
36
|
- !ruby/object:Gem::Dependency
|
42
37
|
name: hoe
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &75536950 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
44
40
|
requirements:
|
45
41
|
- - ~>
|
46
42
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
43
|
+
version: '3.3'
|
48
44
|
type: :development
|
49
45
|
prerelease: false
|
50
|
-
version_requirements:
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.6'
|
46
|
+
version_requirements: *75536950
|
55
47
|
description: fetcher - Fetch Text Documents or Binary Blobs via HTTP, HTTPS
|
56
48
|
email: webslideshow@googlegroups.com
|
57
49
|
executables:
|
@@ -73,7 +65,6 @@ files:
|
|
73
65
|
homepage: https://github.com/geraldb/fetcher
|
74
66
|
licenses:
|
75
67
|
- Public Domain
|
76
|
-
metadata: {}
|
77
68
|
post_install_message:
|
78
69
|
rdoc_options:
|
79
70
|
- --main
|
@@ -81,19 +72,21 @@ rdoc_options:
|
|
81
72
|
require_paths:
|
82
73
|
- lib
|
83
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
84
76
|
requirements:
|
85
77
|
- - ! '>='
|
86
78
|
- !ruby/object:Gem::Version
|
87
79
|
version: 1.9.2
|
88
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
89
82
|
requirements:
|
90
83
|
- - ! '>='
|
91
84
|
- !ruby/object:Gem::Version
|
92
85
|
version: '0'
|
93
86
|
requirements: []
|
94
87
|
rubyforge_project: fetcher
|
95
|
-
rubygems_version:
|
88
|
+
rubygems_version: 1.8.17
|
96
89
|
signing_key:
|
97
|
-
specification_version:
|
90
|
+
specification_version: 3
|
98
91
|
summary: fetcher - Fetch Text Documents or Binary Blobs via HTTP, HTTPS
|
99
92
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: ef1b964e3b4a79b13b008147f894244610851bb9
|
4
|
-
data.tar.gz: 84815891771fe636ecf09891451dca80bb4fd83f
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 01df88051ef004d00c25e9dcbdb1fb363737f1862106af02c4f74ad6712894960eb47c152853be0a29689c41aa47db7ebb57b00ef9154ff8564e92dafb4d213e
|
7
|
-
data.tar.gz: 13a9c6a495483b07a0fc4b693cec8cc205aa7de48333f95884535d4ac2ab61cd3e4d5e85b4b24c41f477fcee3a971d125381bae36d872b319d12a18dfb240d3c
|