Skip to content

Commit

Permalink
Add Hash#to_querystring
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Jul 2, 2015
1 parent 52595ec commit 8422ddd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def httparty_error(r)
get "/go" do
return "Insufficient parameters" if params[:q].empty?
if /^https?:\/\/(www\.)?youtu(\.?be|be\.com)/ =~ params[:q]
redirect "/youtube?q=#{params[:q]}"
redirect "/youtube?#{params.to_querystring}"
elsif /^https?:\/\/(www\.)?facebook\.com/ =~ params[:q]
redirect "/facebook?q=#{params[:q]}"
redirect "/facebook?#{params.to_querystring}}"
elsif /^https?:\/\/(www\.)?instagram\.com/ =~ params[:q]
redirect "/instagram?q=#{params[:q]}"
redirect "/instagram?#{params.to_querystring}"
else
"Unknown service"
end
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/05-hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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 8422ddd

Please sign in to comment.