sqwiggle-node
Node.js library for the Sqwiggle API
Installation
npm install sqwiggle-node
Configuration
Create an API Client at https://www.sqwiggle.com/company/clients
Then you can instantiate the API client:
var Sqwiggle = require("sqwiggle-node");var token = '...'; // Your API token herevar client = new Sqwiggle(token);
Usage
Services
The module exports an API wrapper that you can use to query any of the existing API endpoints. There are 4 patterns for API calls: // Index actionsclient.service.index({data: "for filtering or updating"}, function(error, response) { if(error) { // Something went wrong. You will find details in the error hash console.log(error) } else { // Response contains the information retrieved from the server console.log(response) }}) // Find actionsclient.service.find(objectId, function(error, response) { }) // Create actionsclient.service.create({object: "data", goes: "here"}, function(error, response) { }) // Update actionsclient.service.update(objectId, {object: "data", goes: "here"}, function(error, response) { }) // Delete actionsclient.service.delete(objectId, function(error, response) { })
Available Services
There are 7 services that follow this pattern:
- messages
- invites
- conversations
- attachments
- organizations
- rooms
- users
As well as one that does not:
- info
which has 3 endpoints:
client.info.configuration(callback)client.info.versions(callback)client.info.all(callback)
For more information on the endpoints and parameters, check out the Sqwiggle API documentation
Sample Calls
var Sqwiggle = require("sqwiggle-node");var token = '...'; // Your API token here.var client = new Sqwiggle(token); // Get a list of all the roomsclient.rooms.index(null, function(err, resp) { if(err) { console.log(err); } else { console.log(resp); }} // Get the last 5 messagesclient.messages.index({page: 1, limit: 5}, function(err, resp) { if(err) { console.log(err); } else { console.log(resp); }} // Create a message in a roomclient.messages.create({text: 'Hello from Node!', room_id: 12345}, function(err, resp) { if(err) { // there was an issue creating the message } else { console.log(resp) }} // Change an attachment to a messageclient.attachment.update(12345, {title: 'Fun Image!'}, function(err, resp) { if(err) { // there was an issue updating the attachment } else { console.log(resp) }}) // Delete an invitationclient.invites.delete(4321, function(err, resp) { if(err) { // didn't work } else { // Response will always be 'OK' for successful deletes. console.log(resp) }} // Get all of the info on client versions and current configuration:client.info.all(function(err, resp) { if(err) { // something went wrong } else { console.log(resp) }})
Contributing
- Fork the project
- Create your feature branch (
git checkout -b my-new-feature
) - Write a test for your use-case
- Implement the use-case
- Commit your changes (
git commit -am "Adding some feature"
) - Push to the branch(
git push origin my-new-feature
) - Open a new Pull Request