libravatar 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Kang-min Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ = libravatar
2
+
3
+ http://libravatar.org is an avatar service to let their users associate avatar images
4
+ with their emails or openids. This rubygem generates their avatar URL.
5
+
6
+ == Contributing to libravatar
7
+
8
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
9
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
10
+ * Fork the project
11
+ * Start a feature/bugfix branch
12
+ * Commit and push until you are happy with your contribution
13
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
14
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2011 Kang-min Liu. See LICENSE.txt for
19
+ further details.
20
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
7
+ gem.name = "libravatar"
8
+ gem.homepage = "http://github.com/gugod/libravatar"
9
+ gem.license = "MIT"
10
+ gem.summary = %Q{Avatar URL Generation wih libravatar.org}
11
+ gem.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}
12
+ gem.email = "gugod@gugod.org"
13
+ gem.authors = ["Kang-min Liu"]
14
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
15
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
16
+ # gem.add_runtime_dependency 'digest/sha2', '> 0.1'
17
+ # gem.add_runtime_dependency 'uri', '> 0.1'
18
+ gem.add_development_dependency 'shoulda', '> 1.2.3'
19
+ end
20
+ Jeweler::RubygemsDotOrgTasks.new
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "libravatar #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/lib/libravatar.rb ADDED
@@ -0,0 +1,59 @@
1
+ #
2
+ # The Libravatar class generates the avatar URL provided by the libravatar
3
+ # web service at http://www.libravatar.org
4
+ #
5
+ # Users may associate their avatar images with multiple OpenIDs and Emails.
6
+ #
7
+ # Author:: Kang-min Liu (http://gugod.org)
8
+ # Copyright:: Copyright (c) 2011 Kang-min Liu
9
+ # License:: MIT
10
+ #
11
+
12
+ require 'digest/sha2'
13
+ require 'uri'
14
+
15
+ class Libravatar
16
+ attr_accessor :email, :openid, :size, :default
17
+
18
+ # The options should contain :email or :openid values. If both are
19
+ # given, email will be used. The value of openid and email will be
20
+ # normalized by the rule described in http://www.libravatar.org/api
21
+ #
22
+ # List of option keys:
23
+ #
24
+ # - :email
25
+ # - :openid
26
+ # - :size An integer ranged 1 - 512, default is 80.
27
+ #
28
+ def initialize(options = {})
29
+ @email = options[:email]
30
+ @openid = options[:openid]
31
+ @size = options[:size]
32
+ @default = options[:default]
33
+ end
34
+
35
+ # Generate the libravatar URL
36
+ def to_s
37
+ @email.downcase! if @email
38
+ id = Digest::SHA2.hexdigest(@email || normalize_openid(@openid))
39
+ s = @size ? "s=#{@size}" : nil
40
+ d = @default ? "d=#{@default}" : nil
41
+
42
+ query = [s,d].reject{|x|!x}.join("&")
43
+ query = "?#{query}" unless query == ""
44
+ return "http://cdn.libravatar.org/avatar/" + id + query
45
+ end
46
+
47
+ private
48
+
49
+ # Normalize an openid URL following the description on libravatar.org
50
+ def normalize_openid(s)
51
+ x = URI.parse(s)
52
+ x.host.downcase!
53
+ x.scheme = x.scheme.downcase
54
+ if (x.path == "" && x.fragment == nil)
55
+ x.path = "/"
56
+ end
57
+ return x.to_s
58
+ end
59
+ end
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{libravatar}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kang-min Liu"]
12
+ s.date = %q{2011-04-15}
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
+ s.email = %q{gugod@gugod.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE.txt",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/libravatar.rb",
26
+ "libravatar.gemspec",
27
+ "test/helper.rb",
28
+ "test/test_libravatar.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/gugod/libravatar}
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.6.1}
34
+ s.summary = %q{Avatar URL Generation wih libravatar.org}
35
+ s.test_files = [
36
+ "test/helper.rb",
37
+ "test/test_libravatar.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<shoulda>, ["> 1.2.3"])
45
+ else
46
+ s.add_dependency(%q<shoulda>, ["> 1.2.3"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<shoulda>, ["> 1.2.3"])
50
+ end
51
+ end
52
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'libravatar'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,34 @@
1
+ require 'helper'
2
+
3
+ class TestLibravatar < Test::Unit::TestCase
4
+ should "Generate url from email" do
5
+ # echo -n "user@example.com"|shasum -a 256
6
+ # => b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514
7
+ avatar = Libravatar.new(:email => "user@example.com")
8
+ assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514"
9
+
10
+ assert_equal Libravatar.new(:email => "USER@ExAmPlE.CoM").to_s, "http://cdn.libravatar.org/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514"
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"
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"
15
+ end
16
+
17
+ should "Generate url from openid" do
18
+ avatar = Libravatar.new(:openid => "http://example.com/id/Bob")
19
+ assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd"
20
+
21
+ avatar = Libravatar.new(:openid => "hTTp://EXAMPLE.COM/id/Bob")
22
+ assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd"
23
+
24
+ avatar = Libravatar.new(:openid => "hTTp://EXAMPLE.COM/id/Bob", :size => 512)
25
+ assert_equal avatar.to_s, "http://cdn.libravatar.org/avatar/80cd0679bb52beac4d5d388c163016dbc5d3f30c262a4f539564236ca9d49ccd?s=512"
26
+ end
27
+
28
+ should "Normalize OpenID" do
29
+ x = Libravatar.new
30
+ assert_equal x.send(:normalize_openid, "HTTP://EXAMPLE.COM/id/Bob"), "http://example.com/id/Bob"
31
+
32
+ assert_equal x.send(:normalize_openid, "HTTP://EXAMPLE.COM"), "http://example.com/"
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libravatar
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Kang-min Liu
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-15 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 3
34
+ version: 1.2.3
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: 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
38
+ email: gugod@gugod.org
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE.txt
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - LICENSE.txt
49
+ - README.rdoc
50
+ - Rakefile
51
+ - VERSION
52
+ - lib/libravatar.rb
53
+ - libravatar.gemspec
54
+ - test/helper.rb
55
+ - test/test_libravatar.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/gugod/libravatar
58
+ licenses:
59
+ - MIT
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.6.1
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Avatar URL Generation wih libravatar.org
90
+ test_files:
91
+ - test/helper.rb
92
+ - test/test_libravatar.rb