A Clojure library designed to interact with Tableau APIs including Data Extract API, REST Server API and the undocumented Web Service API.
clj-tableau
is available as a Maven artifact from Clojars:
clj-tableau
supports clojure 1.6.0 and higher.
To use tableau extract API you should download and manually put the dependent jar files (dataextract.jar
and jna.jar
) to the /resources
folder. Please make sure that the TDE library binaries are included in the PATH environment variable.
The TDE related functionality is provided by the clj-tableau.dataextract
namespace.
First, require it in the REPL:
(require '[clj-tableau.dataextract :refer :all])
Or in your application:
(ns my-app.core
(:require [clj-tableau.dataextract :refer :all]))
Opening or creating a TDE file:
(with-extract [tdefile "myfile.tde"]
<yourcode>
)
tdefile
handle will be closed when you leave the closure. To create a new table inside tdefile
and add two rows in it:
; define table structure
(def mytable-def
; collation can be omitted
;
{ :collation Collation/EN_GB
:columns [ :foo Type/String
:bar Type/Integer]})
(with-extract [tdefile "myfile.tde"]
(->
; open or create new table in tde file
; if tde exists, mytable-def parameter
; is not required
(table tdefile "Extract" mytable-def)
; add-rows take table + sequence of vectors
; with column values
(add-rows '(["first" 1] ["second" 2]))))
You can add lines one-by-one with add-row
or pass (lazy) sequences to add-rows
function. Row should be vec
with same number of elements as defined columns in extract table.
If you append rows to an existing TDE file then the table definition parameter of table
function can be omitted.
REST API support is a new addition to clj-tableau. Our implementation uses the clj-http
and data.xml
clojure libraries. This new namespace allows to query site, group & user related information supplied by Tableau Server.
The first step is to require the namespace in our REPL:
(require '[clj-tableau.restapi :refer :all])
You have two options for logging onto your desired Tableau Server:
(logon-to-server "http://tableau-server.com" "TestSite" "JohnDoe" "secret")
(with-tableau-rest-api [sess ["http://tableau-server.com" "TestSite" "JohnDoe" "secret"]]
(->>
(get-users-on-site sess)))
Most of the functions require you to pass an existing session. For example if you would like to know the list of groups on the server then all you need to do is:
(get-groups-on-site (logon-to-server "http://tableau-server.com" "TestSite" "JohnDoe" "secret"))
The same goes for listing all users on the site:
(get-users-on-site (logon-to-server "http://tableau-server.com" "TestSite" "JohnDoe" "secret"))
For a full list of available functions please refer to:
Example codes are located under /doc
folder.
Copyright © 2015 Tamas Foldi (@tfoldi), Starschema Ltd.
Distributed under BSD License.