Module: Cortex::Snippets::Client

Defined in:
lib/cortex/snippets/client.rb

Class Method Summary collapse

Class Method Details

.cortex_clientObject



9
10
11
12
13
14
15
# File 'lib/cortex/snippets/client.rb', line 9

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(key: ENV['CORTEX_SNIPPET_KEY'], secret: ENV['CORTEX_SNIPPET_SECRET'], base_url: ENV['CORTEX_SNIPPET_BASE_URL'], scopes: ENV['CORTEX_SNIPPET_SCOPES']) }
  else
    @cortex_client ||= ConnectionPool::Wrapper.new(size: 5, timeout: 3) { Cortex::Client.new(access_token: ENV['CORTEX_SNIPPET_ACCESS_TOKEN']) }
  end
end

.current_webpage(request) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/cortex/snippets/client.rb', line 17

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)).contents
    end
  else
    raise 'Your Web framework is not supported. Supported frameworks: Rails'
  end
end