Socket
Socket
Sign inDemoInstall

sapi

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

test/endpoint/getbylistingid.js

5

CHANGELOG.md

@@ -1,3 +0,4 @@

### 0.0.3 (SNAPSHOT)
*
### 0.0.4 (SNAPSHOT)
* Add proxy support.
* Modify endpoint callback to return SAPI response object.

@@ -4,0 +5,0 @@ ### 0.0.2

4

lib/endpoint/getbylistingid.js

@@ -7,3 +7,3 @@ /**

params = {
required: ['query'],
required: ['key', 'query'],
optional: []

@@ -33,3 +33,3 @@ };

}
}
};
}

@@ -36,0 +36,0 @@

@@ -7,3 +7,3 @@ /**

params = {
required: ['dataType'],
required: ['key', 'dataType'],
optional: []

@@ -33,3 +33,3 @@ };

}
}
};
}

@@ -36,0 +36,0 @@

@@ -7,3 +7,3 @@ /**

params = {
required: ['userIp', 'id'],
required: ['key', 'userIp', 'id'],
optional: ['userAgent', 'userSessionId', 'content']

@@ -33,3 +33,3 @@ };

}
}
};
}

@@ -36,0 +36,0 @@

@@ -7,3 +7,3 @@ /**

params = {
required: ['query', 'location'],
required: ['key', 'query', 'location'],
optional: ['page', 'rows', 'sortBy', 'sensitiveCategories', 'categoryId', 'postcode', 'radius', 'locationTiers', 'suburb', 'state', 'boundingBox', 'content', 'productKeyword']

@@ -33,3 +33,3 @@ };

}
}
};
}

@@ -36,0 +36,0 @@

@@ -12,2 +12,3 @@ var request = require('request'),

* - url (String): Jenkins URL without query string
* - proxy (String): proxy server URL in format http://user:pass@host:port
* - qs (Object): object containing URL query strings with format { name: value }

@@ -22,3 +23,3 @@ * - handlers (Object): response handlers with format { statuscode: handlerfunction }

**/
function _http(method, url, queryStrings, handlers, cb) {
function _http(method, url, proxy, queryStrings, handlers, cb) {

@@ -30,5 +31,8 @@ var params = {

};
if (process.env.http_proxy) {
params.proxy = process.env.http_proxy;
// use environment variable http_proxy if proxy is not set via Sapi#proxy
if (proxy || process.env.http_proxy) {
params.proxy = proxy || process.env.http_proxy;
}
request(params, function (err, result) {

@@ -46,3 +50,4 @@ if (err) {

} else if (handlers[result.statusCode]) {
handlers[result.statusCode](result);
// SAPI documentation indicates that all expected response is in JSON format
handlers[result.statusCode](JSON.parse(result.body));
} else {

@@ -64,2 +69,13 @@ cb(new Error('Unexpected status code ' + result.statusCode + ' from SAPI\nResponse body:\n' + result.body));

/**
* Sapi#proxy(String) -> Object
* - proxy (String): proxy server URL in format http://user:pass@host:port
*
* Set proxy server URL, used to connect to SAPI service.
**/
Sapi.prototype.proxy = function (proxy) {
this._proxy = proxy;
return this;
};
endpoints.forEach(function (endpoint) {

@@ -81,3 +97,3 @@

return this;
}
};
});

@@ -92,6 +108,6 @@

Sapi.prototype[endpoint.name] = function _endpoint(cb) {
_http('get', this.url + '/' + endpoint.path(this.params), this.params, endpoint.handlers(cb), cb);
}
_http('get', this.url + '/' + endpoint.path(this.params), this._proxy, this.params, endpoint.handlers(cb), cb);
};
});
module.exports = Sapi;

@@ -11,3 +11,3 @@ {

],
"version": "0.0.3",
"version": "0.0.4",
"homepage": "http://github.com/cliffano/sapi",

@@ -35,2 +35,3 @@ "author": "Cliffano Subagio <blah@cliffano.com> (http://blog.cliffano.com)",

"devDependencies": {
"bagofholding": "0.0.10",
"mocha": "1.3.0",

@@ -37,0 +38,0 @@ "sandboxed-module": "0.1.3",

@@ -6,4 +6,6 @@ sapi [![http://travis-ci.org/cliffano/sapi](https://secure.travis-ci.org/cliffano/sapi.png?branch=master)](http://travis-ci.org/cliffano/sapi)

Use Sapi
This is handy when you want to use [Sensis API](http://developers.sensis.com.au/about) service from a Node.js application. This Sapi module provides a chainable interface to set the endpoint parameters.
Tested with Sensis API version ob-20110511.
Installation

@@ -23,11 +25,59 @@ ------------

var sapi = require('sapi'),
s = new sapi('key', 'http://sapi/version/env/');
var sapi = new (require('sapi'))('key', 'http://api.sensis.com.au/ob-20110511/test/');
s.query('restaurant').location('222 Lonsdale St, Melbourne, VIC 3000').search(function (err, result) {
if (err) {
console.error(err);
} else {
console.log(require('util').inspect(result));
}
});
sapi.proxy('http://user:pass@proxy:8080'); // optional
Parameters can then be chained to an endpoint:
sapi
.param1('value1')
.param2('value2')
.param3('value3')
.endpoint(function (err, result) {
...
});
Search for restaurants in Melbourne:
sapi
.query('restaurants')
.location('Melbourne')
.search(function (err, result) {
...
});
Get listing details by ID:
sapi
.query('12345')
.getByListingId(function (err, result) {
...
});
Retrieve categories metadata:
sapi
.dataType('categories')
.metadata(function (err, result) {
...
});
Send report events:
sapi
.userIp('192.1.2.3')
.id('VyY2UiOi')
.content('(03) 1234 5678')
.report(function (err, result) {
...
});
Endpoints
---------
Check out Sensis API documentation for further details of the [endpoints](http://developers.sensis.com.au/docs/using_endpoints), a list of parameters, and response message structure:
* [Search](http://developers.sensis.com.au/docs/endpoint_reference/Search)
* [Get by Listing ID](http://developers.sensis.com.au/docs/endpoint_reference/Get_by_Listing_ID)
* [Report](http://developers.sensis.com.au/docs/endpoint_reference/Report)
* [Metadata](http://developers.sensis.com.au/docs/endpoint_reference/Metadata)
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc