Sha256: f7ebb54d87f788fdab11557c41475c8e15f3c1eb26d57c8d9ef17c61f6eb6039
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module Cortex module Snippets module Client class << self def cortex_client if ENV['CORTEX_SNIPPET_ACCESS_TOKEN'].nil? || ENV['CORTEX_SNIPPET_ACCESS_TOKEN'].empty? @cortex_client ||= ConnectionPool::Wrapper.new(size: 5, timeout: 3) { Cortex::Client.new(access_token: ENV['CORTEX_SNIPPET_ACCESS_TOKEN']) } else @cortex_client ||= ConnectionPool::Wrapper.new(size: 5, timeout: 3) { Cortex::Client.new(key: ENV['CORTEX_SNIPPET_KEY'], secret: ENV['CORTEX_SNIPPET_SECRET'], base_url: ENV['CORTEX_SNIPPET_BASE_URL']) } end end def current_webpage(request) if defined?(Rails) Rails.cache.fetch("webpages/#{request_url(request)}", expires_in: 30.minutes) do cortex_client.webpages.get_feed(request_url(request)) end else raise 'Your Web framework is not supported. Supported frameworks: Rails' end end private def request_url(request) # TODO: Should be grabbing request URL in a framework-agnostic manner, but this is fine for now request.original_url end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cortex-snippets-client-ruby-0.1.0 | lib/cortex/snippets/client.rb |