7 Commits
v0.1 ... main

Author SHA1 Message Date
4b1a7b1bc2 tests and corrections 2026-01-31 22:03:23 +01:00
b1d38164f8 Unnecesary log 2026-01-31 21:18:55 +01:00
f0f3baaa3d Better error message 2026-01-31 20:47:45 +01:00
4cec5b55c7 Better doc 2026-01-31 20:40:55 +01:00
dba520dce2 Fix tests 2026-01-31 20:22:58 +01:00
c164c4f696 Fix to-fancy-hex
Fixes bug that responds allways nil
2026-01-30 16:16:46 +01:00
c3d4b544ad Code cleaning 2026-01-30 00:10:06 +01:00
6 changed files with 35 additions and 22 deletions

View File

@@ -2,7 +2,7 @@
(:require [clojure.tools.build.api :as b])) (:require [clojure.tools.build.api :as b]))
(def lib 'rcorral/utils) (def lib 'rcorral/utils)
(def version "0.1.0") ;; or read from file, etc (def version "0.2.0") ;; or read from file, etc
(def class-dir "target/classes") (def class-dir "target/classes")
(def jar-file (format "target/%s-%s.jar" (name lib) version)) (def jar-file (format "target/%s-%s.jar" (name lib) version))

View File

@@ -20,7 +20,9 @@
(defn get-and-save-key-from-env (defn get-and-save-key-from-env
"Get api key from environment and store in the KEYS map. It key is not found in "Get api key from environment and store in the KEYS map. It key is not found in
the environment, it tries to load the development key as a fallback. If none api the environment, it tries to load the development key as a fallback. If none api
key is found, return nil" key is found, return nil.
KEYS is a map of atom values, that stores current loaded keys."
[KEYS default-key key] [KEYS default-key key]
(if-let [value (get-key-from-env key)] (if-let [value (get-key-from-env key)]
(reset! (key KEYS) value) (reset! (key KEYS) value)
@@ -40,7 +42,7 @@
(if-let [def-key-value (deref (default-key KEYS))] (if-let [def-key-value (deref (default-key KEYS))]
def-key-value def-key-value
(get-and-save-key-from-env KEYS default-key keytype))) (get-and-save-key-from-env KEYS default-key keytype)))
(println "Invalid key type. Available keys:" (keys KEYS)))) (println "Invalid key type '" keytype "'. Available keys:" (keys KEYS))))
(defn set-api-key (defn set-api-key
@@ -172,7 +174,6 @@
debug false debug false
debug-http @debug-http} debug-http @debug-http}
:as cfg-params}] :as cfg-params}]
(println "Params" cfg-params)
(when debug (println "Endpoints:" (count endpoints-cfg) "Key provider:" key-provider)) (when debug (println "Endpoints:" (count endpoints-cfg) "Key provider:" key-provider))
(let [; Process path-parameters (let [; Process path-parameters
processed-url (if (keyword? url) processed-url (if (keyword? url)

View File

@@ -3,7 +3,6 @@
"Example about how to build an API client using rcorral.api.core" "Example about how to build an API client using rcorral.api.core"
;; ;;
;; Endpoints configuration ;; Endpoints configuration
;; ;;
@@ -16,7 +15,7 @@
(defn auth-provider (defn auth-provider
"Auth provider that gets user and password and adds a header for basic auth" "Auth provider that gets user and password and adds a header for basic auth"
[user password url params headers] [user password _ params headers]
(if (and (some? user) (some? password)) (if (and (some? user) (some? password))
(let [concatenated (str user ":" password) (let [concatenated (str user ":" password)
encoded (.encodeToString (java.util.Base64/getEncoder) (.getBytes concatenated)) encoded (.encodeToString (java.util.Base64/getEncoder) (.getBytes concatenated))
@@ -25,17 +24,10 @@
[params headers])) [params headers]))
(defn get-endpoint (defn get-endpoint
[url user passwd & {:keys [path-params query-params header-params verbose] [url user passwd & {:as params}]
:or {path-params {}
query-params {}
header-params {"Accept" "application/json"}
debug false
debug-http false}
:as params}]
(println "Calling with" params) (println "Calling with" params)
(api/call-api ENDPOINTS (partial auth-provider user passwd) url params)) (api/call-api ENDPOINTS (partial auth-provider user passwd) url params))
(comment (comment
(get-endpoint :licenses nil nil :debug true) (get-endpoint :licenses nil nil :debug true)
(get-endpoint :user-info "user" "passwd" :debug true) (get-endpoint :user-info "user" "passwd" :debug true))
)

View File

@@ -88,7 +88,7 @@
([x] ([x]
(to-fancy-hex x 2)) (to-fancy-hex x 2))
([x group-size] ([x group-size]
(try (when (s/join " " (try (when x (s/join " "
(map s/join (map s/join
(partition group-size (hex/encode (byte-array (map #(b/to-byte %) x))))))) (partition group-size (hex/encode (byte-array (map #(b/to-byte %) x)))))))
(catch Exception e)))) (catch Exception e))))
@@ -99,12 +99,13 @@
More info: https://en.wikipedia.org/wiki/Euclidean_division More info: https://en.wikipedia.org/wiki/Euclidean_division
" "
[a b] [a b]
(when (and a b)
(when (zero? b) (when (zero? b)
(throw (IllegalArgumentException. "You can't divide by zero!"))) (throw (IllegalArgumentException. "You can't divide by zero!")))
(let [b-abs (Math/abs b) (let [b-abs (Math/abs b)
r (mod a b-abs)] ;; 0 <= r < |b| r (mod a b-abs)] ;; 0 <= r < |b|
(quot (- a r) b) ;; adjusts quotient with the positive remainder (quot (- a r) b) ;; adjusts quotient with the positive remainder
)) )))
(defn euclidean-rem (defn euclidean-rem
"Modulus for euclidean division for integers "Modulus for euclidean division for integers

View File

@@ -83,6 +83,11 @@
(is (= "0F" (to-fancy-hex [15]))) (is (= "0F" (to-fancy-hex [15])))
(is (= "0F 7F" (to-fancy-hex [15 127]))))) (is (= "0F 7F" (to-fancy-hex [15 127])))))
(deftest euclidean-quot-test
(testing "Invalid values"
(is (nil? (euclidean-quot nil nil)))
(is (= "" ""))))
(deftest decimal->base-test (deftest decimal->base-test
(testing "Convert from decimal base to an arbitrary base" (testing "Convert from decimal base to an arbitrary base"
(is (= [0] (decimal->base nil 10))) (is (= [0] (decimal->base nil 10)))

View File

@@ -0,0 +1,14 @@
(ns rcorral.util-test
(:require [clojure.test :refer :all]
[rcorral.bin-util :refer :all]
[alphabase.bytes :as b]
[alphabase.base16 :as hex]
[alphabase.base64 :as b64]
[alphabase.base32 :as b32])
(:import (java.util Arrays)))
(deftest success-test
(testing "Generate a successful case"
(is true) ;; Not nill
))