Skip to content

Commit 229c2bd

Browse files
committed
also store binding version as data for use in various places
1 parent 71a29a0 commit 229c2bd

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

src/main/com/yetanalytics/lrs/pedestal/interceptor.cljc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@
7474
{:name ::set-version-bindings
7575
:enter (fn [ctx]
7676
(if-let [version (:com.yetanalytics.lrs/version ctx)]
77-
(update
78-
ctx
79-
:bindings
80-
assoc
81-
#'xapi-schema.spec/*xapi-version*
82-
(cond
83-
(cstr/starts-with? version "1") "1.0.3"
84-
(cstr/starts-with? version "2") "2.0.0"))
77+
(let [spec-version (cond
78+
(cstr/starts-with? version "1") "1.0.3"
79+
(cstr/starts-with? version "2") "2.0.0")]
80+
(-> ctx
81+
(assoc :com.yetanalytics.lrs/spec-version spec-version)
82+
(update
83+
:bindings
84+
assoc
85+
#'xapi-schema.spec/*xapi-version*
86+
spec-version)))
8587
ctx))
8688
:leave (fn [ctx]
8789
(update ctx :bindings dissoc #'xapi-schema.spec/*xapi-version*))}))
@@ -176,7 +178,7 @@
176178
(assoc-in ctx
177179
[:response :headers "x-experience-api-version"]
178180
;; Get version from context or latest patch
179-
(:com.yetanalytics.lrs/version ctx "2.0.0")))}))
181+
(:com.yetanalytics.lrs/spec-version ctx "2.0.0")))}))
180182

181183
(defn calculate-etag [x]
182184
(sha-1 x))

src/main/com/yetanalytics/lrs/pedestal/interceptor/xapi.cljc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
(let [version (:com.yetanalytics.lrs/version ctx)]
5353
;; Version 2.0.0 and up do not allow this so we error
5454
(if (or (nil? version)
55-
(not (.startsWith ^String version "1.0")))
55+
(not (.startsWith ^String version "1")))
5656
(error!
5757
ctx
5858
"xAPI alternate request syntax not supported!")
@@ -190,13 +190,8 @@
190190
#?(:clj (conform-cheshire spec-kw raw-params)
191191
;; Force binding of spec version in cljs
192192
:cljs
193-
(let [v (:com.yetanalytics.lrs/version ctx)]
194-
(binding [xs/*xapi-version*
195-
(cond
196-
(cstr/starts-with? v "1")
197-
"1.0.3"
198-
(cstr/starts-with? v "2")
199-
"2.0.0")]
193+
(let [v (:com.yetanalytics.lrs/spec-version ctx)]
194+
(binding [xs/*xapi-version* (or v "2.0.0")]
200195
(conform-cheshire spec-kw raw-params))))
201196
{:keys [path-info
202197
request-method]} request]

src/main/com/yetanalytics/lrs/pedestal/interceptor/xapi/statements.cljc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,8 @@
240240
#?(:clj (validate-request-statements* ctx)
241241
;; Force binding of spec version in cljs
242242
:cljs
243-
(let [version (:com.yetanalytics.lrs/version ctx)]
244-
(binding [xs/*xapi-version* (cond
245-
(cs/starts-with? version "1")
246-
"1.0.3"
247-
(cs/starts-with? version "2")
248-
"2.0.0")]
249-
(validate-request-statements* ctx)))))})
243+
(binding [xs/*xapi-version* (:com.yetanalytics.lrs/spec-version ctx "2.0.0")]
244+
(validate-request-statements* ctx))))})
250245

251246
(defn scan-attachments
252247
"Scan attachment files with a user-provided function."

src/main/com/yetanalytics/lrs/pedestal/routes/documents.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@
303303
(if (and (or
304304
;; In 2.0, no headers ok for no doc
305305
(= "2.0.0"
306-
(:com.yetanalytics.lrs/version ctx))
306+
(:com.yetanalytics.lrs/spec-version ctx))
307307
;; prior tests seem to want this for everything but
308308
;; profiles
309309
(not (#{:xapi.activities.profile.PUT.request/params
@@ -338,7 +338,7 @@
338338
(if (and (or
339339
;; In 2.0, no headers ok for no doc
340340
(= "2.0.0"
341-
(:com.yetanalytics.lrs/version ctx))
341+
(:com.yetanalytics.lrs/spec-version ctx))
342342
;; prior tests seem to want this for everything but
343343
;; profiles
344344
(not (#{:xapi.activities.profile.PUT.request/params

0 commit comments

Comments
 (0)