You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.rb 1.4KB

  1. # frozen_string_literal: true
  2. require "dotenv/load"
  3. require "bundler/setup"
  4. require "active_record"
  5. require 'active_support/time'
  6. require "pg"
  7. require "logger"
  8. require "sucker_punch"
  9. require "sinatra"
  10. require "sinatra/reloader" if development?
  11. require "sinatra/json"
  12. use Rack::Auth::Basic, "What is the air-speed velocity of an unladen swallow?" do |username, password|
  13. username == ENV.fetch("AUTH_USER") && password == ENV.fetch("AUTH_PASS")
  14. end
  15. SuckerPunch.logger = Logger.new(STDOUT)
  16. ActiveRecord::Base.logger = Logger.new(STDOUT)
  17. ActiveRecord::Base.establish_connection(ENV.fetch("DATABASE_URL"))
  18. require_relative "models/bucket.rb"
  19. require_relative "models/person.rb"
  20. require_relative "models/todo_item.rb"
  21. require_relative "models/todo_item_assignee.rb"
  22. require_relative "models/todo_list.rb"
  23. require_relative "models/token.rb"
  24. require_relative "jobs/sync_job.rb"
  25. require_relative "basecamp3"
  26. basecamp = Basecamp3.new
  27. get "/" do
  28. if basecamp.authenticated?
  29. erb :index, locals: { basecamp: basecamp }
  30. else
  31. erb :oauth, locals: { authorize_url: basecamp.authorize_url }
  32. end
  33. end
  34. get "/oauth-token" do
  35. basecamp.get_access_token(params["code"])
  36. basecamp = Basecamp3.new
  37. redirect "/"
  38. end
  39. get "/import" do
  40. if request.xhr?
  41. SyncJob.perform_async(basecamp)
  42. end
  43. end
  44. get "/sync-status" do
  45. Token.find_by(client_id: ENV["BASECAMP_CLIENT_ID"]).sync_active.to_s
  46. end