sapi
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,5 +0,8 @@ | ||
### 0.0.2 (SNAPSHOT) | ||
### 0.0.3 (SNAPSHOT) | ||
* | ||
### 0.0.2 | ||
* Add getListingById, report, and metadata endpoints support. | ||
### 0.0.1 | ||
* Initial version, only supports search endpoint. |
/** | ||
* http://developers.sensis.com.au/docs/endpoint_reference/Metadata | ||
* Get by Listing ID endpoint name and parameters. | ||
* Reference: http://developers.sensis.com.au/docs/endpoint_reference/Metadata | ||
**/ | ||
@@ -10,2 +11,8 @@ var name = 'getByListingId', | ||
/** | ||
* getbylistingid#path -> String | ||
* - params (Object): endpoint parameters constructed from chainable functions | ||
* | ||
* Create the endpoint URL path, to be appended to SAPI base URL. | ||
**/ | ||
function path (params) { | ||
@@ -15,2 +22,8 @@ return name; | ||
/** | ||
* getbylistingid#handlers -> Object | ||
* - cb (Function): standard cb(err, result) callback | ||
* | ||
* Set up endpoint success and error handlers. | ||
**/ | ||
function handlers(cb) { | ||
@@ -17,0 +30,0 @@ return { |
/** | ||
* http://developers.sensis.com.au/docs/endpoint_reference/Metadata | ||
* Metadata endpoint name and parameters. | ||
* Reference: http://developers.sensis.com.au/docs/endpoint_reference/Metadata | ||
**/ | ||
@@ -10,2 +11,8 @@ var name = 'metadata', | ||
/** | ||
* metadata#path -> String | ||
* - params (Object): endpoint parameters constructed from chainable functions | ||
* | ||
* Create the endpoint URL path, to be appended to SAPI base URL. | ||
**/ | ||
function path (params) { | ||
@@ -15,2 +22,8 @@ return name + '/' + params.dataType; | ||
/** | ||
* metadata#handlers -> Object | ||
* - cb (Function): standard cb(err, result) callback | ||
* | ||
* Set up endpoint success and error handlers. | ||
**/ | ||
function handlers(cb) { | ||
@@ -17,0 +30,0 @@ return { |
/** | ||
* http://developers.sensis.com.au/docs/endpoint_reference/Report | ||
* Report endpoint name and parameters. | ||
* Reference: http://developers.sensis.com.au/docs/endpoint_reference/Report | ||
**/ | ||
@@ -10,2 +11,8 @@ var name = 'report', | ||
/** | ||
* report#path -> String | ||
* - params (Object): endpoint parameters constructed from chainable functions | ||
* | ||
* Create the endpoint URL path, to be appended to SAPI base URL. | ||
**/ | ||
function path (params) { | ||
@@ -15,2 +22,8 @@ return name + '/' + params.eventName; | ||
/** | ||
* report#handlers -> Object | ||
* - cb (Function): standard cb(err, result) callback | ||
* | ||
* Set up endpoint success and error handlers. | ||
**/ | ||
function handlers(cb) { | ||
@@ -17,0 +30,0 @@ return { |
/** | ||
* http://developers.sensis.com.au/docs/endpoint_reference/Search | ||
* Search endpoint name and parameters. | ||
* Reference: http://developers.sensis.com.au/docs/endpoint_reference/Search | ||
**/ | ||
@@ -10,2 +11,8 @@ var name = 'search', | ||
/** | ||
* search#path -> String | ||
* - params (Object): endpoint parameters constructed from chainable functions | ||
* | ||
* Create the endpoint URL path, to be appended to SAPI base URL. | ||
**/ | ||
function path (params) { | ||
@@ -15,2 +22,8 @@ return name; | ||
/** | ||
* search#handlers -> Object | ||
* - cb (Function): standard cb(err, result) callback | ||
* | ||
* Set up endpoint success and error handlers. | ||
**/ | ||
function handlers(cb) { | ||
@@ -17,0 +30,0 @@ return { |
@@ -8,15 +8,31 @@ var request = require('request'), | ||
/** internal | ||
* sapi#_http(method, url, qs, handlers, cb) | ||
* - method (String): http method | ||
* - url (String): Jenkins URL without query string | ||
* - qs (Object): object containing URL query strings with format { name: value } | ||
* - handlers (Object): response handlers with format { statuscode: handlerfunction } | ||
* - cb (Function): standard cb(err, result) callback | ||
* | ||
* Sends a HTTP request to a SAPI URL and handle the following errors: | ||
* - request error | ||
* - authentication error | ||
* - unexpected status error | ||
**/ | ||
function _http(method, url, queryStrings, handlers, cb) { | ||
request({ | ||
var params = { | ||
method: method, | ||
uri: url, | ||
qs: queryStrings | ||
}, function (err, result) { | ||
}; | ||
if (process.env.http_proxy) { | ||
params.proxy = process.env.http_proxy; | ||
} | ||
request(params, function (err, result) { | ||
if (err) { | ||
cb(err); | ||
} else if (result.statusCode === 403) { | ||
// TODO: why not return 401 instead for invalid authentication, | ||
// to differentiate the error to missing authentication | ||
// SAPI does not differentiate required authentication and failed authentication | ||
// since both return status code 403, need to check key param existence to differentiate the two | ||
if (queryStrings.key) { | ||
@@ -35,2 +51,7 @@ cb(new Error('Authentication failed - invalid key ' + queryStrings.key)); | ||
/** | ||
* class Sapi | ||
* - key (String): Sensis API key, apply here http://developers.sensis.com.au/docs/getting_started/Apply_for_an_API_key | ||
* - url (String): Sensis API base URL - http://developers.sensis.com.au/docs/using_endpoints | ||
**/ | ||
function Sapi(key, url) { | ||
@@ -46,2 +67,10 @@ this.params = { key: key }; | ||
params.forEach(function (param) { | ||
/** | ||
* Sapi#endpointparam(value) -> Object | ||
* - value (String): parameter value | ||
* | ||
* Chainable function for each parameter. | ||
* Usage pattern: sapi.param1().param2().param3().end(); | ||
* The idea here is to allow the construction of 0...* parameters before calling the endpoint. | ||
**/ | ||
Sapi.prototype[param] = function (value) { | ||
@@ -53,2 +82,8 @@ this.params[param] = value; | ||
/** | ||
* Sapi#endpointname(cb) | ||
* - cb (Function): standard cb(err, result) callback | ||
* | ||
* End function for each endpoint that makes http request to SAPI. | ||
**/ | ||
Sapi.prototype[endpoint.name] = function _endpoint(cb) { | ||
@@ -55,0 +90,0 @@ _http('get', this.url + '/' + endpoint.path(this.params), this.params, endpoint.handlers(cb), cb); |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "http://github.com/cliffano/sapi", | ||
@@ -35,3 +35,5 @@ "author": "Cliffano Subagio <blah@cliffano.com> (http://blog.cliffano.com)", | ||
"devDependencies": { | ||
"sandboxed-module": "0.1.3" | ||
"mocha": "1.3.0", | ||
"sandboxed-module": "0.1.3", | ||
"should": "0.6.3" | ||
}, | ||
@@ -38,0 +40,0 @@ "engines": { |
sapi [![http://travis-ci.org/cliffano/sapi](https://secure.travis-ci.org/cliffano/sapi.png?branch=master)](http://travis-ci.org/cliffano/sapi) | ||
----------- | ||
[Sensis API](http://developers.sensis.com.au/about) Node.js client | ||
[Sensis API](http://developers.sensis.com.au/about) Node.js client. | ||
Use Sapi | ||
Installation | ||
@@ -7,0 +9,0 @@ ------------ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
9714
225
31
3
2