cmr.client.common.util

Utility functions for general use by both the Clojure client and the ClojureScript client.

create-http-client-constructor

(create-http-client-constructor client-constructor-var client-data-constructor)

This is a utility function that returns a function for creating clients of a particular type, e.g., ingest, search, or access-control clients.

The arguments details are as follows:

  • client-constructor-var - this is the var of that is assigned the value of the call to create-service-client-constructor; it is passed so that the anonymous function below has something to refer to in support of multiple arities
  • client-data-constructor - this is the constrcutor for the record that is used for the implementation of the protocol (that which is extended)

create-service-client-constructor

(create-service-client-constructor service-type client-constructor-var client-data-constructor options-fn http-client-constructor)

This is a utility function that returns a function for creating clients of a particular type, e.g., ingest, search, or access-control clients.

The arguments details are as follows:

  • service-type - must be one of the supported service types, notably :ingest, :search, or :access-control
  • client-constructor-var - this is the var of that is assigned the value of the call to create-service-client-constructor; it is passed so that the anonymous function below has something to refer to in support of multiple arities
  • client-data-constructor - this is the constrcutor for the record that is used for the implementation of the protocol (that which is extended)
  • options-fn - a functin which creates the client client options, including basic defaults, for the implementation; it should be a function that in turn calls a CMR*ClientOpions constructor
  • http-client-constructor - a function that instrantiates the CMR HTTP client used by all CMR service type clients (different for Clojure and ClojureScript)

This docstring is a bit dense; for more clarity, be sure to view the calls made to this function in both the Clojure and ClojureScript clients.

get-default-endpoint

(get-default-endpoint options service-key)

Get the default endpoint; if the client options specify an endpoint, then use that one.

get-default-token

(get-default-token options)

Use the token that is defined in the options data structure; if one is not provided, a null value for token will be used.

get-endpoint

(get-endpoint service-key)(get-endpoint environment-type service-key)

Get the default endpoint for a given CMR service. If an environment type is provided, override the default and get the endpoint for that type.

import-def

macro

(import-def from-ns def-name)

Import a single function or var:

(import-def a b) => (def b a/b)

import-vars

macro

(import-vars & imports)

Import multiple defs from multiple namespaces.

This works for vars and functions, but not macros. Uses the same syntax as potemkin.namespaces/import-vars, namely: (import-vars [m.n.ns1 a b] [x.y.ns2 d e f])

parse-endpoint

(parse-endpoint endpoint)(parse-endpoint endpoint service-key)

Given a string or a deployment environment and a service key, retur the service endpoint.

with-callback

(with-callback chan callback)

A utility function for running a callback function when a channel receives data.