indabaui-agent

Minimal SuperAgent customizations for working with Indaba Music API

npm install indabaui-agent
2 downloads in the last week
4 downloads in the last month

indaba agent

Minimal SuperAgent customizations for working with Indaba Music API

  • Use standard SuperAgent API unmodified
  • Use agent.inGet, agent.inGetAll, agent.inPost, and request.inEnd for extra convenience with Indaba API.
  • Set agent._endpoint to use relative paths
  • Set agent._token to include Authorization header in each request
  • Use inEnd instead of end to parse jSend response and provides error first callback

Installation

$ component install indabaui/agent

API


var agent = require('agent');

// path + callback
agent.inGet('/opportunities', function(err, data) {
  console.log(data);
});

// path + query + callback
agent.inGet('/opportunities', {limit: 10}, function(err, data) {
  console.log(data);
});

// superagent chaining style
agent.inGet('/opportunities')
  .query({limit: 10})
  .query({offset: 80})
  .inEnd(function(err, data) {
    console.log(data);
  });

// inGetAll
agent.inGetAll('/opportunities', function(err, data) {
  console.log(data);
});

// one off authenticated request
agent.inGet('/whoami')
  .query({access_token: 'xxxx'})
  .inEnd(function(err, data) {
    console.log(data);
  });

// set `agent._token` and you can omit access_token on subsequent requests
agent._token = 'xxxx';
agent.inGet('/whoami')
  .inEnd(function(err, data) {
    console.log(data);
  });

Tokens on the server

Do not set agent._token on the server. There is only one instance of agent, so this token is not unique to any context. Instead, you should explicitly include a user's token when using agent server side:

// one off authenticated request
agent.inGet('/whoami')
  .query({access_token: 'xxxx'})
  .inEnd(function(err, data) {
    console.log(data);
  });

License

MIT

npm loves you