1+ __precompile__ (true )
2+
13module Plotly
2- using HTTPClient . HTTPC
4+ using Requests
35using JSON
46
57include (" plot.jl" )
68include (" utils.jl" )
79
10+ # export default_options, default_opts, get_config, get_plot_endpoint, get_credentials,get_content_endpoint,get_template
11+
812type CurrentPlot
913 filename:: ASCIIString
1014 fileopt:: ASCIIString
@@ -49,19 +53,22 @@ function plot(data::Array,options=Dict())
4953 creds = get_credentials ()
5054 endpoint = get_plot_endpoint ()
5155 opt = merge (default_options,options)
56+
57+ # post("http://httpbin.org/post"; headers = Dict("Date" => "Tue, 15 Nov 1994 08:12:31 GMT"), cookies = Dict("sessionkey" => "abc"))
58+
5259 r = post (endpoint,
53- merge (default_opts,
60+ data = merge (default_opts,
5461 Dict (
5562 " un" => creds. username,
5663 " key" => creds. api_key,
5764 " args" => json (data),
5865 " kwargs" => json (opt)
5966 ))
6067 )
61- body= JSON . parse ( bytestring (r . body) )
68+ body= Requests . json (r )
6269
63- if r . http_code != 200
64- error ([" r.http_code " ])
70+ if statuscode (r) != 200
71+ error ([" r.status " ])
6572 elseif body[" error" ] != " "
6673 error (body[" error" ])
6774 else
@@ -78,7 +85,7 @@ function layout(layout_opts::Dict,meta_opts=Dict())
7885 merge! (meta_opts,get_required_params ([" filename" ," fileopt" ],meta_opts))
7986
8087 r = post (endpoint,
81- merge (default_opts,
88+ data = merge (default_opts,
8289 Dict (" un" => creds. username,
8390 " key" => creds. api_key,
8491 " args" => json (layout_opts),
@@ -94,7 +101,7 @@ function style(style_opts,meta_opts=Dict())
94101 merge! (meta_opts,get_required_params ([" filename" ," fileopt" ],meta_opts))
95102
96103 r = post (endpoint,
97- merge (default_opts,
104+ data = merge (default_opts,
98105 Dict (" un" => creds. username,
99106 " key" => creds. api_key,
100107 " args" => json ([style_opts]),
@@ -118,12 +125,9 @@ function getFile(file_id::ASCIIString, owner=None)
118125
119126 auth = string (" Basic " , base64 (" $username :$api_key " ))
120127
121- options = RequestOptions (headers= [
122- (" Authorization" , auth),
123- (" Plotly-Client-Platform" , lib_version)
124- ])
128+ options = Dict (" Authorization" => auth," Plotly-Client-Platform" => lib_version)
125129
126- r = get (endpoint, options)
130+ r = get (endpoint, headers = options)
127131 print (r)
128132
129133 __parseresponse (r)
@@ -148,9 +152,9 @@ function get_required_params(required,opts)
148152end
149153
150154function __parseresponse (r)
151- body= JSON . parse ( bytestring (r . body) )
152- if r . http_code != 200
153- error ([" r.http_code " ])
155+ body= Requests . json (r )
156+ if statuscode (r) != 200
157+ error ([" r.status " ])
154158 elseif haskey (body, " error" ) && body[" error" ] != " "
155159 error (body[" error" ])
156160 elseif haskey (body, " detail" ) && body[" detail" ] != " "
0 commit comments