aggravatar 0.1.0 → 1.0.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/.gitignore CHANGED
@@ -1,5 +1,17 @@
1
- *.sw?
2
- .DS_Store
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
3
9
  coverage
4
- rdoc
10
+ doc/
11
+ lib/bundler/man
5
12
  pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aggravatar.gemspec
4
+ gemspec
@@ -1,5 +1,7 @@
1
1
  Copyright (c) 2009 Adam Tanner
2
2
 
3
+ MIT License
4
+
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
5
7
  "Software"), to deal in the Software without restriction, including
@@ -0,0 +1,37 @@
1
+ # Aggravatar
2
+
3
+ You give it an email, it gives you a Gravatar URL. What more do you want?
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'aggravatar'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install aggravatar
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require "aggravatar"
23
+
24
+ Aggravatar.gravatar_url "adam@adamtanner.org", size: 200, rating: "g", force_default: true
25
+ # => "http://www.gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88?size=200&rating=g&forcedefault=y
26
+
27
+ Aggravatar.secure_gravatar_url "adam@adamtanner.org", default: "http://example.com/images/avatar.jpg"
28
+ # => "https://secure.gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88?default=http%3A%2F%2Fexample.com%2Fimages%2Favatar.jpg"
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,44 +1,6 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "aggravatar"
8
- gem.summary = %Q{TODO: one-line summary of your gem}
9
- gem.description = %Q{TODO: longer description of your gem}
10
- gem.email = "adam@adamtanner.org"
11
- gem.homepage = "http://github.com/cxvii/aggravatar"
12
- gem.authors = ["Adam Tanner"]
13
- gem.add_development_dependency "rspec"
14
- gem.add_development_dependency "yard"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
- end
20
-
21
- require 'spec/rake/spectask'
22
- Spec::Rake::SpecTask.new(:spec) do |spec|
23
- spec.libs << 'lib' << 'spec'
24
- spec.spec_files = FileList['spec/**/*_spec.rb']
25
- end
26
-
27
- Spec::Rake::SpecTask.new(:rcov) do |spec|
28
- spec.libs << 'lib' << 'spec'
29
- spec.pattern = 'spec/**/*_spec.rb'
30
- spec.rcov = true
31
- end
32
-
33
- task :spec => :check_dependencies
34
-
35
- task :default => :spec
36
-
37
- begin
38
- require 'yard'
39
- YARD::Rake::YardocTask.new
40
- rescue LoadError
41
- task :yardoc do
42
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
43
- end
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "spec/**/*_spec.rb"
44
6
  end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aggravatar/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "aggravatar"
8
+ gem.version = Aggravatar::VERSION
9
+ gem.authors = ["Adam Tanner"]
10
+ gem.email = ["adam@adamtanner.org"]
11
+ gem.description = %q{ You give it an email, it gives you a Gravatar URL. What more do you want? }
12
+ gem.summary = %q{ You give it an email, it gives you a Gravatar URL. What more do you want? }
13
+ gem.homepage = "http://github.com/adamtanner/aggravatar"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -1,51 +1,12 @@
1
- module Aggravatar
2
- def self.included(base)
3
- base.send(:include, InstanceMethods)
4
- end
5
-
6
- def self.host
7
- "gravatar.com"
8
- end
1
+ require "aggravatar/version"
2
+ require "aggravatar/gravatar"
9
3
 
10
- def self.path(email_hash)
11
- "/avatar/#{email_hash}"
4
+ module Aggravatar
5
+ def self.gravatar_url(email, params = {})
6
+ Aggravatar::Gravatar.new(email, params).url
12
7
  end
13
-
14
- module InstanceMethods
15
- require 'MD5'
16
- require 'URI'
17
-
18
- def gravatar_for(email, options={})
19
- build_image_tag(hash(email), options)
20
- end
21
-
22
- private
23
- def hash(email)
24
- MD5.md5(email.strip)
25
- end
26
-
27
- def build_image_tag(email_hash, options={})
28
- "<img src=\"#{build_url(email_hash, options)}\" #{build_tag_attributes(options[:html_attributes])}/>"
29
- end
30
8
 
31
- def build_tag_attributes(attributes)
32
- return nil if attributes.nil?
33
- attributes.inject([]){|array, attribute| array << "#{attribute[0].to_s}=\"#{attribute[1]}\""}.join(" ")
34
- end
35
-
36
- def build_query(query_options)
37
- query_options = query_options.reject{|key, value| key == :html_attributes}
38
- return nil if query_options.empty?
39
- query_options[:default] = URI.escape(query_options[:default], ":/")
40
- query_options.inject([]){|array, option| array << "#{option[0].to_s[0].chr}=#{option[1]}"}.join("&")
41
- end
42
-
43
- def build_url(email_hash, query)
44
- uri = URI::HTTP.build(
45
- :host => Aggravatar.host,
46
- :path => Aggravatar.path(email_hash),
47
- :query => build_query(query)
48
- )
49
- end
9
+ def self.secure_gravatar_url(email, params = {})
10
+ Aggravatar::Gravatar.new(email, params).secure_url
50
11
  end
51
12
  end
@@ -0,0 +1,55 @@
1
+ require "digest/md5"
2
+
3
+ class Aggravatar::Gravatar
4
+ attr_reader :email
5
+
6
+ def initialize(email, params = {})
7
+ @email = email
8
+ @params = params
9
+ end
10
+
11
+ def email_hash
12
+ Digest::MD5.hexdigest email
13
+ end
14
+
15
+ def url
16
+ uri = URI::HTTP.build(
17
+ host: "www.gravatar.com",
18
+ path: avatar_path
19
+ )
20
+
21
+ uri.query = build_query unless @params.empty?
22
+
23
+ uri.to_s
24
+ end
25
+
26
+ def secure_url
27
+ uri = URI::HTTPS.build(
28
+ host: "secure.gravatar.com",
29
+ path: avatar_path
30
+ )
31
+
32
+ uri.query = build_query unless @params.empty?
33
+
34
+ uri.to_s
35
+ end
36
+
37
+ private
38
+ def avatar_path
39
+ "/avatar/#{email_hash}"
40
+ end
41
+
42
+ def build_query
43
+ URI.encode_www_form normalized_params
44
+ end
45
+
46
+ def normalized_params
47
+ params = @params.dup
48
+
49
+ if params.delete(:force_default)
50
+ params[:forcedefault] = "y"
51
+ end
52
+
53
+ params
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Aggravatar
2
+ VERSION = "1.0.0"
3
+ end
@@ -1,29 +1,17 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "aggravatar.rb")
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+ require "aggravatar"
3
4
 
4
- describe "Aggravatar" do
5
- before(:all) do
6
- class Helper
7
- include Aggravatar
8
- end
9
- @helper = Helper.new
10
- end
5
+ describe Aggravatar do
6
+ it "provides a Gravatar URL" do
7
+ url = Aggravatar.gravatar_url "adam@adamtanner.org"
11
8
 
12
- it "should make an image tag for a vanilla Gravatar" do
13
- valid_image_tag = "<img src=\"http://gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88\" />"
14
- image_tag = @helper.gravatar_for("adam@adamtanner.org")
15
- image_tag.should == valid_image_tag
9
+ url.must_equal "http://www.gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88"
16
10
  end
17
11
 
18
- it "should make an image tag for a Gravatar using parameters" do
19
- valid_image_tag = "<img src=\"http://gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88?d=http%3A%2F%2Fexample.com%2Fimages%2Fdefault.jpg&r=g&s=50\" />"
20
- image_tag = @helper.gravatar_for("adam@adamtanner.org", :rating => "g", :default => "http://example.com/images/default.jpg", :size => 50)
21
- image_tag.should == valid_image_tag
22
- end
12
+ it "provides a secure Gravatar URL" do
13
+ url = Aggravatar.secure_gravatar_url "adam@adamtanner.org"
23
14
 
24
- it "should make an image tag for a Gravatar using custom HTML attributes" do
25
- valid_image_tag = "<img src=\"http://gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88\" class=\"gravatar\" id=\"my_gravatar\"/>"
26
- image_tag = @helper.gravatar_for("adam@adamtanner.org", :html_attributes => {:class => "gravatar", :id => "my_gravatar"})
27
- image_tag.should == valid_image_tag
15
+ url.must_equal "https://secure.gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88"
28
16
  end
29
17
  end
@@ -0,0 +1,79 @@
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+ require "aggravatar"
4
+
5
+ describe Aggravatar::Gravatar do
6
+ it "has an email" do
7
+ email = "adam@adamtanner.org"
8
+ gravatar = Aggravatar::Gravatar.new(email)
9
+
10
+ gravatar.email.must_equal email
11
+ end
12
+
13
+ it "has a hash of the email" do
14
+ email = "adam@adamtanner.org"
15
+ hash = "11591979f29ab9c2bb58868232d07b88"
16
+ gravatar = Aggravatar::Gravatar.new(email)
17
+
18
+ gravatar.email_hash.must_equal hash
19
+ end
20
+
21
+ it "builds a Gravatar URL" do
22
+ email = "adam@adamtanner.org"
23
+ gravatar = Aggravatar::Gravatar.new(email)
24
+
25
+ gravatar.url.must_equal "http://www.gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88"
26
+ end
27
+
28
+ it "builds a secure Gravatar URL" do
29
+ email = "adam@adamtanner.org"
30
+ gravatar = Aggravatar::Gravatar.new(email)
31
+
32
+ gravatar.secure_url.must_equal "https://secure.gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88"
33
+ end
34
+
35
+ it "supports the size option" do
36
+ email = "adam@adamtanner.org"
37
+
38
+ gravatar = Aggravatar::Gravatar.new(email, size: 200)
39
+
40
+ gravatar.url.must_match "?size=200"
41
+ gravatar.secure_url.must_match "?size=200"
42
+ end
43
+
44
+ it "supports the rating option" do
45
+ email = "adam@adamtanner.org"
46
+
47
+ gravatar = Aggravatar::Gravatar.new(email, rating: "g")
48
+
49
+ gravatar.url.must_match "?rating=g"
50
+ gravatar.secure_url.must_match "?rating=g"
51
+ end
52
+
53
+ it "supports the default option" do
54
+ email = "adam@adamtanner.org"
55
+
56
+ gravatar = Aggravatar::Gravatar.new(email, default: "404")
57
+
58
+ gravatar.url.must_match "?default=404"
59
+ gravatar.secure_url.must_match "?default=404"
60
+ end
61
+
62
+ it "supports the default option with URL" do
63
+ email = "adam@adamtanner.org"
64
+
65
+ gravatar = Aggravatar::Gravatar.new(email, default: "http://example.com/me.jpg")
66
+
67
+ gravatar.url.must_match "?default=http%3A%2F%2Fexample.com%2Fme.jpg"
68
+ gravatar.secure_url.must_match "?default=http%3A%2F%2Fexample.com%2Fme.jpg"
69
+ end
70
+
71
+ it "supports the force default option" do
72
+ email = "adam@adamtanner.org"
73
+
74
+ gravatar = Aggravatar::Gravatar.new(email, force_default: true)
75
+
76
+ gravatar.url.must_match "?forcedefault=y"
77
+ gravatar.secure_url.must_match "?forcedefault=y"
78
+ end
79
+ end
metadata CHANGED
@@ -1,84 +1,66 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: aggravatar
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Adam Tanner
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-09-23 00:00:00 -04:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: yard
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
35
- description: You give it an email. It gives you a Gravatar. What more do you want?
36
- email: adam@adamtanner.org
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! ' You give it an email, it gives you a Gravatar URL. What more do you
15
+ want? '
16
+ email:
17
+ - adam@adamtanner.org
37
18
  executables: []
38
-
39
19
  extensions: []
40
-
41
- extra_rdoc_files:
42
- - LICENSE
43
- - README.rdoc
44
- files:
20
+ extra_rdoc_files: []
21
+ files:
45
22
  - .document
46
23
  - .gitignore
47
- - LICENSE
48
- - README.rdoc
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
49
27
  - Rakefile
50
- - VERSION
28
+ - aggravatar.gemspec
51
29
  - lib/aggravatar.rb
30
+ - lib/aggravatar/gravatar.rb
31
+ - lib/aggravatar/version.rb
52
32
  - spec/aggravatar_spec.rb
53
- - spec/spec_helper.rb
54
- has_rdoc: true
55
- homepage: http://github.com/cxvii/aggravatar
33
+ - spec/gravatar_spec.rb
34
+ homepage: http://github.com/adamtanner/aggravatar
56
35
  licenses: []
57
-
58
36
  post_install_message:
59
- rdoc_options:
60
- - --charset=UTF-8
61
- require_paths:
37
+ rdoc_options: []
38
+ require_paths:
62
39
  - lib
63
- required_ruby_version: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
68
- version:
69
- required_rubygems_version: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: "0"
74
- version:
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ segments:
47
+ - 0
48
+ hash: -2729454159932039267
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ segments:
56
+ - 0
57
+ hash: -2729454159932039267
75
58
  requirements: []
76
-
77
59
  rubyforge_project:
78
- rubygems_version: 1.3.5
60
+ rubygems_version: 1.8.23
79
61
  signing_key:
80
- specification_version: 2
81
- summary: Helper method for generating Gravatars.
82
- test_files:
62
+ specification_version: 3
63
+ summary: You give it an email, it gives you a Gravatar URL. What more do you want?
64
+ test_files:
83
65
  - spec/aggravatar_spec.rb
84
- - spec/spec_helper.rb
66
+ - spec/gravatar_spec.rb
@@ -1,39 +0,0 @@
1
-
2
- = Aggravatar
3
-
4
- You give it an email, it gives you a Gravatar. What more do you want?
5
-
6
- == How to Use It
7
- Step 1: First you install it. (Assuming you already have Github sources added.)
8
- gem install adamtanner-aggravatar
9
-
10
- Step 2: Then you include Aggravatar in your class.
11
- require 'aggravatar'
12
- include Aggravatar
13
-
14
- == How to Use It From Rails
15
- Step 1: First you install it as a plugin.
16
- script/plugin install git://github.com/adamtanner/aggravatar.git
17
-
18
- Step 2: Skip to Step 3.
19
-
20
- ----------------------------
21
-
22
- Step 3: Then you ask it for a Gravatar.
23
- gravatar_for("email@example.com")
24
-
25
- Aggravatar even supports the wide array of options Gravatar gives you!
26
- gravatar_for("email@example.com", :size => 80, :default => "/my_default_gravatar.png", :rating => 'g')
27
-
28
- I know what you're thinking, and I've already got you covered.
29
- You're saying, "Hey, what if I need to add a class/title/id/etc to my Gravatar?!"
30
-
31
- Well here you go:
32
- gravatar_for("email@example.com", :html_attributes => {:class => "gravatar", :id => "my_gravatar", :title => "My Gravatar"}")
33
-
34
- You're not limited to just class, title, and id either! You can use any attribute you want! (even ones you make up!)
35
-
36
- == Copyright
37
-
38
- Copyright (c) 2009 Adam Tanner. See LICENSE for details.
39
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
@@ -1,9 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'aggravatar'
4
- require 'spec'
5
- require 'spec/autorun'
6
-
7
- Spec::Runner.configure do |config|
8
-
9
- end