Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sc_table_custom() #6

Closed
GregorDeCillia opened this issue Feb 5, 2021 · 0 comments
Closed

Add sc_table_custom() #6

GregorDeCillia opened this issue Feb 5, 2021 · 0 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@GregorDeCillia
Copy link
Contributor

GregorDeCillia commented Feb 5, 2021

Implement a function that takes ids for a database, measures and fields and sends a json request. Here is a snippet on how to do that manually at the moment

# pick a dataset
db_id <- "detouextregsai"
db_schema <- sc_schema_db(db_id)
db_uid <- paste0("str:database:", db_id)

# browse the schema to obtain resource ids
id_arrivals <- db_schema$Facts$Arrivals$Arrivals$id
id_time <- db_schema$`Mandatory fields`$`Season/Tourism Month`$`Season/Tourism Month`$id

# get the response
json_list <- list(database = db_uid, measures = list(id_arrivals), dimensions = list(list(id_time)))
response <- httr::POST(
  url = paste0(STATcubeR:::base_url, "/table"),
  body = jsonlite::toJSON(json_list, auto_unbox = TRUE),
  encode = "raw",
  config = httr::add_headers(APIKey = sc_key())
)

# convert to class sc_table
my_table <- STATcubeR:::sc_table_class$new(response)

Transofm this snippet into a function

sc_table_custom(database_id, measures, fields)
@GregorDeCillia GregorDeCillia added the feature New feature or request label Feb 5, 2021
@GregorDeCillia GregorDeCillia self-assigned this Feb 5, 2021
@GregorDeCillia GregorDeCillia added this to the Version 1.0 milestone Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant