Skip to content
Permalink
Browse files

ok, now opts recognize double_decode option, this would fix broken json:

now we're passing opts around, instead of suppress_decode argument.
since now we have double_decode option now...
when this is turned on, rest-graph would parse the json twice,
for the facebook's crappy broken json.

broken_old_rest is now essentially secret_old_rest with double_decode
turned on by default.
  • Loading branch information...
godfat committed Sep 30, 2010
1 parent 7107fe3 commit c9aa96485d3922e750b23f7421daad19ff7988f0
Showing with 12 additions and 11 deletions.
  1. +11 −10 lib/rest-graph.rb
  2. +1 −1 test/test_api.rb
@@ -347,10 +347,7 @@ def secret_old_rest path, query={}, opts={}
end

def broken_old_rest path, query={}, opts={}
post_request(
secret_old_rest(path, query, :suppress_decode => true).
tr('\\', '')[1..-2],
opts[:suppress_decode])
secret_old_rest(path, query, {:double_decode => true}.merge(opts))
end

def exchange_sessions opts={}
@@ -375,10 +372,9 @@ def fql_multi codes, query={}, opts={}
private
def request meth, uri, opts={}, payload=nil
start_time = Time.now
post_request(cache_get(uri) || fetch(meth, uri, payload),
opts[:suppress_decode])
post_request(cache_get(uri) || fetch(meth, uri, payload), opts)
rescue RestClient::Exception => e
post_request(e.http_body, opts[:suppress_decode])
post_request(e.http_body, opts)
ensure
log_handler.call(Event::Requested.new(Time.now - start_time, uri))
end
@@ -397,9 +393,14 @@ def build_headers
headers
end

def post_request result, suppress_decode=nil
if auto_decode && !suppress_decode
check_error(self.class.json_decode(result))
def post_request result, opts={}
if auto_decode && !opts[:suppress_decode]
check_error(self.class.json_decode(
if opts[:double_decode]
self.class.json_decode("[#{result}]").first
else
result
end))
else
result
end
@@ -54,7 +54,7 @@
stub_request(:put, 'https://graph.facebook.com/feed/me').
with(:body => 'message=hi%20there').to_return(:body => '[]')

mock.proxy(rg = RestGraph.new).post_request('[]', nil)
mock.proxy(rg = RestGraph.new).post_request('[]', {})
rg.put('feed/me', :message => 'hi there').
should == []
end

0 comments on commit c9aa964

Please sign in to comment.
You can’t perform that action at this time.