Skip to content

Refactor Webpage URL Generation #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 5 additions & 5 deletions lib/cortex/snippets/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cortex/snippets/client/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Cortex
module Snippets
module Client
VERSION = '0.5.2'
VERSION = '0.5.3'
end
end
end