Skip to content

Commit da021fd

Browse files
author
Dom Harrington
committed
Whoops, fixing up api url and making it work
1 parent fc56e8f commit da021fd

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/push.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ exports.desc = "Get a public URL for your API";
99
exports.category = "services";
1010

1111
exports.run = function(config, info, cb) {
12-
if (!cb) cb = () => {};
12+
if (!cb) cb = (err) => {
13+
if (err) {
14+
console.error(err)
15+
return process.exit(1);
16+
}
17+
18+
process.exit();
19+
};
1320

1421
const [apiKey, id] = info.opts.token.split('-');
1522

1623
function callback(err, response, data) {
1724
if (err) return cb(err);
18-
if (response.statusCode === 201) {
19-
console.log("");
25+
if (response.statusCode === 201 || response.statusCode === 200) {
26+
console.log(data);
2027
console.log("Success! ".green);
2128
} else {
22-
console.log(data)
2329
console.error("There was an error uploading!".red);
2430
}
2531

@@ -29,14 +35,14 @@ exports.run = function(config, info, cb) {
2935

3036
const options = {
3137
formData: {
32-
swagger: fs.createReadStream(path.join(process.cwd(), info.args[0])),
38+
swagger: fs.createReadStream(path.resolve(process.cwd(), info.args[0])),
3339
},
3440
auth: { user: apiKey },
3541
};
3642

3743
if (!id) {
38-
request.post(`${config.host.url}/v1/api/swagger`, options, callback);
44+
request.post(`${config.host.url}/api/v1/swagger`, options, callback);
3945
} else {
40-
request.put(`${config.host.url}/v1/api/swagger/${id}`, options, callback);
46+
request.put(`${config.host.url}/api/v1/swagger/${id}`, options, callback);
4147
}
4248
};

test/push.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('push action', () => {
1010
after(() => nock.cleanAll());
1111

1212
it('should POST to the swagger api if no id provided', (done) => {
13-
const mock = nock(config.host.url).post('/v1/api/swagger', (body) => {
13+
const mock = nock(config.host.url).post('/api/v1/swagger', (body) => {
1414
return body.match('form-data; name=\"swagger\"');
1515
}).basicAuth({ user: apiKey }).reply(201);
1616

@@ -24,7 +24,7 @@ describe('push action', () => {
2424

2525
it('should PUT to the swagger api if id is provided', (done) => {
2626
const id = '5aa0409b7cf527a93bfb44df';
27-
const mock = nock(config.host.url).put(`/v1/api/swagger/${id}`, (body) => {
27+
const mock = nock(config.host.url).put(`/api/v1/swagger/${id}`, (body) => {
2828
return body.match('form-data; name=\"swagger\"');
2929
}).basicAuth({ user: apiKey }).reply(201);
3030

0 commit comments

Comments
 (0)