DNT API
Node.JS library for communicating with Turistforeningen's API.
Table of Contents
Requirements
Require Node.JS version >= 0.10
.
Installing
npm install dnt-api --save
Usage
var DNT = require('dnt-api');
Class: DNT
var dnt = new DNT('My Application/1.0', 'myApiKey');
dnt.getMemberFor(object
query, function
cb)
The getMemberFor()
method is used to get details for a given member from the
membership register.
query parameter
The query
parameter can at the moment have either one, or both, of the following
properties:
sherpa_id
- which is the local user id for Sherpa 3.medlemsnummer
which is the membership number for a given membership.
cb parameter
The callback function to this requests takes tree parameters:
Error
err - this is an error if the HTTP request itself failed.number
statusCode - HTTP status code returned from the API.object
memberData - data returned from the API.
Example
dnt.getMemberFor({ sherpa_id: 1234 }, function(err, statusCode, memberData) {
if (err) { throw err }
if (statusCode === 200) {
console.log('Member is ' + memberData.fornavn);
} else {
console.error('Request failed! HTTP status code returned is ' + statusCode);
console.error(memberData.errors);
}
});
dnt.getAssociationsFor(object
query, function
cb)
The getAssociationsFor()
method is used to get associations (NO foreninger)
for a given member from the membership register.
query parameter
The query
parameter can at the moment have either one, or both, of the following
properties:
bruker_sherpa_id
- which is the local user id for Sherpa 3.bruker_medlemsnummer
which is the membership number for a given membership.
cb parameter
The callback function to this requests takes tree parameters:
Error
err - this is an error if the HTTP request itself failed.number
statusCode - HTTP status code returned from the API.Array
associations - data returned from the API.
Example
dnt.getAssociationsFor({ bruker_sherpa_id: 1234 }, function(err, statusCode, associations) {
if (err) { throw err }
if (statusCode === 200) {
for (var i = 0; i < associations.length; i++) {
console.log('Member is associated with ' + associations[i].navn);
}
} else {
console.error('Request failed! HTTP status code returned is ' + statusCode);
console.error(associations.errors);
}
});