libravatar 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/libravatar.rb +24 -4
- data/libravatar.gemspec +2 -2
- data/test/test_libravatar.rb +7 -1
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/libravatar.rb
CHANGED
@@ -57,12 +57,13 @@ class Libravatar
|
|
57
57
|
|
58
58
|
# Grab the DNS SRV records associated with the target domain,
|
59
59
|
# and choose one according to RFC2782.
|
60
|
-
def
|
60
|
+
def srv_lookup
|
61
61
|
profile = @@profiles[ @https ? 1 : 0 ]
|
62
62
|
Resolv::DNS::open do |dns|
|
63
63
|
rrs = dns.getresources(profile[:srv] + get_target_domain(),
|
64
64
|
Resolv::DNS::Resource::IN::SRV).to_a
|
65
|
-
return
|
65
|
+
return [nil, nil] unless rrs.any?
|
66
|
+
|
66
67
|
|
67
68
|
min_priority = rrs.map{ |r| r.priority }.min
|
68
69
|
rrs.delete_if{ |r| r.priority != min_priority }
|
@@ -72,13 +73,24 @@ class Libravatar
|
|
72
73
|
weight_sum = rrs.inject(0) { |a,r| a+r.weight }
|
73
74
|
value = rand( weight_sum + 1 )
|
74
75
|
rrs.each do |r|
|
75
|
-
|
76
|
-
return profile[:scheme] + r.target.to_s + port_fragment if r.weight <= value
|
76
|
+
return [r.target, r.port] if r.weight <= value
|
77
77
|
value -= r.weight
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
def get_base_url
|
83
|
+
profile = @@profiles[ @https ? 1 : 0 ]
|
84
|
+
target, port = srv_lookup
|
85
|
+
|
86
|
+
if (target && port)
|
87
|
+
port_fragment = port != profile[:port] ? ':' + port : ''
|
88
|
+
return profile[:scheme] + target.to_s + port_fragment
|
89
|
+
else
|
90
|
+
return profile[:scheme] + profile[:host]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
82
94
|
# Generate the libravatar URL
|
83
95
|
def to_s
|
84
96
|
if @email
|
@@ -98,6 +110,14 @@ class Libravatar
|
|
98
110
|
|
99
111
|
private
|
100
112
|
|
113
|
+
def sanitize_srv_lookup(hostname, port)
|
114
|
+
unless hostname.match(/^[0-9a-zA-Z\-.]+$/) && 1 <= port && port <= 65535
|
115
|
+
return [nil, nil]
|
116
|
+
end
|
117
|
+
|
118
|
+
return [hostname, port]
|
119
|
+
end
|
120
|
+
|
101
121
|
# Normalize an openid URL following the description on libravatar.org
|
102
122
|
def normalize_openid(s)
|
103
123
|
x = URI.parse(s)
|
data/libravatar.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{libravatar}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kang-min Liu"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-24}
|
13
13
|
s.description = %q{libravatar.org provides avatar image hosting (like gravatar.com). Their users may associate avatar images with email or openid. This rubygem can be used to generate libravatar avatar image URL}
|
14
14
|
s.email = %q{gugod@gugod.org}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_libravatar.rb
CHANGED
@@ -38,8 +38,14 @@ class TestLibravatar < Test::Unit::TestCase
|
|
38
38
|
assert_equal x.send(:normalize_openid, "HTTP://EXAMPLE.COM"), "http://example.com/"
|
39
39
|
end
|
40
40
|
|
41
|
-
should "
|
41
|
+
should "Return the federated URI" do
|
42
42
|
avatar = Libravatar.new(:email => 'invalid@catalyst.net.nz')
|
43
43
|
assert_equal avatar.to_s, 'http://static.avatars.catalyst.net.nz/avatar/f924d1e9f2c10ee9efa7acdd16484c2f'
|
44
44
|
end
|
45
|
+
|
46
|
+
should "Sanitize the SRV lookup result" do
|
47
|
+
avatar = Libravatar.new
|
48
|
+
assert_equal ["hosntame.abcde.fghi.com", 12345], avatar.send(:sanitize_srv_lookup, "hosntame.abcde.fghi.com", 12345)
|
49
|
+
assert_equal [nil, nil], avatar.send(:sanitize_srv_lookup, "FNORD IMPUNTK *#(*$#&", 65348283)
|
50
|
+
end
|
45
51
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libravatar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kang-min Liu
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-24 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|