Module: Nesta::Plugin::ContentFocus::Helpers

Defined in:
lib/nesta-plugin-contentfocus/helpers.rb

Instance Method Summary collapse

Instance Method Details

#check_contentfocusObject



15
16
17
18
# File 'lib/nesta-plugin-contentfocus/helpers.rb', line 15

def check_contentfocus
  return if request.path_info =~ %r{\A/contentfocus\z}
  setup_contentfocus unless contentfocus_configured?
end

#contentfocus_configured?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/nesta-plugin-contentfocus/helpers.rb', line 6

def contentfocus_configured?
  Client.contentfocus_configured?
end

#contentfocus_request?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nesta-plugin-contentfocus/helpers.rb', line 20

def contentfocus_request?
  Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Authenticating Dropbox webhook request..."
  expected_user, expected_pass = Client.userinfo
  auth = Rack::Auth::Basic::Request.new(request.env)
  if auth.provided? && auth.basic? && auth.credentials == [expected_user, expected_pass]
    Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Authenticated."
    return true
  else
    Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Authentication failed."
    return false
  end
end

#setup_contentfocusObject



10
11
12
13
# File 'lib/nesta-plugin-contentfocus/helpers.rb', line 10

def setup_contentfocus
  Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Redirecting to contentfocus.io to complete account setup."
  redirect to("#{Nesta::Plugin::ContentFocus::Client.host}account/setup?domain=#{request.host}")
end

#site_domainObject



33
34
35
# File 'lib/nesta-plugin-contentfocus/helpers.rb', line 33

def site_domain
  request.host
end