Skip to content

Commit

Permalink
Support /pages/x/id facebook urls.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Jul 3, 2015
1 parent 89b4d15 commit 3f8d153
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app.rb
Expand Up @@ -81,7 +81,9 @@ def httparty_error(r)
get "/facebook" do
return "Insufficient parameters" if params[:q].empty?

if /facebook\.com\/(?<name>[^\/\?#]+)/ =~ params[:q]
if /facebook\.com\/pages\/[^\/]+\/(?<name>\d+)/ =~ params[:q]
# https://www.facebook.com/pages/Aln%C3%B6-IF/284405309736?fref=ts
elsif /facebook\.com\/(?<name>[^\/\?#]+)/ =~ params[:q]
# https://www.facebook.com/celldweller/info?tab=overview
else
name = params[:q]
Expand All @@ -92,7 +94,7 @@ def httparty_error(r)
raise FacebookError, response if !response.success?

data = response.parsed_response
redirect "/facebook/#{data["id"]}/#{data["username"]}"
redirect "/facebook/#{data["id"]}/#{data["username"] || data["name"]}"
end

get %r{/facebook/(?<id>\d+)(/(?<username>.+))?} do |id, username|
Expand Down
1 change: 0 additions & 1 deletion config/initializers/05-hash.rb
@@ -1,6 +1,5 @@
class Hash
def to_querystring
# self.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
self.map { |k,v| "#{k}=#{v}" }.join("&")
end
end

0 comments on commit 3f8d153

Please sign in to comment.