radiospieler 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +10 -8
- data/VERSION +1 -1
- data/lib/core-extensions/impl_missing.rb +0 -11
- data/lib/extensions/http.rb +47 -7
- data/radiospieler.gemspec +8 -4
- data/radiospieler.tmproj +2 -68
- data/test/http_test.rb +12 -3
- data/test/uri_test.rb +10 -0
- metadata +36 -24
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.2.
|
4
|
+
addressable (2.2.8)
|
5
5
|
archive-tar-minitar (0.5.2)
|
6
6
|
columnize (0.3.6)
|
7
7
|
crack (0.3.1)
|
@@ -12,10 +12,11 @@ GEM
|
|
12
12
|
git (>= 1.2.5)
|
13
13
|
rake
|
14
14
|
rdoc
|
15
|
-
json (1.
|
15
|
+
json (1.7.0)
|
16
16
|
linecache19 (0.5.12)
|
17
17
|
ruby_core_source (>= 0.1.4)
|
18
|
-
multi_json (1.
|
18
|
+
multi_json (1.3.4)
|
19
|
+
nokogiri (1.5.2)
|
19
20
|
psych (1.3.2)
|
20
21
|
rake (0.9.2.2)
|
21
22
|
rdoc (3.12)
|
@@ -30,15 +31,15 @@ GEM
|
|
30
31
|
ruby-debug-base19 (>= 0.11.19)
|
31
32
|
ruby_core_source (0.1.5)
|
32
33
|
archive-tar-minitar (>= 0.5.2)
|
33
|
-
simple_cache_rs (0.9.
|
34
|
+
simple_cache_rs (0.9.3)
|
34
35
|
sqlite3
|
35
36
|
simple_cov (0.2.0)
|
36
|
-
simplecov (0.6.
|
37
|
-
multi_json (~> 1.
|
37
|
+
simplecov (0.6.2)
|
38
|
+
multi_json (~> 1.3)
|
38
39
|
simplecov-html (~> 0.5.3)
|
39
40
|
simplecov-html (0.5.3)
|
40
|
-
sqlite3 (1.3.
|
41
|
-
vcr (2.
|
41
|
+
sqlite3 (1.3.6)
|
42
|
+
vcr (2.1.1)
|
42
43
|
webmock (1.8.6)
|
43
44
|
addressable (>= 2.2.7)
|
44
45
|
crack (>= 0.1.7)
|
@@ -50,6 +51,7 @@ DEPENDENCIES
|
|
50
51
|
bundler
|
51
52
|
htmlentities
|
52
53
|
jeweler
|
54
|
+
nokogiri
|
53
55
|
psych
|
54
56
|
ruby-debug19
|
55
57
|
simple_cache_rs
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.8
|
@@ -1,16 +1,5 @@
|
|
1
1
|
class ImplementationMissing < NameError; end
|
2
2
|
|
3
|
-
class Object
|
4
|
-
private
|
5
|
-
|
6
|
-
def implementation_missing!
|
7
|
-
calling_method_name = caller[1]
|
8
|
-
calling_method_name = $1 if calling_method_name =~ /.*in `(.*)'$/
|
9
|
-
|
10
|
-
raise ImplementationMissing, "Implementation missing: #{self.class.name}##{calling_method_name}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
3
|
module Kernel
|
15
4
|
private
|
16
5
|
|
data/lib/extensions/http.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'simple_cache'
|
3
|
+
require 'nokogiri'
|
3
4
|
|
4
5
|
# The Http module defines a
|
5
6
|
#
|
@@ -23,18 +24,25 @@ module Http
|
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
def get(url, max_age =
|
27
|
+
def get(url, max_age = nil)
|
28
|
+
body, headers = get_body_and_headers(url, max_age)
|
29
|
+
body
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_body_and_headers(url, max_age = nil)
|
33
|
+
max_age ||= MaxAge.for(url)
|
34
|
+
|
27
35
|
App.logger.benchmark("[GET] #{url}", :minimum => 20) do
|
28
|
-
SimpleCache.cached(url, max_age) do
|
36
|
+
SimpleCache.cached("f-#{url}", max_age) do
|
29
37
|
App.logger.debug "[GET] #{url}"
|
30
|
-
|
38
|
+
get_body_and_headers_(url)
|
31
39
|
end
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
35
43
|
private
|
36
44
|
|
37
|
-
def
|
45
|
+
def get_body_and_headers_(uri_str, limit = 10)
|
38
46
|
raise 'too many redirections' if limit == 0
|
39
47
|
|
40
48
|
uri = URI.parse(uri_str)
|
@@ -49,13 +57,45 @@ module Http
|
|
49
57
|
|
50
58
|
case response
|
51
59
|
when Net::HTTPSuccess then
|
52
|
-
response.body
|
60
|
+
body, headers = response.body, response.to_hash
|
61
|
+
[ reencode(body, response["Content-Type"]), headers ]
|
53
62
|
when Net::HTTPRedirection then
|
54
63
|
location = response['location']
|
55
64
|
App.logger.debug "redirected to #{location}"
|
56
|
-
|
65
|
+
get_body_and_headers_(location, limit - 1)
|
57
66
|
else
|
58
|
-
response.value
|
67
|
+
[ response.value, nil ]
|
59
68
|
end
|
60
69
|
end
|
70
|
+
|
71
|
+
def reencode(body, content_type)
|
72
|
+
encodings = [ "ISO-8859-1", "UTF-8" ]
|
73
|
+
|
74
|
+
encodings.unshift($1) if content_type =~ /; charset=(\S+)/
|
75
|
+
encodings.unshift(html_encoding(body)) if content_type =~ /html/
|
76
|
+
|
77
|
+
force_valid_encoding body, *encodings
|
78
|
+
end
|
79
|
+
|
80
|
+
def force_valid_encoding(string, *encodings)
|
81
|
+
encodings.each do |enc|
|
82
|
+
next unless enc
|
83
|
+
begin
|
84
|
+
s = string.force_encoding(enc)
|
85
|
+
next unless s.valid_encoding?
|
86
|
+
return s.encode("UTF-8")
|
87
|
+
rescue Encoding::UndefinedConversionError
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
|
94
|
+
def html_encoding(html)
|
95
|
+
doc = Nokogiri.HTML(html)
|
96
|
+
node = doc.css("meta[http-equiv='Content-Type']").first
|
97
|
+
|
98
|
+
return unless node && node["content"] =~ /; charset=(\S+)/
|
99
|
+
$1
|
100
|
+
end
|
61
101
|
end
|
data/radiospieler.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "radiospieler"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["radiospiel"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-05-03"
|
13
13
|
s.description = "Some basics that your application could benefit from."
|
14
14
|
s.email = "eno@open-lab.org"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -58,12 +58,13 @@ Gem::Specification.new do |s|
|
|
58
58
|
"test/string_ext_test.rb",
|
59
59
|
"test/test_helper.rb",
|
60
60
|
"test/tls_test.rb",
|
61
|
-
"test/uid_test.rb"
|
61
|
+
"test/uid_test.rb",
|
62
|
+
"test/uri_test.rb"
|
62
63
|
]
|
63
64
|
s.homepage = "http://github.com/radiospiel/radiospieler"
|
64
65
|
s.licenses = ["MIT"]
|
65
66
|
s.require_paths = ["lib"]
|
66
|
-
s.rubygems_version = "1.8.
|
67
|
+
s.rubygems_version = "1.8.10"
|
67
68
|
s.summary = "Application base code"
|
68
69
|
|
69
70
|
if s.respond_to? :specification_version then
|
@@ -72,6 +73,7 @@ Gem::Specification.new do |s|
|
|
72
73
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
73
74
|
s.add_runtime_dependency(%q<htmlentities>, [">= 0"])
|
74
75
|
s.add_runtime_dependency(%q<simple_cache_rs>, [">= 0"])
|
76
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
75
77
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
76
78
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
77
79
|
s.add_development_dependency(%q<vcr>, [">= 0"])
|
@@ -83,6 +85,7 @@ Gem::Specification.new do |s|
|
|
83
85
|
else
|
84
86
|
s.add_dependency(%q<htmlentities>, [">= 0"])
|
85
87
|
s.add_dependency(%q<simple_cache_rs>, [">= 0"])
|
88
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
86
89
|
s.add_dependency(%q<bundler>, [">= 0"])
|
87
90
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
88
91
|
s.add_dependency(%q<vcr>, [">= 0"])
|
@@ -95,6 +98,7 @@ Gem::Specification.new do |s|
|
|
95
98
|
else
|
96
99
|
s.add_dependency(%q<htmlentities>, [">= 0"])
|
97
100
|
s.add_dependency(%q<simple_cache_rs>, [">= 0"])
|
101
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
98
102
|
s.add_dependency(%q<bundler>, [">= 0"])
|
99
103
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
100
104
|
s.add_dependency(%q<vcr>, [">= 0"])
|
data/radiospieler.tmproj
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
3
|
<plist version="1.0">
|
4
4
|
<dict>
|
5
|
-
<key>currentDocument</key>
|
6
|
-
<string>lib/app/app/config.rb</string>
|
7
5
|
<key>documents</key>
|
8
6
|
<array>
|
9
7
|
<dict>
|
@@ -20,74 +18,10 @@
|
|
20
18
|
<key>fileHierarchyDrawerWidth</key>
|
21
19
|
<integer>221</integer>
|
22
20
|
<key>metaData</key>
|
23
|
-
<dict
|
24
|
-
<key>Gemfile</key>
|
25
|
-
<dict>
|
26
|
-
<key>caret</key>
|
27
|
-
<dict>
|
28
|
-
<key>column</key>
|
29
|
-
<integer>17</integer>
|
30
|
-
<key>line</key>
|
31
|
-
<integer>8</integer>
|
32
|
-
</dict>
|
33
|
-
<key>firstVisibleColumn</key>
|
34
|
-
<integer>0</integer>
|
35
|
-
<key>firstVisibleLine</key>
|
36
|
-
<integer>0</integer>
|
37
|
-
</dict>
|
38
|
-
<key>lib/app/app/config.rb</key>
|
39
|
-
<dict>
|
40
|
-
<key>caret</key>
|
41
|
-
<dict>
|
42
|
-
<key>column</key>
|
43
|
-
<integer>21</integer>
|
44
|
-
<key>line</key>
|
45
|
-
<integer>27</integer>
|
46
|
-
</dict>
|
47
|
-
<key>firstVisibleColumn</key>
|
48
|
-
<integer>0</integer>
|
49
|
-
<key>firstVisibleLine</key>
|
50
|
-
<integer>0</integer>
|
51
|
-
</dict>
|
52
|
-
<key>lib/app/app/root.rb</key>
|
53
|
-
<dict>
|
54
|
-
<key>caret</key>
|
55
|
-
<dict>
|
56
|
-
<key>column</key>
|
57
|
-
<integer>0</integer>
|
58
|
-
<key>line</key>
|
59
|
-
<integer>6</integer>
|
60
|
-
</dict>
|
61
|
-
<key>firstVisibleColumn</key>
|
62
|
-
<integer>0</integer>
|
63
|
-
<key>firstVisibleLine</key>
|
64
|
-
<integer>0</integer>
|
65
|
-
</dict>
|
66
|
-
<key>lib/extensions/zz_geocoder.rb</key>
|
67
|
-
<dict>
|
68
|
-
<key>caret</key>
|
69
|
-
<dict>
|
70
|
-
<key>column</key>
|
71
|
-
<integer>21</integer>
|
72
|
-
<key>line</key>
|
73
|
-
<integer>8</integer>
|
74
|
-
</dict>
|
75
|
-
<key>firstVisibleColumn</key>
|
76
|
-
<integer>0</integer>
|
77
|
-
<key>firstVisibleLine</key>
|
78
|
-
<integer>0</integer>
|
79
|
-
</dict>
|
80
|
-
</dict>
|
81
|
-
<key>openDocuments</key>
|
82
|
-
<array>
|
83
|
-
<string>Gemfile</string>
|
84
|
-
<string>lib/app/app/config.rb</string>
|
85
|
-
<string>lib/app/app/root.rb</string>
|
86
|
-
<string>lib/extensions/zz_geocoder.rb</string>
|
87
|
-
</array>
|
21
|
+
<dict/>
|
88
22
|
<key>showFileHierarchyDrawer</key>
|
89
23
|
<true/>
|
90
24
|
<key>windowFrame</key>
|
91
|
-
<string>{{
|
25
|
+
<string>{{0, 0}, {1365, 1178}}</string>
|
92
26
|
</dict>
|
93
27
|
</plist>
|
data/test/http_test.rb
CHANGED
@@ -9,10 +9,19 @@ VCR.configure do |c|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class HttpTest < Test::Unit::TestCase
|
12
|
-
def
|
13
|
-
|
12
|
+
def test_get_with_redirection
|
13
|
+
VCR.use_cassette('http_test') do
|
14
14
|
google = Http.get("http://google.de")
|
15
15
|
assert google.starts_with?("<!doctype html>")
|
16
|
-
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_get_body_and_headers
|
20
|
+
VCR.use_cassette('http_test') do
|
21
|
+
body, headers = Http.get_body_and_headers("http://google.de", 0)
|
22
|
+
assert body.starts_with?("<!doctype html>")
|
23
|
+
assert_equal ["text/html; charset=ISO-8859-1"], headers["content-type"]
|
24
|
+
assert_equal "UTF-8", body.encoding.name
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
data/test/uri_test.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiospieler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: htmlentities
|
16
|
-
requirement: &
|
16
|
+
requirement: &70261390331080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70261390331080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: simple_cache_rs
|
27
|
-
requirement: &
|
27
|
+
requirement: &70261390330540 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70261390330540
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: nokogiri
|
38
|
+
requirement: &70261390329900 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70261390329900
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: bundler
|
38
|
-
requirement: &
|
49
|
+
requirement: &70261390329360 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70261390329360
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: jeweler
|
49
|
-
requirement: &
|
60
|
+
requirement: &70261390328680 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70261390328680
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: vcr
|
60
|
-
requirement: &
|
71
|
+
requirement: &70261390327980 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70261390327980
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: webmock
|
71
|
-
requirement: &
|
82
|
+
requirement: &70261390326640 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *70261390326640
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: psych
|
82
|
-
requirement: &
|
93
|
+
requirement: &70261390325880 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: '0'
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *70261390325880
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: simplecov
|
93
|
-
requirement: &
|
104
|
+
requirement: &70261390325340 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - ! '>='
|
@@ -98,10 +109,10 @@ dependencies:
|
|
98
109
|
version: '0'
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *70261390325340
|
102
113
|
- !ruby/object:Gem::Dependency
|
103
114
|
name: ruby-debug19
|
104
|
-
requirement: &
|
115
|
+
requirement: &70261390324680 !ruby/object:Gem::Requirement
|
105
116
|
none: false
|
106
117
|
requirements:
|
107
118
|
- - ! '>='
|
@@ -109,10 +120,10 @@ dependencies:
|
|
109
120
|
version: '0'
|
110
121
|
type: :development
|
111
122
|
prerelease: false
|
112
|
-
version_requirements: *
|
123
|
+
version_requirements: *70261390324680
|
113
124
|
- !ruby/object:Gem::Dependency
|
114
125
|
name: simple_cov
|
115
|
-
requirement: &
|
126
|
+
requirement: &70261390324020 !ruby/object:Gem::Requirement
|
116
127
|
none: false
|
117
128
|
requirements:
|
118
129
|
- - ! '>='
|
@@ -120,7 +131,7 @@ dependencies:
|
|
120
131
|
version: '0'
|
121
132
|
type: :development
|
122
133
|
prerelease: false
|
123
|
-
version_requirements: *
|
134
|
+
version_requirements: *70261390324020
|
124
135
|
description: Some basics that your application could benefit from.
|
125
136
|
email: eno@open-lab.org
|
126
137
|
executables: []
|
@@ -171,6 +182,7 @@ files:
|
|
171
182
|
- test/test_helper.rb
|
172
183
|
- test/tls_test.rb
|
173
184
|
- test/uid_test.rb
|
185
|
+
- test/uri_test.rb
|
174
186
|
homepage: http://github.com/radiospiel/radiospieler
|
175
187
|
licenses:
|
176
188
|
- MIT
|
@@ -186,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
198
|
version: '0'
|
187
199
|
segments:
|
188
200
|
- 0
|
189
|
-
hash:
|
201
|
+
hash: -453988988338308160
|
190
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
203
|
none: false
|
192
204
|
requirements:
|
@@ -195,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
207
|
version: '0'
|
196
208
|
requirements: []
|
197
209
|
rubyforge_project:
|
198
|
-
rubygems_version: 1.8.
|
210
|
+
rubygems_version: 1.8.10
|
199
211
|
signing_key:
|
200
212
|
specification_version: 3
|
201
213
|
summary: Application base code
|