Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented signup_url according to http://blog.gravatar.com/2009/08/…

  • Loading branch information...
commit c2c9c5f761774d461c353c99b5a8cda50d4fd512 1 parent 4f045f0
@pwnall pwnall authored
Showing with 18 additions and 1 deletion.
  1. +10 −1 lib/gravatar.rb
  2. +8 −0 spec/lib/gravatar_spec.rb
View
11 lib/gravatar.rb
@@ -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__))
@@ -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.
#
View
8 spec/lib/gravatar_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.