 (def client-id (env :asana-client-id))
 (def client-secret (env :asana-client-secret))
 
+
+;; Authentication flow
 (def token-url "https://app.asana.com/-/oauth_token")
 (def authorization-url "https://app.asana.com/-/oauth_authorize")
 (def api-url "https://app.asana.com/api/1.0")

                                                  :refresh-token refresh_token})))
            (timbre/warnf "Bad response when exchanging token %s" (:body resp))))))))

(defn register-webhook
  [extension-id]
  (let [ext (db/with-conn (db/extension-by-id extension-id))

    {:status 200 :headers {"X-Hook-Secret" secret}}
    (do (println "webhook" event-req)
        {:status 200})))

;; Fetching information
(defn fetch-asana-info
  [extension-id path]
  (let [ext (db/with-conn (db/extension-by-id extension-id))]
    (let [resp @(http/get (str api-url path)
                  {:oauth-token (ext :token)})]
      (if (= 200 (:status resp))
        (-> resp :body json/read-str)
        (timbre/warnf "token expired %s" (:body resp))))))

(defn available-workspaces
  [extension-id]
  (-> (fetch-asana-info extension-id "/users/me")
      (get-in ["data" "workspaces"])))

(defn workspace-projects
  [extension-id workspace-id]
  (fetch-asana-info extension-id (str "/workspaces/" workspace-id "/projects")))
