 (ns wombats.handlers.auth
-  (:require [io.pedestal.interceptor.helpers :as interceptor]
+  (:require [clojure.string :refer [ends-with? join split]]
+            [io.pedestal.interceptor.helpers :as interceptor]
             [org.httpkit.client :as http]
             [cheshire.core :refer [parse-string]]
             [wombats.interceptors.github :refer [get-github-settings]]

   (fn [{:keys [request response] :as context}]
     (let [access-token (get-in request [:headers "authorization"])
           remove-access-token (dao/get-fn :remove-access-token context)
           web-client-redirect (remove-slash (get-in request [:headers "referer"]))]

       (when access-token
         @(remove-access-token access-token))

                       "Accept" "application/json"}}))

(defn- remove-slash
  "Removes the trailing slash from a string (if it exists)"
  [string]
  (if (ends-with? string "/")
    (-> string
        (split #"")
        (drop-last)
        (join))

    string))

(defn- get-referer
  "Pulls out the referer from a request object"
  [request]
  (get-in request [:headers "referer"]))

(defn- get-formatted-referer
  "Formats the referer"
  [request]
  (remove-slash (get-referer request)))

(defn- parse-user-response
  "Parses the body if the request succeeded"
