@@ -141,10 +141,11 @@ struct <- function(x, y, ...) {
141
141
get_domain <- function (type = " main" ) {
142
142
if (type == " stream" ) {
143
143
Sys.getenv(" plotly_streaming_domain" , " http://stream.plot.ly" )
144
+ } else if (type == " v2" ) {
145
+ Sys.getenv(" plotly_domain" , " https://api.plot.ly/v2/" )
144
146
} else {
145
147
Sys.getenv(" plotly_domain" , " https://plot.ly" )
146
148
}
147
-
148
149
}
149
150
150
151
# plotly's special keyword arguments in POST body
@@ -153,12 +154,28 @@ get_kwargs <- function() {
153
154
}
154
155
155
156
# POST header fields
156
- plotly_headers <- function () {
157
- httr :: add_headers(.headers = c(
158
- " plotly-username" = verify(" username" ),
159
- " plotly-apikey" = verify(" api_key" ),
160
- " plotly-version" = as.character(packageVersion(" plotly" )),
161
- " plotly-platform" = " R" ))
157
+ # ' @importFrom base64enc base64encode
158
+ plotly_headers <- function (type = " main" ) {
159
+ usr <- verify(" username" )
160
+ key <- verify(" api_key" )
161
+ v <- as.character(packageVersion(" plotly" ))
162
+ h <- if (type == " v2" ) {
163
+ auth <- base64enc :: base64encode(charToRaw(paste(usr , key , sep = " :" )))
164
+ c(
165
+ " authorization" = paste(" Basic" , auth ),
166
+ " plotly-client-platform" = paste(" R" , v ),
167
+ " plotly_version" = v ,
168
+ " content-type" = " application/json"
169
+ )
170
+ } else {
171
+ c(
172
+ " plotly-username" = usr ,
173
+ " plotly-apikey" = key ,
174
+ " plotly-version" = v ,
175
+ " plotly-platform" = " R"
176
+ )
177
+ }
178
+ httr :: add_headers(.headers = h )
162
179
}
163
180
164
181
# try to write environment variables to an .Rprofile
0 commit comments