Skip to content

Commit 01d28e2

Browse files
committed
allow for plot, layout, style, and getFile functions to use config endpoints
1 parent 93802ef commit 01d28e2

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

src/Plotly.jl

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,14 @@ function get_content_endpoint(file_id::String, owner::String)
184184
end
185185

186186
function plot(data::Array,options=Dict())
187-
global plotlyaccount
188-
if !isdefined(Plotly,:plotlyaccount)
189-
println("Please 'signin(username, api_key)' before proceeding. See http://plot.ly/API for help!")
190-
return
191-
end
187+
creds = get_credentials()
188+
endpoint = get_plot_endpoint()
192189
opt = merge(default_options,options)
193-
r = post("http://plot.ly/clientresp",
190+
r = post(endpoint,
194191
merge(default_opts,
195192
{
196-
"un" => plotlyaccount.username,
197-
"key" => plotlyaccount.api_key,
193+
"un" => creds.username,
194+
"key" => creds.api_key,
198195
"args" => json(data),
199196
"kwargs" => json(opt)
200197
})
@@ -215,34 +212,28 @@ end
215212
include("plot.jl")
216213

217214
function layout(layout_opts::Dict,meta_opts=Dict())
218-
global plotlyaccount
219-
if !isdefined(Plotly,:plotlyaccount)
220-
println("Please 'signin(username, api_key)' before proceeding. See http://plot.ly/API for help!")
221-
return
222-
end
215+
creds = get_credentials()
216+
endpoint = get_plot_endpoint()
223217

224218
merge!(meta_opts,get_required_params(["filename","fileopt"],meta_opts))
225219

226-
r = post("http://plot.ly/clientresp",
220+
r = post(endpoint,
227221
merge(default_opts,
228-
{"un" => plotlyaccount.username,
229-
"key" => plotlyaccount.api_key,
222+
{"un" => creds.username,
223+
"key" => creds.api_key,
230224
"args" => json(layout_opts),
231225
"origin" => "layout",
232226
"kwargs" => json(meta_opts)}))
233227
__parseresponse(r)
234228
end
235229

236230
function style(style_opts,meta_opts=Dict())
237-
global plotlyaccount
238-
if !isdefined(Plotly,:plotlyaccount)
239-
println("Please 'signin(username, api_key)' before proceeding. See http://plot.ly/API for help!")
240-
return
241-
end
231+
creds = get_credentials()
232+
endpoint = get_plot_endpoint()
242233

243234
merge!(meta_opts,get_required_params(["filename","fileopt"],meta_opts))
244235

245-
r = post("http://plot.ly/clientresp",
236+
r = post(endpoint,
246237
merge(default_opts,
247238
{"un" => plotlyaccount.username,
248239
"key" => plotlyaccount.api_key,
@@ -253,27 +244,26 @@ function style(style_opts,meta_opts=Dict())
253244
end
254245

255246

256-
function getFile(file_id::String, file_owner=None)
257-
global plotlyaccount
258-
259-
user = plotlyaccount.username
260-
apikey = plotlyaccount.api_key
247+
function getFile(file_id::String, owner=None)
248+
creds = get_credentials()
249+
username = creds.username
250+
api_key = creds.api_key
261251

262-
if (file_owner == None)
263-
file_owner = user
252+
if (owner == None)
253+
owner = username
264254
end
265255

266-
url = "https://api.plot.ly/v2/files/$file_owner:$file_id/content"
256+
endpoint = get_content_endpoint(file_id, owner)
267257
lib_version = string(default_opts["platform"], " ", default_opts["version"])
268258

269-
auth = string("Basic ", base64("$user:$apikey"))
259+
auth = string("Basic ", base64("$username:$api_key"))
270260

271261
options = RequestOptions(headers=[
272262
("Authorization", auth),
273263
("Plotly-Client-Platform", lib_version)
274264
])
275265

276-
r = get(url, options)
266+
r = get(endpoint, options)
277267

278268
__parseresponse(r)
279269

0 commit comments

Comments
 (0)