gravity 0.1.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/.gitignore +5 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +77 -0
- data/Rakefile +26 -0
- data/gravity.gemspec +22 -0
- data/init.rb +2 -0
- data/lib/gravity.rb +77 -0
- data/lib/gravity/version.rb +3 -0
- data/test/gravity_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +90 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
Gravity
|
2
|
+
=======
|
3
|
+
|
4
|
+
Gravity is a simple [Gravatar](http://gravatar.com) plugin for Rails. It allows you to easily get Gravatar images and profile informations.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
============
|
8
|
+
|
9
|
+
Just add it to your Gemfile like this:
|
10
|
+
|
11
|
+
gem "gravity"
|
12
|
+
|
13
|
+
and you're ready to go.
|
14
|
+
|
15
|
+
Usage
|
16
|
+
====
|
17
|
+
|
18
|
+
In your model:
|
19
|
+
|
20
|
+
class User < ActiveRecord::Base
|
21
|
+
has_gravatar
|
22
|
+
end
|
23
|
+
|
24
|
+
In your views:
|
25
|
+
|
26
|
+
<%= image_tag @user.gravatar_image %>
|
27
|
+
<%= @user.gravatar_profile['displayName'] %>
|
28
|
+
|
29
|
+
This works if you have an `email` field in your model. To use a different field for email, pass the field name to the `:email` option:
|
30
|
+
|
31
|
+
class User < ActiveRecord::Base
|
32
|
+
has_gravatar :email => :email_address
|
33
|
+
end
|
34
|
+
|
35
|
+
You can also pass options to the ´gravatar_image´ and ´gravatar_profile´ methods:
|
36
|
+
|
37
|
+
<%= image_tag @user.gravatar_image :size => 40, :default => 'identicon' %>
|
38
|
+
<%= @user.gravatar_profile(:secure => true)['displayName'] %>
|
39
|
+
|
40
|
+
Here is a complete list of options:
|
41
|
+
|
42
|
+
<table width="100%">
|
43
|
+
<thead>
|
44
|
+
<th>Option</th>
|
45
|
+
<th>Description</th>
|
46
|
+
<th>Default</th>
|
47
|
+
<th>Values<th>
|
48
|
+
</tr>
|
49
|
+
<tr>
|
50
|
+
<td><b>secure</b></td>
|
51
|
+
<td>Use SSL to call gravatar.org</td>
|
52
|
+
<td>false</td>
|
53
|
+
<td>true/false</td>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td><b>size</b> or <b>s</b></td>
|
57
|
+
<td>The size of the image</td>
|
58
|
+
<td>80</td>
|
59
|
+
<td>1..512</td>
|
60
|
+
</tr>
|
61
|
+
<tr>
|
62
|
+
<td><b>default</b> or <b>d</b></td>
|
63
|
+
<td>The avatar image used by default</td>
|
64
|
+
<td><i>none</i></td>
|
65
|
+
<td>"identicon", "monsterid", "wavatar" or an absolute URL.</td>
|
66
|
+
</tr>
|
67
|
+
<tr>
|
68
|
+
<td><b>rating</b> or <b>r</b></td>
|
69
|
+
<td>The lowest level of ratings you want to allow</td>
|
70
|
+
<td>G</td>
|
71
|
+
<td>G, PG, R or X</td>
|
72
|
+
</tr>
|
73
|
+
</table>
|
74
|
+
|
75
|
+
See the [Gravatar site](gravatar.com/site/implement/images) for more informations.
|
76
|
+
|
77
|
+
Copyright (c) 2011 Giuseppe Capizzi, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
require 'bundler'
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
desc 'Default: run unit tests.'
|
9
|
+
task :default => :test
|
10
|
+
|
11
|
+
desc 'Test the gravity plugin.'
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.libs << 'lib'
|
14
|
+
t.libs << 'test'
|
15
|
+
t.pattern = 'test/**/*_test.rb'
|
16
|
+
t.verbose = true
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Generate documentation for the gravity plugin.'
|
20
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
21
|
+
rdoc.rdoc_dir = 'rdoc'
|
22
|
+
rdoc.title = 'Gravity'
|
23
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
24
|
+
rdoc.rdoc_files.include('README')
|
25
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
|
+
end
|
data/gravity.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "gravity/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "gravity"
|
7
|
+
s.version = Gravity::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Giuseppe Capizzi"]
|
10
|
+
s.email = ["g.capizzi@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/gcapizzi/gravity"
|
12
|
+
s.summary = %q{A simple gravatar plugin for Rails.}
|
13
|
+
s.description = %q{A simple gravatar plugin for Rails.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "gravity"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.add_dependency("json")
|
22
|
+
end
|
data/init.rb
ADDED
data/lib/gravity.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require "net/http"
|
3
|
+
require "net/https"
|
4
|
+
require "uri"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module Gravity
|
8
|
+
def self.included(base)
|
9
|
+
base.send :extend, ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
attr_accessor :gravatar_options
|
14
|
+
|
15
|
+
def has_gravatar options = {}
|
16
|
+
send :include, InstanceMethods
|
17
|
+
|
18
|
+
self.gravatar_options = {
|
19
|
+
:email => :email,
|
20
|
+
:secure => false
|
21
|
+
}.merge(options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module InstanceMethods
|
26
|
+
def gravatar_hash(email)
|
27
|
+
Digest::MD5.hexdigest email.to_s.strip.downcase
|
28
|
+
end
|
29
|
+
|
30
|
+
def gravatar_url(secure)
|
31
|
+
'http' + (secure ? 's://secure.' : '://') + 'gravatar.com/'
|
32
|
+
end
|
33
|
+
|
34
|
+
def gravatar_image(options = {})
|
35
|
+
options = self.class.gravatar_options.merge options
|
36
|
+
email = self.send options.delete(:email)
|
37
|
+
secure = options.delete :secure
|
38
|
+
url = gravatar_url(secure) + 'avatar/' + gravatar_hash(email)
|
39
|
+
|
40
|
+
if !options.empty?
|
41
|
+
url += '?' + options.map{|o, v| "#{o}=#{v.to_s}"}.join('&')
|
42
|
+
end
|
43
|
+
|
44
|
+
url
|
45
|
+
end
|
46
|
+
|
47
|
+
def gravatar_profile(options = {})
|
48
|
+
options = self.class.gravatar_options.merge options
|
49
|
+
|
50
|
+
email = self.send options.delete(:email)
|
51
|
+
secure = options.delete :secure
|
52
|
+
url = gravatar_url(secure) + gravatar_hash(email) + '.json'
|
53
|
+
|
54
|
+
json_profile = JSON.parse get(url)
|
55
|
+
json_profile['entry'].first
|
56
|
+
end
|
57
|
+
|
58
|
+
def get(url)
|
59
|
+
uri = URI.parse(url)
|
60
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
61
|
+
if uri.scheme == 'https'
|
62
|
+
http.use_ssl = true
|
63
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
64
|
+
end
|
65
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
66
|
+
response = http.request(request)
|
67
|
+
|
68
|
+
if response.kind_of?(Net::HTTPRedirection)
|
69
|
+
get response['location']
|
70
|
+
else
|
71
|
+
response.body
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
ActiveRecord::Base.send :include, Gravity
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gravity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Giuseppe Capizzi
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-24 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: A simple gravatar plugin for Rails.
|
35
|
+
email:
|
36
|
+
- g.capizzi@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- MIT-LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- gravity.gemspec
|
50
|
+
- init.rb
|
51
|
+
- lib/gravity.rb
|
52
|
+
- lib/gravity/version.rb
|
53
|
+
- test/gravity_test.rb
|
54
|
+
- test/test_helper.rb
|
55
|
+
homepage: http://github.com/gcapizzi/gravity
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: gravity
|
84
|
+
rubygems_version: 1.7.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: A simple gravatar plugin for Rails.
|
88
|
+
test_files:
|
89
|
+
- test/gravity_test.rb
|
90
|
+
- test/test_helper.rb
|