Skip to content
This repository
Browse code

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

  • Loading branch information...
commit c2c9c5f761774d461c353c99b5a8cda50d4fd512 1 parent 4f045f0
Victor Costan authored February 10, 2012
11  lib/gravatar.rb
@@ -18,7 +18,7 @@
18 18
 class Gravatar
19 19
   API_METHODS = [
20 20
     :exists?, :addresses, :user_images, :save_data!, :save_image!, :save_url!, :use_image!, :use_user_image!,
21  
-    :remove_image!, :delete_user_image!, :test, :image_url, :image_data
  21
+    :remove_image!, :delete_user_image!, :test, :image_url, :image_data, :signup_url
22 22
   ]
23 23
   autoload :TestCase, File.expand_path('gravatar/test_case', File.dirname(__FILE__))
24 24
   
@@ -207,6 +207,15 @@ def image_url(options = {})
207 207
     "#{proto}://#{sub}.gravatar.com/avatar/#{email_hash}#{extension_for_image(options)}#{query_for_image(options)}"
208 208
   end
209 209
 
  210
+  # Returns the URL for Gravatar's signup form, with the user's email pre-filled. Options include:
  211
+  #
  212
+  #   :locale                if non-nil, wil be used to prefix the URL. Example: :en
  213
+  def signup_url(options = {})
  214
+    locale_prefix = options[:locale] ? "#{options[:locale]}." : ''
  215
+
  216
+    "https://#{locale_prefix}gravatar.com/site/signup/#{CGI.escape(email)}"
  217
+  end
  218
+
210 219
   # Returns the image data for this user's gravatar image. This is the same as reading the data at #image_url. See
211 220
   # that method for more information.
212 221
   #
8  spec/lib/gravatar_spec.rb
@@ -173,5 +173,13 @@
173 173
       )
174 174
       combinations.should include(image_url(:ssl => true, :default => "identicon", :size => 80, :rating => :g))
175 175
     end
  176
+    
  177
+    it "should return gravatar signup_url" do
  178
+      signup_url.should == "https://gravatar.com/site/signup/gravatartest123%40gmail.com"
  179
+    end
  180
+
  181
+    it "should return gravatar signup_url with locale" do
  182
+      signup_url(:locale => :en).should == "https://en.gravatar.com/site/signup/gravatartest123%40gmail.com"      
  183
+    end
176 184
   end
177 185
 end

0 notes on commit c2c9c5f

Please sign in to comment.
Something went wrong with that request. Please try again.