Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit f7b7286

Browse files
author
alexander-daniel
committed
killed signup() and changed plot to use request
1 parent 7eefc98 commit f7b7286

3 files changed

Lines changed: 20 additions & 97 deletions

File tree

‎examples/signup-example.js‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎index.js‎

Lines changed: 18 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -32,58 +32,6 @@ function Plotly(username,api_key) {
3232
this.origin="plot";
3333
}
3434

35-
Plotly.prototype.signup = function(username, email, callback) {
36-
var self = this;
37-
38-
if (!callback) { callback = function() {}; }
39-
40-
var pack = {'version': this.version, 'un': username, 'email': email, 'platform':this.platform };
41-
var urlencoded = '';
42-
43-
for (var key in pack) {
44-
urlencoded += key + "=" + pack[key] + "&";
45-
}
46-
urlencoded = urlencoded.substring(0, urlencoded.length - 1);
47-
48-
var options = {
49-
host: self.host || 'plot.ly',
50-
port: self.port || 443,
51-
path: '/apimkacct',
52-
method: 'POST',
53-
headers: {
54-
'Content-Type': 'application/x-www-form-urlencoded',
55-
'Content-Length': urlencoded.length
56-
}
57-
};
58-
59-
var req = https.request(options, function (res) {
60-
parseRes(res, function (err, body) {
61-
body = JSON.parse(body);
62-
if (err || res.statusCode !== 200) {
63-
callback({err: err, body: body, statusCode: res.statusCode});
64-
} else {
65-
self.username = body.un;
66-
self.api_key = body.api_key;
67-
callback(null, {
68-
un: body.un,
69-
api_key: body.api_key,
70-
tmp_pw: body.tmp_pw,
71-
msg: body.message,
72-
error: body.error,
73-
statusCode: res.statusCode
74-
});
75-
}
76-
});
77-
});
78-
79-
req.on('error', function(err) {
80-
callback(err);
81-
});
82-
83-
req.write(urlencoded);
84-
req.end();
85-
};
86-
8735
Plotly.prototype.plot = function(data, graph_options, callback) {
8836
var self = this;
8937
if (!callback) { callback = function() {}; }
@@ -107,48 +55,31 @@ Plotly.prototype.plot = function(data, graph_options, callback) {
10755
}
10856

10957
// trim off last ambersand
110-
urlencoded = urlencoded.substring(0, urlencoded.length - 1);
58+
var payload = urlencoded.substring(0, urlencoded.length - 1);
59+
60+
var headers = {
61+
'plotly-username': this.username,
62+
'plotly-apikey': this.api_key,
63+
'plotly-version': this.version,
64+
'plotly-platform': this.platform
65+
};
11166

11267
var options = {
113-
host: self.host,
114-
port: self.port,
115-
path: '/clientresp',
68+
url: 'https://' + self.host + '/clientresp',
69+
headers: headers,
11670
method: 'POST',
117-
headers: {
118-
'Content-Type': 'application/x-www-form-urlencoded',
119-
'Content-Length': urlencoded.length
120-
},
121-
withCredentials: false
71+
body: payload
12272
};
12373

124-
var req = https.request(options, function (res) {
125-
parseRes(res, function (err, body) {
126-
body = JSON.parse(body);
127-
if ( body['stream-status'] != undefined) {
128-
self.stream_host = url.parse(body['stream-host']).hostname;
129-
}
130-
if ( body.error.length > 0 ) {
131-
callback({msg: body.error, body: body, statusCode: res.statusCode});
132-
} else {
133-
callback(null, {
134-
streamstatus : body['stream-status'],
135-
url: body.url,
136-
message: body.message,
137-
warning: body.warning,
138-
filename: body.filename,
139-
error: body.error
140-
});
141-
}
142-
143-
});
144-
});
145-
146-
req.on('error', function(err) {
147-
callback(err);
74+
request(options, function (err, res, body) {
75+
if (JSON.parse(body).error) {
76+
callback(JSON.parse(body).error);
77+
} else {
78+
var msg = JSON.parse(body);
79+
callback(null, msg);
80+
}
14881
});
14982

150-
req.write(urlencoded);
151-
req.end();
15283
};
15384

15485
Plotly.prototype.stream = function(token, callback) {

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"author": "Alexander Daniel <alex@lesinstruments.com> (http://lesinstruments.com/)",
2424
"license": "MIT",
2525
"dependencies": {
26-
"request": "~2.36.0",
27-
"mkdirp": "~0.5.0"
26+
"mkdirp": "~0.5.0",
27+
"request": "^2.36.0"
2828
}
2929
}

0 commit comments

Comments
 (0)