Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved pagination url parsing

  • Loading branch information...
commit 05ee19e6e1c7aa9ff961231cd68b2b1689bd6a58 1 parent dcda170
Brian Norton & Ian Lesperance authored
View
9 lib/koala/api/graph_collection.rb
@@ -87,10 +87,11 @@ def parse_page_url(url)
#
# @return an array of parameters that can be provided via graph_call(*parsed_params)
def self.parse_page_url(url)
- match = url.match(/.com\/(.*)\?(.*)/)
- base = match[1]
- args = match[2]
- params = CGI.parse(args)
+ uri = URI.parse(url)
+
+ base = uri.path.sub(/^\//, '')
+ params = CGI.parse(uri.query)
+
new_params = {}
params.each_pair do |key,value|
new_params[key] = value.join ","
View
4 spec/cases/graph_collection_spec.rb
@@ -91,12 +91,12 @@
describe ".parse_page_url" do
it "should return the base as the first array entry" do
base = "url_path"
- Koala::Facebook::GraphCollection.parse_page_url("anything.com/#{base}?anything").first.should == base
+ Koala::Facebook::GraphCollection.parse_page_url("http://anything.net/#{base}?anything").first.should == base
end
it "should return the arguments as a hash as the last array entry" do
args_hash = {"one" => "val_one", "two" => "val_two"}
- Koala::Facebook::GraphCollection.parse_page_url("anything.com/anything?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").last.should == args_hash
+ Koala::Facebook::GraphCollection.parse_page_url("http://anything.net/anything?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").last.should == args_hash
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.