Browse files

fix paging to use the new-ish cursor standard

  • Loading branch information...
1 parent ae8cb95 commit 2cfe51a1797d9a041cb055a930c2ece25b5d92ea @courtenay committed Mar 15, 2010
Showing with 9 additions and 7 deletions.
  1. +9 −7 adult_friend_finder.rb
View
16 adult_friend_finder.rb
@@ -10,24 +10,26 @@ def consumer
def pull(url)
txt = []
- page = 1
+ page = -1
data = nil
@access_token = OAuth::AccessToken.new(consumer, @user.token, @user.secret)
- while(data != "[]" && page < 10)
- txt << data
- request = consumer.request(:get, "/statuses/friends/#{url}.json?page=#{page}", @access_token, { :scheme => :query_string })
+ while(data != "[]" && page != "0")
+ request = consumer.request(:get, "/statuses/friends/#{url}.json?cursor=#{page}", @access_token, { :scheme => :query_string })
case request
when Net::HTTPSuccess
data = request.body
else
- raise "Auth fail?"
+ raise "Auth fail? #{request.inspect}"
end
+ json = JSON.parse(data)
+ page = json['next_cursor_str']
+ data = json['users'].to_json
data.gsub!(/\]$/, "").gsub!(/^\[/, "") # strip out the array [ and ]
- page += 1
+ txt << data
end
- "[" + txt.compact.join(",").gsub!(/,+$/, "") + "]" # put those [ and ] on either side
+ "[" + txt.compact.join(",").gsub(/,+$/, "").to_s + "]" # put those [ and ] on either side
end
def check_api_load

0 comments on commit 2cfe51a

Please sign in to comment.