0.3.37 docs





    Feb 19, 2018

    Nairobi & New York


    Index of all namespaces

    « Project + dependencies

    The Clojure Web API Client.

    cljs.core — cljsDocsSource


    - * *1 *2 *3 + - / < <= = == > >=

    A *assert* ->ArrayChunk ->ArrayIter ->ArrayList ->ArrayNode ->ArrayNodeIterator ->ArrayNodeSeq ->Atom accumulating-seq-count aclone add-to-string-hash-cache add-watch aget alength alter-meta! ancestors any? apply apply-to array array->transient-hash-map array-chunk array-copy array-copy-downward array-extend-kv array-for array-index-of array-index-of-equiv? array-index-of-identical? array-index-of-keyword? array-index-of-nil? array-index-of-symbol? array-iter array-list array-map array-map-extend-kv array-map-index-of array-reduce array-seq array? ArrayChunk ArrayIter ArrayList ArrayNode ArrayNodeIterator ArrayNodeSeq ASeq aset assoc assoc! assoc-in associative? atom Atom

    B ->BitmapIndexedNode ->BlackNode ->Box balance-left balance-left-del balance-right balance-right-del bit-and bit-and-not bit-clear bit-count bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-shift-right-zero-fill bit-test bit-xor bitmap-indexed-node-index BitmapIndexedNode bitpos BlackNode boolean boolean? booleans bounded-count Box build-subvec butlast byte bytes

    C *clojurescript-version* ->ChunkBuffer ->ChunkedCons ->ChunkedSeq ->Cons cat char char-escapes char? CHAR_MAP chars chunk chunk-append chunk-buffer chunk-cons chunk-first chunk-next chunk-rest ChunkBuffer chunked-seq chunked-seq? ChunkedCons ChunkedSeq ci-reduce clj->js clone clone-and-set cloneable? coll? comp comparator compare compare-and-set! compare-indexed compare-keywords compare-symbols complement completing concat conj conj! cons Cons constantly contains? count counted? create-array-node-seq create-inode-seq create-node create-ns create-tree-map-seq cycle

    D ->Delay dec dedupe default-dispatch-val Delay delay? demunge demunge-pattern demunge-str DEMUNGE_MAP DEMUNGE_PATTERN deref derive descendants disj disj! dispatch-fn dissoc dissoc! distinct distinct? divide do-assoc doall dominates dorun double double-array double? doubles drop drop-last drop-while

    E *e ->Eduction ->EmptyList ->ES6EntriesIterator ->ES6Iterator ->ES6IteratorSeq ->ES6SetEntriesIterator edit-and-set eduction Eduction empty empty-ordered-hash empty-unordered-hash empty? EmptyList enable-console-print! ensure-reduced equiv-map equiv-sequential es6-entries-iterator es6-iterator es6-iterator-seq es6-set-entries-iterator ES6EntriesIterator ES6Iterator ES6IteratorSeq ES6SetEntriesIterator even? every-pred every? ex-cause ex-data ex-info ex-message ExceptionInfo extend-object!

    F *flush-on-newline* false? ffirst filter filterv find find-and-cache-best-method find-macros-ns find-ns find-ns-obj find-ns-obj* first first-array-for-longvec fix fixture1 fixture2 flatten flatten1 float float? floats flush Fn fn->comparator fn? fnext fnil force frequencies

    G -global-hierarchy gensym gensym_counter get get-global-hierarchy get-in get-method get-validator group-by

    H ->HashCollisionNode ->HashMapIter ->HashSetIter hash hash-coll hash-collision-node-find-index hash-combine hash-imap hash-iset hash-keyword hash-map hash-ordered-coll hash-set hash-string hash-string* hash-symbol hash-unordered-coll HashCollisionNode HashMapIter HashSetIter

    I ->IndexedSeq ->IndexedSeqIterator -indexOf IAssociative IAtom IChunk IChunkedNext IChunkedSeq ICloneable ICollection IComparable ICounted ident? identical? identity IDeref IDerefWithTimeout IEditableCollection IEmptyableCollection IEncodeClojure IEncodeJS IEquiv IFn ifn? IHash IIndexed IIterable IKVReduce IList ILookup IMap IMapEntry IMeta imul IMultiFn INamed inc indexed? IndexedSeq IndexedSeqIterator INext infinite? INIT inode-kv-reduce Inst inst-ms inst? instance? int int-array int-rotate-left int? integer? interleave interpose into into-array ints IPending IPrintWithWriter IRecord IReduce IReset IReversible is_proto_ isa? ISeq ISeqable ISequential ISet ISorted IStack ISwap iter ITER_SYMBOL iterable? iterate ITransientAssociative ITransientCollection ITransientMap ITransientSet ITransientVector IUUID IVector IVolatile IWatchable IWithMeta IWriter

    J js->clj js-delete js-invoke js-keys js-mod js-obj js-reserved js-reserved-arr js-reserved? juxt

    K ->KeySeq ->Keyword keep keep-indexed key key->js key-test keys KeySeq Keyword keyword keyword-identical? keyword?

    L *loaded-libs* ->LazySeq ->LazyTransformer ->List -lastIndexOf last lazy-transformer LazySeq LazyTransformer linear-traversal-nth list List list* list? load-file long long-array longs lookup-sentinel

    M *main-cli-fn* ->MetaFn ->MultiFn ->MultiStepper m3-C1 m3-C2 m3-fmix m3-hash-int m3-hash-unencoded-chars m3-mix-H1 m3-mix-K1 m3-seed make-array make-hierarchy map map-indexed map? mapcat mapv mask max max-key memoize merge merge-with meta MetaFn methods min min-key missing-protocol mix-collection-hash mk-bound-fn mod multi-stepper MultiFn MultiStepper munge munge-str

    N *ns* ->Namespace ->NeverEquiv ->NodeIterator ->NodeSeq name namespace Namespace nat-int? native-satisfies? neg-int? neg? never-equiv NeverEquiv new-path newline next nfirst nil-iter nil? nnext NodeIterator NodeSeq not not-any? not-empty not-every? not-native not= ns-interns* ns-lookup ns-name NS_CACHE nth nthnext nthrest number?

    O *out* ->ObjMap obj-clone obj-map obj-map->hash-map obj-map-compare-keys object-array object? ObjMap odd?

    P *print-dup* *print-err-fn* *print-fn* *print-length* *print-level* *print-meta* *print-newline* *print-readably* ->PersistentArrayMap ->PersistentArrayMapIterator ->PersistentArrayMapSeq ->PersistentHashMap ->PersistentHashSet ->PersistentQueue ->PersistentQueueIter ->PersistentQueueSeq ->PersistentTreeMap ->PersistentTreeMapSeq ->PersistentTreeSet ->PersistentVector pack-array-node parents partial partition partition-all partition-by peek persistent! persistent-array-map-seq PersistentArrayMap PersistentArrayMapIterator PersistentArrayMapSeq PersistentHashMap PersistentHashSet PersistentQueue PersistentQueueIter PersistentQueueSeq PersistentTreeMap PersistentTreeMapSeq PersistentTreeSet PersistentVector pop pop! pop-tail pos-int? pos? pr pr-opts pr-sb-with-opts pr-seq-writer pr-sequential-writer pr-str pr-str* pr-str-with-opts pr-with-opts pr-writer pr-writer-ex-info pr-writer-impl prefer-method prefers prefers* preserving-reduced prim-seq print print-map print-meta? print-str println println-str prn prn-str prn-str-with-opts PROTOCOL_SENTINEL push-tail pv-aget pv-aset pv-clone-node pv-fresh-node

    Q qualified-ident? qualified-keyword? qualified-symbol? quot quote-string

    R ->Range ->RangedIterator ->RangeIterator ->RecordIter ->RedNode ->Reduced ->RSeq rand rand-int rand-nth random-sample random-uuid range Range ranged-iterator RangedIterator RangeIterator re-find re-matches re-pattern re-seq realized? record? RecordIter RedNode reduce reduce-kv reduceable? Reduced reduced reduced? reductions regexp? rem remove remove-all-methods remove-method remove-pair remove-watch repeat repeatedly replace replicate reset! reset-cache reset-meta! rest reverse reversible? RSeq rseq rsubseq run!

    S ->SeqIter ->Stepper ->StringBufferWriter ->StringIter ->Subvec ->Symbol scan-array second select-keys seq seq-iter seq-reduce seq? seqable? SeqIter sequence sequential? set set-from-indexed-seq set-print-err-fn! set-print-fn! set-validator! set? short shorts shuffle simple-ident? simple-keyword? simple-symbol? some some-fn some? sort sort-by sorted-map sorted-map-by sorted-set sorted-set-by sorted? special-symbol? split-at split-with spread START stepper Stepper str string-hash-cache string-hash-cache-count string-iter string-print string? StringBufferWriter StringIter subs subseq Subvec subvec swap! swap-global-hierarchy! Symbol symbol symbol-identical? symbol? system-time

    T *target* ->TaggedLiteral ->TransientArrayMap ->TransientHashMap ->TransientHashSet ->TransientVector tagged-literal tagged-literal? TaggedLiteral tail-off take take-last take-nth take-while test throw-no-method-error to-array to-array-2d trampoline transduce transient TransientArrayMap TransientHashMap TransientHashSet TransientVector tree-map-add tree-map-append tree-map-kv-reduce tree-map-remove tree-map-replace tree-map-seq-push tree-seq true? truth_ tv-editable-root tv-editable-tail tv-ensure-editable tv-pop-tail tv-push-tail type type->str

    U *unchecked-if* ->UUID unchecked-add unchecked-add-int unchecked-array-for unchecked-byte unchecked-char unchecked-dec unchecked-dec-int unchecked-divide-int unchecked-double unchecked-editable-array-for unchecked-float unchecked-inc unchecked-inc-int unchecked-int unchecked-long unchecked-multiply unchecked-multiply-int unchecked-negate unchecked-negate-int unchecked-remainder-int unchecked-short unchecked-subtract unchecked-subtract-int undefined? underive unreduced unsigned-bit-shift-right update update-in uuid UUID uuid?

    V ->ValSeq ->Var ->VectorNode ->Volatile val vals ValSeq Var var? vary-meta vec vector vector-index-out-of-bounds vector? VectorNode Volatile volatile! volatile? vreset!

    W with-meta write-all

    Z zero? zipmap

    The README below is fetched from the published project artifact. Some relative links may be broken.

    Build Status


    Ona API client library in Clojure and ClojureScript


    This library exposes ONA endpoints for retrieving and submitting data through CLJ and CLJS applications.


    Install via clojars with:

    Clojars Project

    Current API Endpoints

    • charts
    • forms
    • media
    • organizations
    • projects
    • profiles
    • teams
    • user
    • xls-reports

    Setting credentials in milia

    Milia stores credentials in the milia.utils.remote/*credentials* dynamic var map, which defaults to:

    {:temp-token nil
     :token nil
     :username nil
     :password nil}

    Set the map by creating a binding:

    (binding [milia.utils.remote/*credentials* {:username "username"
                                                :temp-token "SECRET TOKEN"}]

    And then within that binding change the value of the var using set!:

    (set! milia.utils.remote/*credentials* {:temp-token "NEW SECRET TOKEN"})

    WARNING From CLJS you should ONLY set the temp-token, setting another type of token would expose a permanent credential to client side attackers.

    From CLJ you may also set the token and the username and password. If temp-token exists it will be used, if not token will be used, and if neither exist the username and password will be used for authentication.

    Credential auto-renewal

    If a temp-token is supplied in the credentials var it will be used for authentication before any other methods. As the name would suggest temp-tokens are temporary and do expire. How an expiration is handled differs depending on the target platform.

    In CLJ, if a request fails with a 401 authorization error:

    1. A request is made to the user endpoint using the token credential, which is a permanent key. If a token was not supplied, this request will fail and the failure is returned.
    2. If this request succeeds, we will receive a new temp-token. We then call set! and add the refreshed temp-token into the credentials var.
    3. We retry our initial request. If it fails again, an exception is raised or returned depending on the value of the supress-4xx-exceptions? option in the originating call.

    In CLJS, if a request fails with a 401 authorization error:

    We reload the page. TODO attempt a session based refresh mediated by a client backend.

    Handling Errors

    If the server that milia attempts to connect to returns an exceptional status,

    =400, or if there is a connection problem, milia may raise an exception.

    Milia will raise an exception if:

    1. there is a connection problem in which the server does no return a response or returns a response that does not include a status code,
    2. the server returns a 4xx status and the suppress-4xx-exceptions? flag is false,
    3. the server returns a 5xxx status code.

    If milia raises an exception it will be a map with the key reason and, depending on the type, a key detail which is another map with the keys response and status-code. Examples are shown below:

    No response:

    {:reason :no-http-response}

    4xx response:

    {:reason :http-client-error
     :detail {:response <parsed-json-from-server>
              :status-code <status-code>}

    5xx response:

    {:reason :http-server-error
     :detail {:response <raw-response>
              :status-code <status-code>}

    Setting up a remote server

    You can change the remote server URLs by importing and updating the hosts atom:

      (:require [milia.utils.remote :as milia-remote])
    ;; set the hosts atom in milia to custom hosts
    (defn set-remote-host [] 
      (swap! milia-remote/hosts merge {:client ""
                                       :data ""
                                       :request-protocol "https"
                                       :refresh-path "z/path"}))


    Set the environment variable DEBUG_API to true to enable console debugging output on API requests.

    Using Milia in JavaScript

    To use milia in JavaScript you will have to compile milia and then refer to the compiled output in your JavaScript code. Below are example steps to follow and an example HTML file using the basic features of milia.

    1. Compile the ClojureScript code to JavaScript: lein cljsbuild once prod
    2. Copy the output JavaScript from resources/public/js/lib/milia.js, local to your root milia folder to the location of your choice.
    3. Load the compiled JavaScript into your application.
    4. Use the JavaScript helpers in milia.utils.remote to the set the remote server and the credentials to authenticate against that server.
    5. Only call milia functions that are exported to JavaScript.

    For example:

      <script type="text/javascript" src="resources/public/js/lib/milia.js"></script>
      <script type="text/javascript">
        milia.utils.remote.set_credentials("[username]", "[password]");;

    NOTE: In the above, and any other HTML example, the domain hosting the HTML page must have cross-origin access rights to the Ona server you are requesting data from.

    [TODO] Proposed Client Architecture

    Convert remaining API endpoint files to cljc:

    • charts
    • images
    • j2x