Skip to content

Commit

Permalink
bw compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcastilloavant committed Apr 22, 2016
1 parent 91fafe7 commit a669c94
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: looker3
Type: Package
Title: looker3 (http://github.com/abelcastilloavant/avant-looker3)
Description: Pull data from Looker using the fancy new 3.0 API.
Version: 0.1.2
Version: 0.1.3
Author: Abel Castillo <[email protected]>
Maintainer: Abel Castillo <[email protected]>
Authors@R: c(person("Abel", "Castillo",
Expand Down
14 changes: 14 additions & 0 deletions R/looker3.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ looker3 <- function(model, view, fields,
checkr::validate(model %is% simple_string, view %is% simple_string,
fields %is% character)


if (is.character(filters)) {
filters <- colon_split_to_list(filters)
}

run_inline_query(looker_setup$LOOKER_URL, looker_setup$LOOKER_ID, looker_setup$LOOKER_SECRET,
model, view, fields, filters, limit)
}


colon_split_to_list <- function(string) {
colon_split <- strsplit(string, ": ")
field_names <- lapply(colon_split, `[[`, 1)
values <- lapply(colon_split, `[[`, 2)
names(values) <- field_names
values
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ df <- looker3(model = "thelook",
)
```

Filters can be specified as above, or as a character string with colon separations, e.g.

```
filters = c("orders.created_month: 90 days", "orders.status: complete")
```
11 changes: 10 additions & 1 deletion tests/testthat/test-looker3.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ withr::with_envvar(c(

args <- list(model = "look", view = "items",
fields = c("category.name", "products.count"),
filters = list(c("category.name", "socks")))
filters = list("category.name" = "socks"))

bw_compatible_args <- list(model = "look", view = "items",
fields = c("category.name", "products.count"),
filters = "category.name: socks")

expect_equal(do.call(looker3, args),
c(list(url = fake_env_vars$url, id = fake_env_vars$id, secret = fake_env_vars$secret),
Expand All @@ -63,6 +67,11 @@ withr::with_envvar(c(
c(list(url = fake_env_vars$url, id = fake_env_vars$id, secret = fake_env_vars$secret),
args,
list(limit = 20)))

expect_equal(do.call(looker3, bw_compatible_args),
c(list(url = fake_env_vars$url, id = fake_env_vars$id, secret = fake_env_vars$secret),
args,
list(limit = 10)))
})
})

Expand Down

0 comments on commit a669c94

Please sign in to comment.