LookerQuery: LookerQuery

Description Usage Arguments Examples

View source: R/query.R

Description

Builds an API call in the form of a GET

Usage

1
LookerQuery(dictionary, query, fields, filters = NULL)

Arguments

dictionary
query
fields
filters

Examples

 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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (dictionary, query, fields, filters = NULL) 
{
    require(RCurl)
    require(rjson)
    require(digest)
    Looker$field_list <- paste(as.character(sort(fields)), sep = "' '", 
        collapse = ",")
    Looker$today <- format(Sys.time(), format = "%a, %d %b %Y %H:%M:%S -0800")
    Looker$location <- paste("/api/dictionaries", dictionary, 
        "queries", paste(query, ".json", sep = ""), sep = "/")
    Looker$nonce <- paste(sample(c(letters[1:26], sample(0:9, 
        10)), 32), collapse = "")
    if (is.null(filters)) {
        Looker$url <- paste("https://", Looker$host, Looker$location, 
            "?", paste("fields=", Looker$field_list, sep = ""), 
            sep = "")
    }
    else {
        filter_list_clean <- filtersClean(sort(filters))
        Looker$url <- paste("https://", Looker$host, Looker$location, 
            "?", paste("fields=", Looker$field_list, sep = ""), 
            "&", filter_list_clean, sep = "")
    }
    if (is.null(filters)) {
        Looker$StringToSign <- paste("GET", "\n", Looker$location, 
            "\n", Looker$today, "\n", Looker$nonce, "\n", paste("fields=", 
                Looker$field_list, sep = ""), "\n", sep = "")
    }
    else {
        Looker$StringToSign <- paste("GET", "\n", Looker$location, 
            "\n", Looker$today, "\n", Looker$nonce, "\n", paste("fields=", 
                Looker$field_list, sep = ""), "\n", paste(gsub("&", 
                "\n", filter_list_clean), "\n", sep = ""), sep = "")
    }
    Looker$signature <- base64(hmac(Looker$secret, enc2utf8(Looker$StringToSign), 
        algo = "sha1", raw = TRUE), encode = TRUE)[1]
    Looker$authorization <- paste(Looker$token, Looker$signature, 
        sep = ":")
    Looker$results <- getURL(Looker$url, httpheader = c(Authorization = Looker$authorization, 
        Date = Looker$today, `x-llooker-nonce` = Looker$nonce, 
        Accept = "application/json", `x-llooker-api-version` = 1), 
        .opts = list(ssl.verifypeer = FALSE, timeout = 3))
    Looker$output <- LookerToDataFrame(Looker$results)
    return(Looker$output)
  }

robertzk/LookR documentation built on May 27, 2019, 10:33 a.m.