Created
July 28, 2017 04:14
-
-
Save russellpierce/a93df7900859777686fb9f6a23dc6d0d to your computer and use it in GitHub Desktop.
Create an embed URL for Periscope in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Create Embed for Periscope | |
#' | |
#' Code not complete | |
#' | |
#' @param dashboard | |
#' @param filters | |
#' @param api_key | |
# '@author Russell S. Pierce, \email{Russell.Pierce@@zapier.com} | |
# '@author Christopher Peters, \email{chris.peters@@zapier.com} | |
#' @return | |
#' @export | |
#' @author | |
#' @importFrom digest hmac | |
#' @importFrom jsonlite minify | |
#' @importFrom whisker whisker.render | |
#' @examples | |
#' # create_embed(7863, filters = '[{"name": "Filter1", "value": "value1"}, {"name": "Filter2", "value": "1234"}]', api_key = 'your api key here') | |
create_embed <- function(dashboard, | |
filters, | |
api_key) { | |
url <- whisker::whisker.render('{ | |
"dashboard": {{dashboard}}, | |
"embed": "v2", | |
"filters": {{{filters}}} | |
}', list(dashboard = dashboard, filters = filters), ) %>% | |
jsonlite::minify() %>% | |
utils::URLencode(reserved = TRUE) | |
signature <- url %>% | |
{paste0(hmac(api_key, paste0("/api/embedded_dashboard?data=", .), algo="sha256", raw = T) %>% as.character, collapse="")} | |
paste0("https://www.periscopedata.com/api/embedded_dashboard?data=", url, "&signature=", signature) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment