Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

planet-client

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

planet-client - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

8

api/mosaics.js

@@ -18,4 +18,4 @@ /**

var url = urls.join(urls.MOSAICS, id);
return request.get(url).then(function(obj) {
return obj.data;
return request.get(url).then(function(res) {
return res.body;
});

@@ -35,4 +35,4 @@ }

};
return request.get(config).then(function(obj) {
return new Page(obj.data, search);
return request.get(config).then(function(res) {
return new Page(res.body, search);
});

@@ -39,0 +39,0 @@ }

@@ -19,4 +19,4 @@ /**

var url = urls.join(urls.MOSAICS, mosaicId, 'quads', quadId);
return request.get(url).then(function(obj) {
return obj.data;
return request.get(url).then(function(res) {
return res.body;
});

@@ -37,4 +37,4 @@ }

};
return request.get(config).then(function(obj) {
return new Page(obj.data, search.bind(null, mosaicId));
return request.get(config).then(function(res) {
return new Page(res.body, search.bind(null, mosaicId));
});

@@ -41,0 +41,0 @@ }

@@ -78,3 +78,3 @@ /**

* Create a handler for JSON API responses.
* @param {function(Object)} resolve Called on success with response and data
* @param {function(Object)} resolve Called on success with response and body
* properties.

@@ -103,9 +103,9 @@ * @param {function(Error)} reject Called on failure.

} else {
resolve(response);
resolve({response: response, body: null});
}
return;
}
var body = '';
var data = '';
response.on('data', function(chunk) {
body += String(chunk);
data += String(chunk);
});

@@ -121,29 +121,28 @@

info.completed = true;
var data = null;
if (info.aborted) {
return;
}
var body = null;
var err = null;
if (!info.aborted) {
if (body) {
try {
data = JSON.parse(body);
} catch (parseErr) {
err = new errors.UnexpectedResponse(
'Trouble parsing response body as JSON: ' + body + '\n' +
parseErr.stack + '\n', response, body);
}
if (status === 401) {
err = new errors.Unauthorized('Unauthorized', response, body);
} else if (!(status >= 200 && status < 300)) {
err = new errors.UnexpectedResponse('Unexpected response status: ' +
status, response, data);
} else if (data) {
try {
body = JSON.parse(data);
} catch (parseErr) {
err = new errors.UnexpectedResponse(
'Trouble parsing response body as JSON: ' + data + '\n' +
parseErr.stack + '\n', response, data);
}
if (status === 401) {
err = new errors.Unauthorized('Unauthorized', response, body);
} else if (!(status >= 200 && status < 300)) {
err = new errors.UnexpectedResponse('Unexpected response status: ' +
status, response, body);
}
if (err) {
reject(err);
return;
}
}
if (err) {
reject(err);
return;
}
resolve({
response: response,
data: data
body: body
});

@@ -174,4 +173,6 @@ });

* `XMLHttpRequest.withCredentials` is set (`true` by default).
* @return {Promise<IncomingMessage>} A promise that resolves to a successful
* response. Any non 200 status will result in a rejection.
* @return {Promise<Object>} A promise that resolves on a successful
* response. The object includes response and body properties, where the
* body is a JSON decoded object representing the response body. Any
* non-200 status will result in a rejection.
*/

@@ -226,4 +227,6 @@ function request(config) {

* @param {string} config.url A URL or request config.
* @return {Promise<IncomingMessage>} A promise that resolves to a successful
* response. Any non 200 status will result in a rejection.
* @return {Promise<Object>} A promise that resolves on a successful
* response. The object includes response and body properties, where the
* body is a JSON decoded object representing the response body. Any
* non-200 status will result in a rejection.
*/

@@ -230,0 +233,0 @@ function get(config) {

@@ -28,7 +28,7 @@ /**

var url = urls.join(urls.SCENES, scene.type, scene.id);
return request.get(url).then(function(obj) {
return request.get(url).then(function(res) {
if (options.augmentLinks !== false) {
util.augmentSceneLinks(obj.data);
util.augmentSceneLinks(res.body);
}
return obj.data;
return res.body;
});

@@ -57,5 +57,5 @@ }

};
return request.get(config).then(function(obj) {
return request.get(config).then(function(res) {
if (options.augmentLinks !== false) {
var scenes = obj.data.features;
var scenes = res.body.features;
for (var i = 0, ii = scenes.length; i < ii; ++i) {

@@ -65,3 +65,3 @@ util.augmentSceneLinks(scenes[i]);

}
return new Page(obj.data, search);
return new Page(res.body, search);
});

@@ -68,0 +68,0 @@ }

@@ -12,4 +12,4 @@ /**

var url = urls.join(urls.WORKSPACES, id);
return request.get(url).then(function(obj) {
return obj.data;
return request.get(url).then(function(res) {
return res.body;
});

@@ -20,4 +20,4 @@ }

var url = urls.WORKSPACES;
return request.get(url).then(function(obj) {
return obj.data;
return request.get(url).then(function(res) {
return res.body;
});

@@ -24,0 +24,0 @@ }

@@ -67,3 +67,4 @@ var fs = require('fs');

request.get({url: productUrl, stream: true})
.then(function(response) {
.then(function(res) {
var response = res.response;
response.on('error', done);

@@ -70,0 +71,0 @@ response.on('end', done);

@@ -116,6 +116,9 @@ var path = require('path');

type: opts.type,
intersects: geom,
count: Math.min(opts.limit, 500)
};
if (geom) {
query.intersects = geom;
}
if (opts.acquired) {

@@ -122,0 +125,0 @@ parseAcquired(opts.acquired, query);

{
"name": "planet-client",
"version": "0.2.0",
"version": "0.3.0",
"description": "A client for Planet's imagery API",

@@ -17,2 +17,3 @@ "repository": {

"test": "mocha --recursive test",
"test-debug": "mocha --debug-brk --recursive test",
"start": "watchy --watch bin,examples,api,cli,test -- npm test",

@@ -19,0 +20,0 @@ "postpublish": "npm run publish-doc",

/* eslint-env mocha */
var http = require('http');
var https = require('https');
var stream = require('stream');

@@ -73,2 +74,75 @@ var chai = require('chai');

it('resolves to an object with body and response', function(done) {
var response = new stream.Readable();
response.statusCode = 200;
var body = {
foo: 'bar'
};
var promise = request({url: 'http://example.com'});
promise.then(function(obj) {
assert.equal(obj.response, response);
assert.deepEqual(obj.body, body);
done();
}, done);
assert.equal(http.request.callCount, 1);
var args = http.request.getCall(0).args;
assert.lengthOf(args, 2);
var callback = args[1];
callback(response);
response.emit('data', JSON.stringify(body));
response.emit('end');
});
it('resolves before parsing body if stream is true', function(done) {
var response = new stream.Readable();
response.statusCode = 200;
var body = {
foo: 'bar'
};
var promise = request({
url: 'http://example.com',
stream: true
});
promise.then(function(obj) {
assert.equal(obj.response, response);
assert.isNull(obj.body);
done();
}, done);
assert.equal(http.request.callCount, 1);
var args = http.request.getCall(0).args;
assert.lengthOf(args, 2);
var callback = args[1];
callback(response);
response.emit('data', JSON.stringify(body));
response.emit('end');
});
it('rejects for invalid JSON in successful response', function(done) {
var response = new stream.Readable();
response.statusCode = 200;
var body = 'garbage response body';
var promise = request({url: 'http://example.com'});
promise.then(function(obj) {
done(new Error('Expected promise to be rejected'));
}, function(err) {
assert.instanceOf(err, errors.UnexpectedResponse);
assert.include(err.message, 'Trouble parsing response body as JSON');
assert.equal(err.body, body);
done();
}).catch(done);
assert.equal(http.request.callCount, 1);
var args = http.request.getCall(0).args;
assert.lengthOf(args, 2);
var callback = args[1];
callback(response);
response.emit('data', body);
response.emit('end');
});
it('accepts a terminator for aborting requests', function(done) {

@@ -75,0 +149,0 @@ var promise = request({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc