8000 Merge branch 'master' of github.com:AppsFlyer/unleash-client-clojure · AppsFlyer/unleash-client-clojure@5a16bd4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5a16bd4

Browse files
committed
Merge branch 'master' of github.com:AppsFlyer/unleash-client-clojure
deploy 0.2.0
2 parents d427888 + f1ce7f6 commit 5a16bd4

File tree

5 files changed

+49
-30
lines changed

5 files changed

+49
-30
lines changed

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
[![Coverage Status](https://coveralls.io/repos/github/AppsFlyer/unleash-client-clojure/badge.svg?branch=master)](https://coveralls.io/github/AppsFlyer/unleash-client-clojure?branch=master)
55

66
A Clojure library wrapping [unleash java client](https://github.com/Unleash/unleash-client-java)
7+
78
## Usage
89

910
### Getting feature toggles
11+
1012
```clojure
11-
(require '[unleash-client-clojure.unleash :as u])
13+
(require '[unleash-client-clojure.unleash :as u]
14+
'[unleash-client-clojure.builder :as b])
1215
;; a simple client
13-
(def unleash (u/build "app-name" "instance-id" "http://unleash.herokuapp.com/api/"))
16+
(def unleash (u/build (b/app-name "app-name") (b/unleash-api "http://unleash.herokuapp.com/api/")))
1417
;; simple toggle
1518
(u/enabled? unleash "Bit")
1619
;; toggle with context
@@ -23,6 +26,7 @@ A Clojure library wrapping [unleash java client](https://github.com/Unleash/unle
2326
```
2427

2528
### Variant support
29+
2630
```clojure
2731
(require '[unleash-client-clojure.variant :as v])
2832
(u/get-variant unleash "DemoVariantWithPayload")
@@ -34,16 +38,20 @@ A Clojure library wrapping [unleash java client](https://github.com/Unleash/unle
3438
```
3539

3640
### Advanced client config
41+
3742
```clojure
3843
;; the builder namespace supports passing builder confgurations as functions
3944
(require '[unleash-client-clojure.builder :as b])
40-
(def unleash (u/build "app-name" "instance-id" "http://unleash.herokuapp.com/api/"
41-
(b/environment "staging")
42-
(b/fetch-toggles-interval 1)))
45+
(def unleash (u/build
46+
(b/app-name "app-name")
47+
(b/unleash-api "http://unleash.herokuapp.com/api/")
48+
(b/environment "staging")
49+
(b/fetch-toggles-interval 1)))
4350
;; see the builder namespace for more available options
4451
```
4552

4653
### Subscriber support
54+
4755
```clojure
4856
;; one a subscriber can be pased to the client builder by passing
4957
(b/subscriber my-subscriber)
@@ -55,12 +63,13 @@ A Clojure library wrapping [unleash java client](https://github.com/Unleash/unle
5563
;; any missing key defaults to no-op
5664
;; this is a very noisy example:
5765
(def unleash
58-
(u/build "app-name"
59-
"instance-id"
60-
"http://unleash.herokuapp.com/api/"
61-
(b/subscriber
62-
(s/build {:on-event println})))
66+
(u/build
67+
(b/app-name "app-name")
68+
(b/unleash-api "http://unleash.herokuapp.com/api/")
69+
(b/subscriber
70+
(s/build {:on-event println})))
6371
```
6472

6573
#### TODO:
74+
6675
- [ ] Integration testing

project.clj

Lines changed: 1 addition & 1 deletion
< 8000 /tr>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject unleash-client-clojure "0.1.2"
1+
(defproject unleash-client-clojure "0.2.0-SNAPSHOT"
22
:description "A Clojure library wrapping https://github.com/Unleash/unleash-client-java"
33
:url "https://github.com/AppsFlyer/unleash-client-clojure"
44
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"

src/unleash_client_clojure/builder.clj

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@
33
[no.finn.unleash.util UnleashConfig UnleashConfig$Builder UnleashScheduledExecutor]
44
[no.finn.unleash.event UnleashSubscriber]))
55

6-
(defn build ^UnleashConfig
7-
[app-name ^String instance-id ^String api & fs]
8-
(let [bldr
9-
(-> (UnleashConfig$Builder.)
10-
(.appName app-name)
11-
(.instanceId instance-id)
12-
(.unleashAPI api))]
6+
(defn build ^UnleashConfig [& fs]
7+
(let [bldr (UnleashConfig$Builder.)]
138
(.build ^UnleashConfig$Builder
149
(reduce
1510
(fn
16-
([] bldr)
11+
([] bldr)
1712
([bldr f]
1813
(f bldr)))
1914
bldr
2015
fs))))
2116

17+
(defn app-name [^String name]
18+
(fn [^UnleashConfig$Builder bldr]
19+
(.appName bldr name)))
20+
21+
(defn instance-id [^String id]
22+
(fn [^UnleashConfig$Builder bldr]
23+
(.instanceId bldr id)))
24+
25+
(defn unleash-api [^String api]
26+
(fn [^UnleashConfig$Builder bldr]
27+
(.unleashAPI bldr api)))
28+
2229
(defn custom-http-header [header-name header-value]
2330
(fn [^UnleashConfig$Builder bldr]
2431
(.customHttpHeader bldr header-name header-value)))

src/unleash_client_clojure/unleash.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@
5353
(vec (.getFeatureToggleNames this))))
5454

5555
(defn build
56-
[app-name ^String instance-id ^String api & fs]
57-
(DefaultUnleash. (apply builder/build app-name instance-id api fs)
56+
[& fs]
57+
(DefaultUnleash. (apply builder/build fs)
5858
(into-array Strategy [])))
5959

6060
(defn build-with-custom-strategies
61-
[app-name ^String instance-id ^String api strategies & fs]
62-
(DefaultUnleash. (apply builder/build app-name instance-id api fs)
61+
[strategies & fs]
62+
(DefaultUnleash. (apply builder/build fs)
6363
(into-array Strategy strategies)))

test/unleash_client_clojure/builder_test.clj

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010
(deftest builder
1111
(testing "building unleash sets correct config"
12-
(let [app-name "app"
13-
instance-id "some-instance"
12+
(let [app-name "app"
13+
instance-id "some-instance"
1414
api "http://127.0.0.1"
15-
backup-path (s/join File/separatorChar
15+
backup-path (s/join File/separatorChar
1616
[(System/getProperty "java.io.tmpdir") (str (rand-int 100) ".json")])
1717
context (c/build (c/app-name "some-app"))
1818
subscriber (subscriber/build {})
19-
config (b/build app-name instance-id api
19+
config (b/build
20+
(b/app-name app-name)
21+
(b/instance-id instance-id)
22+
(b/unleash-api api)
2023
(b/custom-http-header "header-name" "header-value")
2124
(b/send-metrics-interval 42)
2225
(b/fetch-toggles-interval 43)
@@ -26,12 +29,12 @@
2629
(b/environment "staging")
2730
(b/custom-http-header-provider
2831
(reify CustomHttpHeadersProvider
29-
(getCustomHeaders [_] {"foo" "bar"})))
32+
(getCustomHeaders [_] {"foo" "bar"})))
3033
(b/unleash-context-provider
3134
(reify UnleashContextProvider
32-
(getContext [_] context)))
35+
(getContext [_] context)))
3336
(b/subscriber subscriber))]
34-
37+
3538
(is (= {"header-name" "header-value"}
3639
(.getCustomHttpHeaders config)))
3740
(is (= 42

0 commit comments

Comments
 (0)
0