Return-Path: X-Original-To: apmail-incubator-deltacloud-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-deltacloud-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 42C064FBF for ; Mon, 6 Jun 2011 16:16:32 +0000 (UTC) Received: (qmail 98618 invoked by uid 500); 6 Jun 2011 16:16:32 -0000 Delivered-To: apmail-incubator-deltacloud-dev-archive@incubator.apache.org Received: (qmail 98603 invoked by uid 500); 6 Jun 2011 16:16:31 -0000 Mailing-List: contact deltacloud-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: deltacloud-dev@incubator.apache.org Delivered-To: mailing list deltacloud-dev@incubator.apache.org Received: (qmail 98595 invoked by uid 99); 6 Jun 2011 16:16:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jun 2011 16:16:31 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of clalance@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jun 2011 16:16:20 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p56GFwT3004217 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 6 Jun 2011 12:15:58 -0400 Received: from localhost.localdomain (ovpn-113-91.phx2.redhat.com [10.3.113.91]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p56GFtmU012060 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 6 Jun 2011 12:15:57 -0400 Date: Mon, 6 Jun 2011 12:15:55 -0400 From: Chris Lalancette To: deltacloud-dev@incubator.apache.org Subject: Re: [PATCH core 1/3] Added 'api_url_for' helper to deal with prefix and matrix parameters as 'driver' and 'provider'. Every link should now include those parameters when they are present. Message-ID: <20110606161554.GC12512@localhost.localdomain> Reply-To: Chris Lalancette References: <1307374515-40207-1-git-send-email-mfojtik@redhat.com> <1307374515-40207-2-git-send-email-mfojtik@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1307374515-40207-2-git-send-email-mfojtik@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Virus-Checked: Checked by ClamAV on apache.org On 06/06/11 - 05:35:13PM, mfojtik@redhat.com wrote: > From: Chris Lalancette > > This patch also introduces DEFAULT_URI_PREFIX constant to be use > as a default for all routes instead of '/api > > Signed-off-by: Michal fojtik > --- > server/lib/sinatra/rack_matrix_params.rb | 2 +- > server/lib/sinatra/url_for.rb | 21 ++++++++++++++++++++- > 2 files changed, 21 insertions(+), 2 deletions(-) Sweet, this seems to work for me, and is a better idea overall. Two nits... > > diff --git a/server/lib/sinatra/rack_matrix_params.rb b/server/lib/sinatra/rack_matrix_params.rb > index 6362c7f..da1889e 100644 > --- a/server/lib/sinatra/rack_matrix_params.rb > +++ b/server/lib/sinatra/rack_matrix_params.rb > @@ -57,7 +57,7 @@ module Rack > value=nil > next > else > - value = param > + value = param.gsub(/\?.*$/, '') > end > end > end > diff --git a/server/lib/sinatra/url_for.rb b/server/lib/sinatra/url_for.rb > index 60da0ef..4bd24ae 100644 > --- a/server/lib/sinatra/url_for.rb > +++ b/server/lib/sinatra/url_for.rb > @@ -28,6 +28,19 @@ require 'uri' > > module Sinatra > module UrlForHelper > + > + DEFAULT_URI_PREFIX = "/api" > + > + def api_url_for(url_fragment, mode=:path_only) > + matrix_params = '' > + if request.params['api'] > + matrix_params += ";provider=%s" % request.params['api']['provider'] if request.params['api']['provider'] > + matrix_params += ";driver=%s" % request.params['api']['driver'] if request.params['api']['driver'] > + end > + url_fragment = "/#{url_fragment}" unless url_fragment =~ /^\// # There is no need to prefix URI with '/' > + url_for "#{DEFAULT_URI_PREFIX}#{matrix_params}#{url_fragment}", mode > + end > + > # Construct a link to +url_fragment+, which should be given relative to > # the base of this Sinatra app. The mode should be either > # :path_only, which will generate an absolute path within > @@ -63,14 +76,20 @@ module Sinatra > # Don't add the base fragment if url_for gets called more than once > # per url or the url_fragment passed in is an absolute url > if url_escape.match(/^#{base}/) or url_escape.match(/^http/) > + # here, we assume that if any driver additions are needed, they have > + # been done prior to entering this method. Hence we just return the > + # URL as-is > url_escape This comment no longer makes sense. > else > + # one last thing we need to do here is to make sure we properly add > + # the driver type to the URL (if necessary) > + # puts request.env['REQUEST_URI'].inspect Nor does this. I would suggest just dropping the comments completely. -- Chris Lalancette