<commit_before>;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2016 <NAME> <<EMAIL>>

(ns uxbox.repo.core
  "A main interface for access to remote resources."
  (:refer-clojure :exclude [do])
  (:require [httpurr.client.xhr :as http]
            [httpurr.status :as http.status]
            [hodgepodge.core :refer (local-storage)]
            [promesa.core :as p :include-macros true]
            [beicon.core :as rx]
            [uxbox.transit :as t]
            [uxbox.state :as ust]))

(goog-define url "http://127.0.0.1:5050/api")

(def ^:private +storage+
  local-storage)

(defn- conditional-decode
  [{:keys [body headers] :as response}]
  (if (= (get headers "content-type") "application/transit+json")
    (assoc response :body (t/decode body))
    response))

(defn- handle-http-status
  [response]
  (if (http.status/success? response)
    (p/resolved response)
    (p/rejected response)))

(def ^:private ^:const +headers+
  {"content-type" "application/transit+json"})

(defn auth-headers
  []
  (when-let [auth (:auth @ust/state)]
    {"authorization" (str "Token " (:token auth "no-token"))}))

(defn- send!
  [{:keys [body headers auth method] :or {auth true} :as request}]
  (let [headers (merge {}
                       (when (not= method :get) +headers+)
                       headers<commit_msg>Don't send content type headers when no body is available.<commit_after>;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2016 <NAME> <<EMAIL>>

(ns uxbox.repo.core
  "A main interface for access to remote resources."
  (:refer-clojure :exclude [do])
  (:require [httpurr.client.xhr :as http]
            [httpurr.status :as http.status]
            [hodgepodge.core :refer (local-storage)]
            [promesa.core :as p :include-macros true]
            [beicon.core :as rx]
            [uxbox.transit :as t]
            [uxbox.state :as ust]))

(goog-define url "http://127.0.0.1:5050/api")

(def ^:private +storage+
  local-storage)

(defn- conditional-decode
  [{:keys [body headers] :as response}]
  (if (= (get headers "content-type") "application/transit+json")
    (assoc response :body (t/decode body))
    response))

(defn- handle-http-status
  [response]
  (if (http.status/success? response)
    (p/resolved response)
    (p/rejected response)))

(def ^:private ^:const +headers+
  {"content-type" "application/transit+json"})

(defn auth-headers
  []
  (when-let [auth (:auth @ust/state)]
    {"authorization" (str "Token " (:token auth "no-token"))}))

(defn- send!
  [{:keys [body headers auth method] :or {auth true} :as request}]
  (let [headers (merge {}
                       (when body +headers+)
                       headers
{'fraction_non_alphanumeric': 0.15323383084577114, 'fraction_numerical': 0.011940298507462687, 'mean_word_length': 2.8916129032258064, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4087624', 'n_tokens_mistral': 1036, 'n_tokens_neox': 990, 'n_words': 308}