libravatar 1.0.0 → 1.0.1
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 +13 -4
- data/libravatar.gemspec +2 -2
- data/test/test_libravatar.rb +12 -6
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/libravatar.rb
CHANGED
@@ -9,11 +9,12 @@
|
|
9
9
|
# License:: MIT
|
10
10
|
#
|
11
11
|
|
12
|
+
require 'digest/md5'
|
12
13
|
require 'digest/sha2'
|
13
14
|
require 'uri'
|
14
15
|
|
15
16
|
class Libravatar
|
16
|
-
attr_accessor :email, :openid, :size, :default
|
17
|
+
attr_accessor :email, :openid, :size, :default, :https
|
17
18
|
|
18
19
|
# The options should contain :email or :openid values. If both are
|
19
20
|
# given, email will be used. The value of openid and email will be
|
@@ -24,24 +25,32 @@ class Libravatar
|
|
24
25
|
# - :email
|
25
26
|
# - :openid
|
26
27
|
# - :size An integer ranged 1 - 512, default is 80.
|
28
|
+
# - :https Set to true to serve avatars over SSL
|
29
|
+
# - :default URL to redirect missing avatars to, or one of these specials: "404", "mm", "identicon", "monsterid", "wavatar", "retro"
|
27
30
|
#
|
28
31
|
def initialize(options = {})
|
29
32
|
@email = options[:email]
|
30
33
|
@openid = options[:openid]
|
31
34
|
@size = options[:size]
|
32
35
|
@default = options[:default]
|
36
|
+
@https = options[:https]
|
33
37
|
end
|
34
38
|
|
35
39
|
# Generate the libravatar URL
|
36
40
|
def to_s
|
37
|
-
|
38
|
-
|
41
|
+
if @email
|
42
|
+
@email.downcase!
|
43
|
+
id = Digest::MD5.hexdigest(@email)
|
44
|
+
else
|
45
|
+
id = Digest::SHA2.hexdigest(normalize_openid(@openid))
|
46
|
+
end
|
39
47
|
s = @size ? "s=#{@size}" : nil
|
40
48
|
d = @default ? "d=#{@default}" : nil
|
41
49
|
|
42
50
|
query = [s,d].reject{|x|!x}.join("&")
|
43
51
|
query = "?#{query}" unless query == ""
|
44
|
-
|
52
|
+
baseurl = @https ? "https://seccdn.libravatar.org/avatar/" : "http://cdn.libravatar.org/avatar/"
|
53
|
+
return baseurl + id + query
|
45
54
|
end
|
46
55
|
|
47
56
|
private
|
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.0.
|
8
|
+
s.version = "1.0.1"
|
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-04-
|
12
|
+
s.date = %q{2011-04-19}
|
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
@@ -2,19 +2,25 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestLibravatar < Test::Unit::TestCase
|
4
4
|
should "Generate url from email" do
|
5
|
-
# echo -n "user@example.com"|
|
6
|
-
# =>
|
5
|
+
# echo -n "user@example.com"|md5sum
|
6
|
+
# => b58996c504c5638798eb6b511e6f49af
|
7
7
|
avatar = Libravatar.new(:email => "user@example.com")
|
8
|
-
assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/
|
8
|
+
assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af"
|
9
9
|
|
10
|
-
assert_equal Libravatar.new(:email => "USER@ExAmPlE.CoM").to_s, "http://cdn.libravatar.org/avatar/
|
10
|
+
assert_equal Libravatar.new(:email => "USER@ExAmPlE.CoM").to_s, "http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af"
|
11
11
|
|
12
|
-
assert_equal Libravatar.new(:email => "
|
12
|
+
assert_equal Libravatar.new(:email => "user@example.com", :https => true).to_s, "https://seccdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af"
|
13
13
|
|
14
|
-
assert_equal Libravatar.new(:email => "
|
14
|
+
assert_equal Libravatar.new(:email => "user@example.com", :https => false).to_s, "http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af"
|
15
|
+
|
16
|
+
assert_equal Libravatar.new(:email => "USER@ExAmPlE.CoM", :default => "http://example.com/avatar.png").to_s, "http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af?d=http://example.com/avatar.png"
|
17
|
+
|
18
|
+
assert_equal Libravatar.new(:email => "USER@ExAmPlE.CoM", :size => 512, :default => "mm").to_s, "http://cdn.libravatar.org/avatar/b58996c504c5638798eb6b511e6f49af?s=512&d=mm"
|
15
19
|
end
|
16
20
|
|
17
21
|
should "Generate url from openid" do
|
22
|
+
# echo -n "http://example.com/id/Bob"|shasum -a 256
|
23
|
+
# => 80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd
|
18
24
|
avatar = Libravatar.new(:openid => "http://example.com/id/Bob")
|
19
25
|
assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd"
|
20
26
|
|
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: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
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-04-
|
18
|
+
date: 2011-04-19 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|