From 8422dddc085ef4db4197bb44b34c52d47fbeb3af Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Thu, 2 Jul 2015 16:04:40 -0700 Subject: [PATCH] Add Hash#to_querystring --- app.rb | 6 +++--- config/initializers/05-hash.rb | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 config/initializers/05-hash.rb diff --git a/app.rb b/app.rb index e32885e..61d1996 100644 --- a/app.rb +++ b/app.rb @@ -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 diff --git a/config/initializers/05-hash.rb b/config/initializers/05-hash.rb new file mode 100644 index 0000000..9be0aac --- /dev/null +++ b/config/initializers/05-hash.rb @@ -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