Module: Nesta::Plugin::Drop::Helpers

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

Instance Method Summary collapse

Instance Method Details

#check_nestadropObject



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

def check_nestadrop
  return if request.path_info =~ %r{\A/nestadrop\z}
  setup_nestadrop unless nestadrop_configured?
end

#nestadrop_configured?Boolean

Returns:

  • (Boolean)


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

def nestadrop_configured?
  Client.nestadrop_configured?
end

#nestadrop_request?Boolean

Returns:

  • (Boolean)


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

def nestadrop_request?
  Nesta::Plugin::Drop.logger.debug "NESTADROP: 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::Drop.logger.debug "NESTADROP: Authenticated."
    return true
  else
    Nesta::Plugin::Drop.logger.debug "NESTADROP: Authentication failed."
    return false
  end
end

#setup_nestadropObject



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

def setup_nestadrop
  Nesta::Plugin::Drop.logger.debug "NESTADROP: Redirecting to nestadrop.io to complete account setup."
  redirect to("#{Nesta::Plugin::Drop::Client.host}account/setup?domain=#{request.host}")
end