From 1a6167de0b1ea82f18b25e3103f13f96a9b73227 Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Thu, 21 Apr 2016 18:25:23 -0500 Subject: [PATCH] Extract a framework-agnostic sanitized_webpage_url method --- CHANGELOG.md | 1 + lib/cortex/snippets/client.rb | 10 +++++----- lib/cortex/snippets/client/version.rb | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ca3516..913fca0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Version History * All Version bumps are required to update this file as well!! ---- +* 0.5.3 - Extract a framework-agnostic sanitized_webpage_url method * 0.5.2 - Addendum to previous version: fix expiry issues * 0.5.1 - Set Webpage feed cache to never expire * 0.5.0 - Auto-inject Client Helper into Views/Controllers. Add 10s race condition resolution to Rails cache fetch. Pass through to Snippet tag entire set of HTML attributes. Implement new namespacing and support Bundler.require. diff --git a/lib/cortex/snippets/client.rb b/lib/cortex/snippets/client.rb index a8d175c..d314209 100644 --- a/lib/cortex/snippets/client.rb +++ b/lib/cortex/snippets/client.rb @@ -18,17 +18,17 @@ def cortex_client def current_webpage(request) if defined?(Rails) - Rails.cache.fetch("webpages/#{request_url(request)}", race_condition_ttl: 10) do - cortex_client.webpages.get_feed(request_url(request)).contents + sanitized_url = sanitized_webpage_url(request.original_url) + Rails.cache.fetch("webpages/#{sanitized_url}", race_condition_ttl: 10) do + cortex_client.webpages.get_feed(sanitized_url).contents end else raise 'Your Web framework is not supported. Supported frameworks: Rails' end end - def request_url(request) - # TODO: Should be grabbing request URL in a framework-agnostic manner, but this is fine for now - uri = Addressable::URI.parse(request.original_url) + def sanitized_webpage_url(url) + uri = Addressable::URI.parse(url) path = uri.path == '/' ? uri.path : uri.path.chomp('/') "#{uri.scheme}://#{uri.authority}#{path}" end diff --git a/lib/cortex/snippets/client/version.rb b/lib/cortex/snippets/client/version.rb index b81fb98..39de64d 100644 --- a/lib/cortex/snippets/client/version.rb +++ b/lib/cortex/snippets/client/version.rb @@ -1,7 +1,7 @@ module Cortex module Snippets module Client - VERSION = '0.5.2' + VERSION = '0.5.3' end end end