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 CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -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
- @email.downcase! if @email
38
- id = Digest::SHA2.hexdigest(@email || normalize_openid(@openid))
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
- return "http://cdn.libravatar.org/avatar/" + id + query
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
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{libravatar}
8
- s.version = "1.0.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-15}
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 = [
@@ -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"|shasum -a 256
6
- # => b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514
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/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514"
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/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514"
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 => "USER@ExAmPlE.CoM", :default => "http://example.com/avatar.png").to_s, "http://cdn.libravatar.org/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?d=http://example.com/avatar.png"
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 => "USER@ExAmPlE.CoM", :size => 512, :default => "mm").to_s, "http://cdn.libravatar.org/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?s=512&d=mm"
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.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-15 00:00:00 +08:00
18
+ date: 2011-04-19 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency