infusionsoft / API-Sample-Code

Sample API Code for various Languages
35 stars 86 forks source link

Node examples? #4

Open molinto opened 9 years ago

molinto commented 9 years ago

Please add node examples guys

jasonshouse commented 9 years ago

:+1: for node examples

temsa commented 8 years ago

:+1:

kressaty commented 8 years ago

@molinto @jasonshouse @temsa if there were a node library / examples, are there any good libraries you like that you prefer how they handle things? Have any of you used https://github.com/baalexander/node-xmlrpc ?

temsa commented 8 years ago

@kressaty : so far I've used with success infusionsoft ^0.3.7 which runs on top of xmlrpc 1.3.0. Yet, it does not wrap the whole API, and seems unmaintained.

Raw code running on top of xmlrpc would be ok :)

kressaty commented 8 years ago

Ok cool. So here's the next question - do we want a specific method for each API request? Or a wrapper system that handles OAuth for you, and then lets you specify the XML-RPC request you're going to make as an argument to a generic "request" method?

infusionsoft.contactAdd(args, callback)

vs

infusionsoft.request('ContactService.add', args, callback)

temsa commented 8 years ago

For a library, maybe something more like this ?

// Allows multiple clients, could also use 'new' to be clear about that but not necessary
var client = require('infusionsoft').client()

// Could also be 'client.ContactService.add' yet does not feel right
// usual args could be given directly when few (less than 4) are needed
client.contact.add(arg1, arg2, arg3, callback)

// if you need more clarity regarding you API you may prefer 'client.contactService', yet 'Service' is not a very useful information in itself and gives less readability

// or, keep it always supported, at least for more complicated arguments, an object containing everything needed
client.contact.add({...}, callback)

// I'm not a promise fanboy, yet you could also return a promise if no callback
client.contact.add(arg1, arg2, arg3).then( function(res) { console.log(res) ))