Skip to content

Commit

Permalink
Implemented signup_url according to http://blog.gravatar.com/2009/08/…
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnall committed Feb 11, 2012
1 parent 4f045f0 commit c2c9c5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/gravatar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class Gravatar
API_METHODS = [
:exists?, :addresses, :user_images, :save_data!, :save_image!, :save_url!, :use_image!, :use_user_image!,
:remove_image!, :delete_user_image!, :test, :image_url, :image_data
:remove_image!, :delete_user_image!, :test, :image_url, :image_data, :signup_url
]
autoload :TestCase, File.expand_path('gravatar/test_case', File.dirname(__FILE__))

Expand Down Expand Up @@ -207,6 +207,15 @@ def image_url(options = {})
"#{proto}://#{sub}.gravatar.com/avatar/#{email_hash}#{extension_for_image(options)}#{query_for_image(options)}"
end

# Returns the URL for Gravatar's signup form, with the user's email pre-filled. Options include:
#
# :locale if non-nil, wil be used to prefix the URL. Example: :en
def signup_url(options = {})
locale_prefix = options[:locale] ? "#{options[:locale]}." : ''

"https://#{locale_prefix}gravatar.com/site/signup/#{CGI.escape(email)}"
end

# Returns the image data for this user's gravatar image. This is the same as reading the data at #image_url. See
# that method for more information.
#
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/gravatar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,13 @@
)
combinations.should include(image_url(:ssl => true, :default => "identicon", :size => 80, :rating => :g))
end

it "should return gravatar signup_url" do
signup_url.should == "https://gravatar.com/site/signup/gravatartest123%40gmail.com"
end

it "should return gravatar signup_url with locale" do
signup_url(:locale => :en).should == "https://en.gravatar.com/site/signup/gravatartest123%40gmail.com"
end
end
end

0 comments on commit c2c9c5f

Please sign in to comment.