0.2.0 • Published 9 years ago
fidem v0.2.0
fidem
Fidem node module provides an easy access to Fidem API.
Install
npm install fidem
Usage
var fidem = require('fidem');
// Create a client.
var client = fidem.createClient({
key: '1foakd92klda034kdkqsl',
secret: '1kkdq45kQdd3LQDazep'
});
// Log action.
client.logAction({
type: 'viewShow',
data: {
id: 'show1',
name: 'The Big Show'
}
}).then(function (result) {
// ...
})
// Authenticate a user.
client.authenticate({
username: 'johnny',
password: 'mySecretPassword'
})
// Retrieve a user by token.
.then(function (token) {
return client.getUserByToken(token);
})
.then(function (user) {
// ...
});
fidem.createClient(config)
Create a new API client.
* @param {object} config
* @param {string} config.key API key.
* @param {string} config.secret API secret.
* @param {string} [config.hostname="services.fidemapps.com"] Hostname.
* @param {string} [config.protocol=http] Protocol (http or https).
* @param {string} [config.port=80|443] Port.
* @returns {Client}
var client = fidem.createClient({
key: '1foakd92klda034kdkqsl',
secret: '1kkdq45kQdd3LQDazep'
});
client.authenticate(credentials, cb)
Get an authentication token for the credentials provided.
* @param {object} credentials
* @param {string} credentials.username Username.
* @param {string} credentials.password Password.
* @param {Function} [cb] Optional callback.
* @returns {Promise}
client.authenticate(credentials).then(function (res) {
console.log(res.token); // xxx
console.log(res.user); // {..}
});
client.request(options, cb)
Make a custom request to the API.
* @param {object} options
will use a session token request.
* @param {string} options.path Path of the request.
* @param {string} [options.token=null] Session token. If provided,
* @param {boolean} [options.sign=true] Sign the request
using key and secret of the client.
* @param {string} [options.method=GET] HTTP method.
* @param {object} [options.body=null] HTTP body of the request for methods
that supports it (POST, PUT, ...).
* @param {object} [options.headers={}] Additional headers.
* @param {object} [options.requestOptions={}] Custom options of the internal
[request](https://github.com/mikeal/request#requestoptions-callback).
* @param {Function} [cb] Optional callback.
* @returns {Promise}
client.request({
path: '/gamification/actions',
method: 'POST',
data: {
type: 'viewShow',
data: {
id: 'show1',
name: 'The Big Show'
}
}
});
client.getUserByToken(token, cb)
Retrieve a user by token.
* @param {string} token Token of the user.
* @param {Function} [cb] Optional callback.
* @returns {Promise}
client.getUserByToken('Qpaldj9kd');
client.logAction(action, cb)
Log an action.
* @param {string} action Action.
* @param {Function} [cb] Optional callback.
* @returns {Promise}
client.logAction({
type: 'viewShow',
data: {
id: 'show1',
name: 'The Big Show'
}
});
client.createMember(accountId, cb)
Create a member.
* @param {string} accountId If of the account.
* @param {Function} [cb] Optional callback.
* @returns {Promise}
client.createMember('demo');
client.startSession(memberId, cb)
Start a new session.
* @param {string} memberId If of the member.
* @param {Function} [cb] Optional callback.
* @returns {Promise}
client.startSession('02Ldkzqkdu');
client.assignMemberToSession(memberId, sessionId, cb)
Assign a member to an existing session.
* @param {string} sessionId If of the session.
* @param {string} memberId If of the member.
* @param {Function} [cb] Optional callback.
* @returns {Promise}
client.assignMemberToSession('-dkqu9j3ld', '_lqsdzoks');
License
MIT