title: How to get 302 redirect location in Rails? (have tried HTTParty, Net/Http and RedirectFollower)
body: <p>Hello<br>
  i am trying to get Facebook user's album's cover picture.<br>
  as it's said in the API page, it returns "An HTTP 302 with the URL of the album's cover picture" when getting:<br>
  http s://graph.facebook.com/[album_id]}/picture?access_token=blahblahblah...<br>
  documents here: <a href="http://developers.facebook.com/docs/reference/api/album" rel="nofollow">http://developers.facebook.com/docs/reference/api/album</a></p>
  
  <p>i've tried HTTParty, Net:HTTP and also the RedirectFollower class<br>
  HTTParty returns the picture image itself, and no "location" (URL) information anywhere<br>
  NET:HTTP and RedirectFollower are a bit tricky...<br>
  if i don't use URI.encode when passing the URL into the get method, it causes "bad uri" error<br>
  but if i use URI.encode to pass the encoded URI, it causes EOFError (end of file reached)<br>
  what's amazing is that i can see the location URL when using apigee's FB API</p>
  
  <p>here is the redirect method which is recommended on the Net:HTTP documents:<br>
  anything should be modified? or is there any easier way to do this?
  thank you!!</p>
  
  <pre><code>def self.fetch(uri_str, limit = 10)
    response = Net::HTTP.get_response(URI.parse(uri_str))
    case response
      when Net::HTTPSuccess     then response
      when Net::HTTPRedirection then fetch(response['location'], limit - 1)
    else
      response.error!
    end
  end
  </code></pre>