Skip to content

Commit f1011c6

Browse files
committed
Merge pull request #20 from merl-dev/master
replaced HTTPClient with Requests
2 parents 4f9c5c9 + 46cc726 commit f1011c6

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
HTTPClient
1+
Requests
22
JSON

src/Plotly.jl

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
__precompile__(true)
2+
13
module Plotly
2-
using HTTPClient.HTTPC
4+
using Requests
35
using JSON
46

57
include("plot.jl")
68
include("utils.jl")
79

10+
#export default_options, default_opts, get_config, get_plot_endpoint, get_credentials,get_content_endpoint,get_template
11+
812
type 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)
148152
end
149153

150154
function __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"] != ""

test/test_utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using JSON
33
using Base.Test
44

55
#test signin only one endpoint specified
6-
@test_throws ErrorException Plotly.signin("fake_username", "fake_api_key", {"plotly_domain"=>"test"})
6+
@test_throws ErrorException Plotly.signin("fake_username", "fake_api_key", Dict("plotly_domain"=>"test"))
77

88
#test signin and get_credentials
99
Plotly.signin("test_username", "test_api_key")
@@ -12,7 +12,7 @@ creds = Plotly.get_credentials()
1212
@test creds.api_key == "test_api_key"
1313

1414
#test signin + endpoints and get_config
15-
endpoints = {"plotly_domain"=>"my_plotly_domain", "plotly_api_domain"=>"my_plotly_api_domain"}
15+
endpoints = Dict("plotly_domain"=>"my_plotly_domain", "plotly_api_domain"=>"my_plotly_api_domain")
1616
Plotly.signin("test_username", "test_api_key", endpoints)
1717
config = Plotly.get_config()
1818
@test config.plotly_domain == "my_plotly_domain"

0 commit comments

Comments
 (0)