Liking cljdoc? Tell your friends :D

unleash-client-clojure

Clojars Project Coverage Status cljdoc badge Build Status

A Clojure library wrapping unleash java client

Usage

Getting feature toggles

(require '[unleash-client-clojure.unleash :as u]
         '[unleash-client-clojure.builder :as b])
;; a simple client
(def unleash (u/build (b/app-name "app-name") (b/unleash-api "http://unleash.herokuapp.com/api/")))
;; simple toggle
(u/enabled? unleash "Bit")
;; toggle with context
(require '[unleash-client-clojure.context :as c])
(def user-context (c/build (c/user-id "user-id")))
(u/enabled? unleash "toggle-name" user-context false)
;; more configuration can be passed by using the functions in the builder namespace
(require '[unleash-client-clojure.builder :as b])
(def unleash (u/build "app-name" "instance-id" "http://unleash.herokuapp.com/api/" (b/environment "staging") (b/fetch-toggles-interval 15)))

Variant support

(require '[unleash-client-clojure.variant :as v])
(u/get-variant unleash "DemoVariantWithPayload")
(let [x (u/get-variant unleash "DemoVariantWithPayload")]
  [(v/get-name x)
   (v/get-type x)
   (v/variant-enabled? x)
   (v/get-value x)])

Advanced client config

;; the builder namespace supports passing builder confgurations as functions
(require '[unleash-client-clojure.builder :as b])
(def unleash (u/build
               (b/app-name "app-name")
               (b/unleash-api "http://unleash.herokuapp.com/api/")
               (b/environment "staging")
               (b/fetch-toggles-interval 1)))
;; see the builder namespace for more available options

Subscriber support

;; one a subscriber can be pased to the client builder by passing
(b/subscriber my-subscriber)
;; the subscriber namespace has functions to help you build a subsriber
(require '[unleash-client-clojure.subscriber :as s])
;; pass a map with the keys [:on-error :on-event :toggle-evaluated
;; :toggles-fetched :client-metrics :client-registered :toggles-backed-up
;; :toggle-backup-restored] and callbacks you want to register.
;; any missing key defaults to no-op
;; this is a very noisy example:
(def unleash
  (u/build
    (b/app-name "app-name")
    (b/unleash-api "http://unleash.herokuapp.com/api/")
    (b/subscriber
      (s/build {:on-event println})))

TODO:

  • [ ] Integration testing

Can you improve this documentation? These fine people already did:
Ido Barkan, avirogalsky, avi.rogalsky & avirogalsky@Avi-Rogalsky
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close