/
dataview.cljc
80 lines (70 loc) · 2.65 KB
/
dataview.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(ns milia.api.dataview
(:refer-clojure :exclude [get update])
(:require [milia.api.http :refer [parse-http]]
[milia.utils.remote :refer [make-url]]))
(defn create
"Create new dataview from existing dataset"
[params]
(let [url (make-url "dataviews")
options {:form-params params}]
(parse-http :post url
:http-options options :suppress-4xx-exceptions? true)))
(defn get
"Retrieves dataview object using dataview id"
[dataview-id & {:keys [no-cache?]}]
(let [url (make-url "dataviews" dataview-id)]
(parse-http :get url :no-cache? no-cache? :suppress-4xx-exceptions? true)))
(defn data
"Retrieves dataview data by ID and with the optional parameters."
[dataview-id & {:keys [:raw? :must-revalidate? :query-params]}]
(let [url (make-url "dataviews" dataview-id "data.json")
options {:query-params query-params}]
(parse-http :get url
:http-options options
:must-revalidate? must-revalidate?
:raw-response? raw?
:suppress-4xx-exceptions? true)))
(defn form
"Retrieves form used to create dataview"
[dataview-id]
(let [url (make-url "dataviews" dataview-id "form.json")]
(parse-http :get url :suppress-4xx-exceptions? true)))
(defn form-details
"Retrieves details of form used to create dataview"
[dataview-id]
(let [url (make-url "dataviews" dataview-id "form_details")]
(parse-http :get url :suppress-4xx-exceptions? true)))
(defn count-data
"Counts data instances returned by dataview object"
[dataview-id]
(let [url (make-url "dataviews" dataview-id "data")
options {:query-params {:count true}}]
(parse-http :get url :http-options options :suppress-4xx-exceptions? true)))
(defn all
"Retrieves all dataview objects"
[]
(let [url (make-url "dataviews")]
(parse-http :get url :suppress-4xx-exceptions? true)))
(defn update
"Updates dataview object"
[dataview-id params]
(let [url (make-url "dataviews" dataview-id)
options {:form-params params}]
(parse-http :put url :http-options options :suppress-4xx-exceptions? true)))
(defn delete
"Deletes dataview object"
[dataview-id]
(let [url (make-url "dataviews" dataview-id)]
(parse-http :delete url)))
(defn download-xls-report
"Download xls report from the j2x service"
([dataset-id meta-id filename data-id]
(let [suffix (str dataset-id "/xls_export?"
"meta=" meta-id
"&data_id="data-id)
url (make-url "dataviews" suffix)]
(parse-http :get
url
:http-options {:as :byte-array}
:as-map? true
:filename filename))))