gravatar_profile 1.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/CHANGELOG.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ === 0.1 / 2010-11-29
2
+ + Initial release
data/README.rdoc ADDED
@@ -0,0 +1,45 @@
1
+ = Author
2
+ Veerasundaravel Thirugnanasundaram <veerasundaravel@gmail.cm>
3
+ http://veerasundaravel.wordpress.com
4
+
5
+ = Synopsis
6
+ gravatar_profile is a Ruby Wrapper for getting GRAVATAR[http://gravatar.com] avatars and profile informations.
7
+
8
+ By passing the user email you can get the gravatar image, gravatar profile url and as well as profile informations also.
9
+
10
+
11
+ = Usage
12
+ Using the GravatarProfile library is fairly simple and straight-forward. The base
13
+ class most of you will be using is the GravatarProfile class.
14
+
15
+ === Installation
16
+ sudo gem install gravatar_profile
17
+
18
+ ===Getting Gravatar image
19
+
20
+ gravatar = GravatarProfile.new("your-email-address")
21
+ gp.gravatar_url
22
+ >> "http://gravatar.com/avatar/6fa14cea01672568042121f81c33d5fbb.png"
23
+
24
+
25
+ === Getting Gravatar Profile Url
26
+
27
+ gp = GravatarProfile.new("your-email-address"")
28
+ gp.gravatar_profile_url
29
+ >> "http://gravatar.com/6fa14cea01672568042121f81c33d5fbb"
30
+
31
+ gp = GravatarProfile.new("your-email-address"")
32
+ gp.gravatar_profile_url(:filetype => :xml)
33
+ >> "http://gravatar.com/6fa14cea01672568042121f81c33d5fbb"
34
+
35
+
36
+ === Accessing profile informations
37
+
38
+ gp = GravatarProfile.new("some-email-address")
39
+
40
+ #For now we are supporting only the XML format profile details
41
+ gp.get_profile_info({:filetype => :xml})
42
+
43
+ #If your server need to use proxyy means specify the proxy details as follows.
44
+ gp.get_profile_info({:proxy_host => 'www.some-proxy.com', :proxy_port=>8000, :filetype => :xml})
45
+ >> {"name"=>[{"givenName"=>["User-GivenName"], "familyName"=>["FamilyName"], "formatted"=>["User-GivenName Lastname"]}], "requestHash"=>["6fa14cea067256804121f81c33d5fbb"], "preferredUsername"=>["user-givenname"], "displayName"=>["user-givenname"], "thumbnailUrl"=>["http://2.gravatar.com/avatar/6fadss14cea0167256804121f81c3d5fbb"], "hash"=>["6fadss14cea0167256804121f81c33d5fbb"], "urls"=>[{"value"=>["http://in.linkedin.com/pub/abced/8/11b/15"]}, {"title"=>["Ruby on Rails Weblog"], "value"=["http://user-givenname.wordpress.com"]}, {"title"=>["Twitter Account"], "value"=>["http://twitter.com/user-givenname"]}], "ims"=>[{"type"=>["yahoo"], "value"=>["some-name2003"]} {"type"=>["gtalk"], "value"=>["some-name2003"]}, {"type"=>["skype"], "value"=>["user-givenname"]}], "emails"=>[{"primary"=>["true"], "value"=>["some-name2003@gmail.com"]}], "photos">[{"type"=>["thumbnail"], "value"=>["http://2.gravatar.com/avatar/6fadss14cea0167256804121f81c33d5fbb"]}, {"value"=>["http://2.gravatar.com/userimage/5146707/c647651ea2579f4900cc05f766a3b23"]}], "id"=>["5146707"], "accounts"=>[{"shortname"=>["facebook"], "url"=>["http://www.facebook.com/profile.php?id=5523354779"], "username"=>["facebook.com"], "domain"=>[facebook.com"], "display"=>["facebook.com"], "verified"=>["true"]}, {"shortname"=>["linkedin"], "url"=>["http://www.linkedin.com/in/user-givenname"], "username"=>["usernameel"], "domain"=>["linkedin.com"], "display"=>["user-givenname"], "verified"=>["true"]}, {"shortname"=>["twitter"], "url"=>["http://twitter.com/user-givenname"], "username"=>["eerasundaravel"], "domain"=>["twitter.com"], "display"=>["@user-givenname"], "verified"=>["true"]}, {"shortname"=>["wordpress"], "url"=>["http://user-givenname.wordpress.com/", "username"=>["user-givenname.wordpress.com"], "domain"=>["user-givenname.wordpress.com"], "display"=>["user-givenname.wordpress.com"], "verified"=>["true"]}], "currentLocaton"=>["Location1, Country"], "aboutMe"=>["About me text goes here"], "phoneNumbers"=>[{"type"=>["mobile"], "value"=>["9894873774"]}], "profileUrl"=>["http://gravatar.com/user-givenname"]}
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{gravatar_profile}
5
+ s.version = "1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Veerasundaravel Thirugnanasundaram"]
9
+ s.date = %q{2010-11-29}
10
+ s.description = %q{gravatar_profile is a Ruby Wrapper for getting GRAVATAR[http://gravatar.com] avatars and profile informations.}
11
+ s.email = ["veerasundaravel@gmail.com"]
12
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", ]
13
+ s.files = ["CHANGELOG.rdoc", "README.rdoc", "gravatar_profile.gemspec", "lib/gravatar_profile.rb"]
14
+ s.homepage = %q{http://veerasundaravel.wordpress.com}
15
+ s.rdoc_options = ["--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{gravatar_profile}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{gravatar_profile is a Ruby Wrapper for getting GRAVATAR[http://gravatar.com] avatars and profile informations. by Veerasundaravel Thirugnanasundaram}
20
+ s.test_files = []
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 1
25
+ s.add_development_dependency(%q<xml-simple>, [">= 1.0.0"])
26
+ else
27
+ s.add_dependency(%q<xml-simple>, [">= 1.0.0"])
28
+ end
29
+ end
@@ -0,0 +1,96 @@
1
+ require 'digest/md5'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'xmlsimple'
5
+
6
+ class GravatarProfile
7
+ DefaultOptions = {
8
+ :rating => 'PG',
9
+ :secure => false,
10
+ :filetype => :png,
11
+ :size => 80
12
+ }
13
+
14
+ def gravatar_abbreviations
15
+ { :size => 's',
16
+ :default => 'd',
17
+ :rating => 'r'
18
+ }
19
+ end
20
+
21
+
22
+ attr_accessor :email, :id
23
+
24
+ def initialize(email = '', options = {})
25
+
26
+ @email = email
27
+ @id = gravatar_id
28
+
29
+ end
30
+
31
+ def gravatar_id
32
+ Digest::MD5.hexdigest(email.to_s.downcase)
33
+ end
34
+
35
+ # Constructs the full Gravatar url.
36
+ def gravatar_url(options={})
37
+ options = GravatarProfile::DefaultOptions.merge(options)
38
+ gravatar_hostname(options.delete(:secure)) +
39
+ gravatar_filename(options.delete(:filetype)) +
40
+ url_params_from_hash(options)
41
+ end
42
+
43
+ # Constructs the full Gravatar url.
44
+ def gravatar_profile_url(options={})
45
+ options = GravatarProfile::DefaultOptions.merge(options)
46
+ gravatar_hostname(options.delete(:secure)) +
47
+ gravatar_profilename(options.delete(:filetype))
48
+ end
49
+
50
+ def get_profile_info(options={})
51
+ options = GravatarProfile::DefaultOptions.merge(options)
52
+ proxy_host = options.delete(:proxy_host)
53
+ proxy_port = options.delete(:proxy_port)
54
+
55
+ url = URI.parse("http://en.gravatar.com")
56
+ res = Net::HTTP::Proxy(proxy_host, proxy_port).start(url.host, url.port) {|http|
57
+ http.get(gravatar_profilename(options.delete(:filetype)))
58
+ }
59
+
60
+ if res.msg == "OK"
61
+ profile_data = XmlSimple.xml_in(res.body)
62
+ if profile_data["entry"]
63
+ return profile_data["entry"].first
64
+ end
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ # Creates a params hash like "?foo=bar" from a hash like {'foo' => 'bar'}.
71
+ # The values are sorted so it produces deterministic output (and can
72
+ # therefore be tested easily).
73
+ def url_params_from_hash(hash)
74
+ '?' + hash.map do |key, val|
75
+ [gravatar_abbreviations[key.to_sym] || key.to_s, val.to_s ].join('=')
76
+ end.sort.join('&')
77
+ end
78
+
79
+ # Returns either Gravatar's secure hostname or not.
80
+ def gravatar_hostname(secure)
81
+ 'http' + (secure ? 's://secure.' : '://') + 'gravatar.com'
82
+ end
83
+
84
+ # Joins the ID and the filetype into one. Like "profile.png"
85
+ def gravatar_filename(filetype)
86
+ "/avatar/#{gravatar_id}.#{filetype}"
87
+ end
88
+
89
+ def gravatar_profilename(filetype)
90
+ if filetype
91
+ "/#{gravatar_id}.#{filetype}"
92
+ else
93
+ "/#{gravatar_id}"
94
+ end
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gravatar_profile
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ version: "1.0"
9
+ platform: ruby
10
+ authors:
11
+ - Veerasundaravel Thirugnanasundaram
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-11-29 00:00:00 +05:30
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: xml-simple
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 1
28
+ - 0
29
+ - 0
30
+ version: 1.0.0
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: gravatar_profile is a Ruby Wrapper for getting GRAVATAR[http://gravatar.com] avatars and profile informations.
34
+ email:
35
+ - veerasundaravel@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - CHANGELOG.rdoc
42
+ - README.rdoc
43
+ files:
44
+ - CHANGELOG.rdoc
45
+ - README.rdoc
46
+ - gravatar_profile.gemspec
47
+ - lib/gravatar_profile.rb
48
+ has_rdoc: true
49
+ homepage: http://veerasundaravel.wordpress.com
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --main
55
+ - README.rdoc
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project: gravatar_profile
75
+ rubygems_version: 1.3.6
76
+ signing_key:
77
+ specification_version: 1
78
+ summary: gravatar_profile is a Ruby Wrapper for getting GRAVATAR[http://gravatar.com] avatars and profile informations. by Veerasundaravel Thirugnanasundaram
79
+ test_files: []
80
+