From 6eafd168de9a24431d4c69710f5e9fb304cce829 Mon Sep 17 00:00:00 2001 From: cpsievert Date: Fri, 29 Jan 2016 17:04:54 -0600 Subject: [PATCH 1/2] modify plotly_domain env var when using API v2, fixes #441 --- R/plotly_POST.R | 2 +- R/utils.R | 13 +++++++------ man/plotly_POST.Rd | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/R/plotly_POST.R b/R/plotly_POST.R index eb9c41c5b7..92f305157a 100644 --- a/R/plotly_POST.R +++ b/R/plotly_POST.R @@ -77,7 +77,7 @@ plotly_POST <- function(x, filename, fileopt = "new", if (sharing[1] == "hidden") { bits <- strsplit(con$url, "/")[[1]] plot_id <- bits[length(bits)] - url <- paste0(get_domain("v2"), "files/", verify("username"), ":", plot_id) + url <- file.path(get_domain("v2"), "files", paste0(verify("username"), ":", plot_id)) bod <- list(share_key_enabled = TRUE) con2 <- httr::PATCH(url, plotly_headers("v2"), body = bod, encode = "json") con$url <- paste0(con$url, "?share_key=", content(con2)$share_key) diff --git a/R/utils.R b/R/utils.R index ae502809ee..005b3b9f53 100644 --- a/R/utils.R +++ b/R/utils.R @@ -184,13 +184,14 @@ struct <- function(x, y, ...) { # TODO: what are some other common configuration options we want to support?? get_domain <- function(type = "main") { - if (type == "stream") { - Sys.getenv("plotly_streaming_domain", "http://stream.plot.ly") - } else if (type == "v2") { - Sys.getenv("plotly_domain", "https://api.plot.ly/v2/") - } else { - Sys.getenv("plotly_domain", "https://plot.ly") + dom <- Sys.getenv("plotly_domain", "https://plot.ly") + if (type == "v2") { + u <- httr::parse_url(dom) + u$hostname <- paste0("api.", u$hostname) + u$path <- "v2" + dom <- httr::build_url(u) } + dom } # plotly's special keyword arguments in POST body diff --git a/man/plotly_POST.Rd b/man/plotly_POST.Rd index e68f806b91..9e5759c552 100644 --- a/man/plotly_POST.Rd +++ b/man/plotly_POST.Rd @@ -5,7 +5,7 @@ \title{Create/Modify plotly graphs} \usage{ plotly_POST(x, filename, fileopt = "new", sharing = c("public", "private", - "secret")) + "hidden")) } \arguments{ \item{x}{either a ggplot object, a plotly object, or a list.} @@ -27,7 +27,7 @@ Plotly feed, your profile, or search engines. You must be logged in to Plotly to view this graph. You can privately share this graph with other Plotly users in your online Plotly account and they will need to be logged in to view this plot. -If 'secret', anyone with this secret link can view this chart. It will +If 'hidden', anyone with this hidden link can view this chart. It will not appear in the Plotly feed, your profile, or search engines. If it is embedded inside a webpage or an IPython notebook, anybody who is viewing that page will be able to view the graph. From b57e1725e92f8dd7248d616f7f16ba0d4c40fcad Mon Sep 17 00:00:00 2001 From: cpsievert Date: Mon, 1 Feb 2016 09:27:40 -0600 Subject: [PATCH 2/2] Instead of inferring api domain, add a new env var --- R/figure.R | 2 +- R/plotly_IMAGE.R | 2 +- R/plotly_POST.R | 5 +++-- R/signup.R | 2 +- R/utils.R | 13 +++++-------- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/R/figure.R b/R/figure.R index 37a62cfb4c..a9ba3c0424 100644 --- a/R/figure.R +++ b/R/figure.R @@ -18,7 +18,7 @@ get_figure <- function(username, id) { if (missing(username)) username <- verify("username") if (missing(id)) stop("Please provide a figure id number") - base_url <- file.path(get_domain(), "apigetfile", username, id) + base_url <- file.path("https://plot.ly/apigetfile", username, id) resp <- httr::GET(base_url, plotly_headers(), httr::config(ssl_verifypeer=FALSE)) process(struct(resp, "figure")) } diff --git a/R/plotly_IMAGE.R b/R/plotly_IMAGE.R index 44042539c8..d6fad7a00c 100644 --- a/R/plotly_IMAGE.R +++ b/R/plotly_IMAGE.R @@ -32,7 +32,7 @@ plotly_IMAGE <- function(x, width = 1000, height = 500, format = "png", scale = scale, encoded = FALSE ) - base_url <- paste0(get_domain("v2"), "images") + base_url <- file.path(get_domain("api"), "v2", "images") resp <- httr::POST(base_url, plotly_headers("v2"), body = to_JSON(bod), if (!missing(out_file)) write_disk(out_file, overwrite = TRUE), ...) diff --git a/R/plotly_POST.R b/R/plotly_POST.R index 92f305157a..80efc117b2 100644 --- a/R/plotly_POST.R +++ b/R/plotly_POST.R @@ -71,13 +71,14 @@ plotly_POST <- function(x, filename, fileopt = "new", args = to_JSON(x$data), kwargs = to_JSON(x[get_kwargs()]) ) - base_url <- file.path(get_domain(), "clientresp") + base_url <- "https://plot.ly/clientresp" resp <- httr::POST(base_url, body = bod) con <- process(struct(resp, "clientresp")) if (sharing[1] == "hidden") { bits <- strsplit(con$url, "/")[[1]] plot_id <- bits[length(bits)] - url <- file.path(get_domain("v2"), "files", paste0(verify("username"), ":", plot_id)) + url <- file.path(get_domain("api"), "v2", "files", + paste0(verify("username"), ":", plot_id)) bod <- list(share_key_enabled = TRUE) con2 <- httr::PATCH(url, plotly_headers("v2"), body = bod, encode = "json") con$url <- paste0(con$url, "?share_key=", content(con2)$share_key) diff --git a/R/signup.R b/R/signup.R index 2d8f5051a3..838f3b0339 100644 --- a/R/signup.R +++ b/R/signup.R @@ -43,7 +43,7 @@ signup <- function(username, email, save = TRUE) { platform = "R", version = as.character(packageVersion("plotly")) ) - base_url <- file.path(get_domain(), "apimkacct") + base_url <- "https://plot.ly/apimkacct" resp <- httr::POST(base_url, body = bod) con <- process(struct(resp, "signup")) if (save) { diff --git a/R/utils.R b/R/utils.R index 005b3b9f53..a5095c0581 100644 --- a/R/utils.R +++ b/R/utils.R @@ -183,15 +183,12 @@ struct <- function(x, y, ...) { } # TODO: what are some other common configuration options we want to support?? -get_domain <- function(type = "main") { - dom <- Sys.getenv("plotly_domain", "https://plot.ly") - if (type == "v2") { - u <- httr::parse_url(dom) - u$hostname <- paste0("api.", u$hostname) - u$path <- "v2" - dom <- httr::build_url(u) +get_domain <- function(type = "") { + if (type == "api") { + Sys.getenv("plotly_api_domain", "https://api.plot.ly") + } else { + Sys.getenv("plotly_domain", "https://plot.ly") } - dom } # plotly's special keyword arguments in POST body