fetcher 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95db80b36d0be7460c96648620191047913fcec3
4
- data.tar.gz: 4b6fa34c25e625ca71860da03a7831f26404d6d2
3
+ metadata.gz: 3377ac81daf3886db7fe5a5e02c4872dd2f0d3c3
4
+ data.tar.gz: 25a2bbed49a659c1e20651d8b5fd60d5ba163bab
5
5
  SHA512:
6
- metadata.gz: 7fc927c713af888ef8049619fe0e368d3039119b57596091c6c8e02de21ae7800d741dd96df4da180807e1ad0df600f3a4fe1bc10ea31d0ca0a67540a7c8e2a0
7
- data.tar.gz: 705e042295b9ca6bf8b8379145da4860f4e823f92ff0569573ba73959eea5dacc280db37f24389ecd7423e0ac2412e79b0640c9c9be06ce4c5219db2cc0a66e1
6
+ metadata.gz: ae2a87a082f30bbb076ed79df44debb5bee8e4c37fbb8807cd10b5b4364bbb8c7262f10eadd7d253fcb1e341c1ce9549832641fa5c3be00e822915e48406bdb9
7
+ data.tar.gz: fd217ff2d88cf4f6668ae608fccda34d5d64e075362f29a07d3aec7fb0150e8222e2ce2ca8cc3c2f5b1ad237d1c2d1a4cf1ffe17c0aca7fd3aec1f9205590638
@@ -10,3 +10,4 @@ lib/fetcher/version.rb
10
10
  lib/fetcher/worker.rb
11
11
  test/helper.rb
12
12
  test/test_get.rb
13
+ test/test_read.rb
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ Hoe.spec 'fetcher' do
24
24
  self.licenses = ['Public Domain']
25
25
 
26
26
  self.spec_extras = {
27
- :required_ruby_version => '>= 1.9.2'
27
+ required_ruby_version: '>= 1.9.2'
28
28
  }
29
29
 
30
30
  end
@@ -7,16 +7,17 @@
7
7
 
8
8
  # core and stlibs
9
9
 
10
- require 'yaml'
11
- require 'pp'
12
- require 'logger'
13
- require 'fileutils'
10
+ require 'yaml' ### used ??? remove??
11
+ require 'logger' ### used ??? remove??
12
+
13
+ require 'fileutils' ### used ??? remove??
14
14
  require 'uri'
15
15
  require 'net/http'
16
16
  require 'net/https'
17
17
  require 'ostruct'
18
18
  require 'date'
19
19
  require 'cgi'
20
+ require 'pp'
20
21
 
21
22
 
22
23
  # 3rd party gems
@@ -56,10 +57,20 @@ module Fetcher
56
57
  Worker.new.copy( src, dest, opts )
57
58
  end
58
59
 
60
+
59
61
  def self.read( src )
60
62
  Worker.new.read( src )
61
63
  end
62
64
 
65
+ def self.read_blob!( src )
66
+ Worker.new.read_blob!( src )
67
+ end
68
+
69
+ def self.read_utf8!( src )
70
+ Worker.new.read_utf8!( src )
71
+ end
72
+
73
+
63
74
  def self.get( src )
64
75
  Worker.new.get( src )
65
76
  end
@@ -70,5 +81,6 @@ end # module Fetcher
70
81
  if __FILE__ == $0
71
82
  Fetcher.main
72
83
  else
73
- puts Fetcher.banner # say hello
84
+ # say hello
85
+ puts Fetcher.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG)
74
86
  end
@@ -3,7 +3,7 @@ module Fetcher
3
3
 
4
4
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
5
5
  MINOR = 4
6
- PATCH = 4
6
+ PATCH = 5
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
@@ -58,15 +58,43 @@ module Fetcher
58
58
 
59
59
 
60
60
  def read( src )
61
- # return contents (response body) a string
61
+ # return contents (response body) as (ascii/binary) string
62
62
  logger.debug "fetch - copy src: #{src} into string"
63
-
63
+
64
64
  response = get_response( src )
65
-
65
+
66
66
  # on error return empty string; - check: better return nil- why? why not??
67
- return '' if response.code != '200'
67
+ if response.code != '200'
68
+ raise HttpError.new( response.code, response.message )
69
+ end
70
+
71
+ response.body.dup # return string copy - why? why not?? (use to_s?)
72
+ end
73
+
74
+ def read_blob!( src )
75
+ ## note: same as read for now
76
+ read( src )
77
+ end
78
+
79
+ def read_utf8!( src )
80
+ # return contents (response body) a string
81
+ logger.debug "fetch - copy src: #{src} into utf8 string"
82
+
83
+ response = get_response( src )
84
+
85
+ # on error throw exception - why? why not??
86
+ if response.code != '200'
87
+ raise HttpError.new( response.code, response.message )
88
+ end
89
+
90
+ ###
91
+ # Note: Net::HTTP will NOT set encoding UTF-8 etc.
92
+ # will be set to ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
93
+ # thus, set/force encoding to utf-8
68
94
 
69
- response.body.dup # return string copy
95
+ txt = response.body.to_s
96
+ txt = txt.force_encoding( Encoding::UTF_8 )
97
+ txt
70
98
  end
71
99
 
72
100
 
@@ -131,7 +159,7 @@ module Fetcher
131
159
 
132
160
  http_proxy = Net::HTTP::Proxy( proxy.host, proxy.port, proxy.user, proxy.password )
133
161
 
134
- redirect_limit = 4
162
+ redirect_limit = 6
135
163
  response = nil
136
164
 
137
165
  until false
@@ -37,5 +37,4 @@ class TestGet < MiniTest::Test
37
37
  assert_equal '404', res.code
38
38
  end
39
39
 
40
-
41
- end # class TestCopy
40
+ end # class TestGet
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+
5
+ ###
6
+ # to run use
7
+ # ruby -I ./lib -I ./test test/test_read.rb
8
+
9
+ class TestRead < MiniTest::Test
10
+
11
+ def test_read_not_found
12
+ url = 'http://blog.engineyard.com/category/ruby/feed'
13
+ worker = Fetcher::Worker.new
14
+
15
+ assert_raises( Fetcher::HttpError ) do
16
+ res = worker.read( url )
17
+ pp res
18
+ end
19
+ end
20
+
21
+ end # class TestRead
22
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logutils
@@ -75,6 +75,7 @@ files:
75
75
  - lib/fetcher/worker.rb
76
76
  - test/helper.rb
77
77
  - test/test_get.rb
78
+ - test/test_read.rb
78
79
  homepage: https://github.com/rubylibs/fetcher
79
80
  licenses:
80
81
  - Public Domain
@@ -103,3 +104,4 @@ specification_version: 4
103
104
  summary: fetcher - Fetch Text Documents or Binary Blobs via HTTP, HTTPS
104
105
  test_files:
105
106
  - test/test_get.rb
107
+ - test/test_read.rb