node-moco
v4.2.0
Published
A microservice api-client to access Mocoapp.com API
Downloads
13
Maintainers
Readme
node-moco
A microservice api-client to access Mocoapp.com API.
This module is based on my Extended-Request package, in fact it's using that package in order to perform the api requests.
Features:
- ES8 (Async/Await)
- ES6 (Promises)
- ES5 (Callback)
- Debug Mode
Table of contents
- API Reference
- Property Reference
- Method Reference
- Create a Moco instance
- Get Activities
- Get Activity
- Get Companies
- Get Company
- Get Comments
- Get Comment
- Get Contacts People
- Get Contacts Person
- Get Deals
- Get Deal
- Get Deal Categories
- Get Deal Category
- Get Invoices
- Get Invoice
- Get Invoice Payments
- Get Invoice Payment
- Get Offers
- Get Offer
- Get Projects
- Get Project
- Get Projects Assigned
- Get Projects Expenses
- Get Purchases
- Get Purchase
- Get Purchase Categories
- Get Purchase Category
- Get Schedules
- Get Schedule
- Get Units
- Get Unit
- Get Users
- Get User
- Get User Employments
- Get User Employment
- Get User Holidays
- Get User Holiday
- Sorting
- Setup / Install
- Unit-Tests
- Notable Changes
- Contributing
- License
API Reference
Moco(
[Object {
domain: String='mycompany'
debug: Boolean=false
token: String=''
} details]
) -> Object {
/* Constants */
this: Object=this
/* Methods */
getActivities: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getActivity: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getCompanies: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getCompany: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getComments: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getComment: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getContactsPeople: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getContactsPerson: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getDeals: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getDeal: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getDealCategories: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getDealCategory: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getInvoices: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getInvoice: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getInvoicePayments: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getInvoicePayment: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getOffers: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getOffer: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getProjects: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getProject: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getProjectsAssigned: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getProjectsExpenses: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getPurchases: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getPurchase: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getPurchaseCategories: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getPurchaseCategory: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getSchedules: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getSchedule: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getUnits: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getUnit: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getUsers: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getUser: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getUserEmployments: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getUserEmployment: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
getUserHolidays: [Object=options, function(class ErrorClass err, any results) cb] | Promise
getUserHoliday: [String|Number=id, function(class ErrorClass err, any results) cb] | Promise
}
Property reference:
| Property | Description | | ------ | ----------- | | details | An object containing configuration details | | domain | The first part of your MOCO domain (eg. mycompany) | | apikey | Your MOCO integration API Key | | debug | Whether to debug requests |
Method reference:
Create a Moco instance
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | domain | mycompany | Yes | | | apikey | your key | Yes | | | debug | enable debugging | No | false |
const company = new Moco({
domain: 'mycompany',
apikey: '<key here>'
})
Get Activities
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | options | for example: { from: '2018-02-01' } | No | None | | cb | optional callback (in case you don't want to use promises) | No | |
Options reference: #get-activities Sorting
/* Async/Await */
const activities = await mycompany.getActivities()
const activities = await mycompany.getActivities({
from: '2017-01-02'
to: '2017-01-02'
})
/* Promise */
mycompany.getActivities()
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
mycompany.getActivities({
from: '2017-01-02'
to: '2017-01-02'
})
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getActivities((err, response) => {
console.log(err, response)
})
mycompany.getActivities({
from: '2017-01-02'
to: '2017-01-02'
},
(err, response) => {
console.log(err, response)
})
Get Activity
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | id | for example: 58844 | Yes | None | | cb | optional callback (in case you don't want to use promises) | No | |
/* Async/Await */
const activity = await mycompany.getActivity(58844)
/* Promise */
mycompany.getActivity(58844)
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getActivity(58844, (err, response) => {
console.log(err, response)
})
Get Companies
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | options | for example: { type: 'customer' } | No | None | | cb | optional callback (in case you don't want to use promises) | No | |
Options reference: #get-companies Sorting
/* Async/Await */
const companies = await mycompany.getCompanies()
const companies = await mycompany.getCompanies({
type: 'customer'
})
/* Promise */
mycompany.getCompanies()
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
mycompany.getCompanies({
type: 'customer'
})
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getCompanies((err, response) => {
console.log(err, response)
})
mycompany.getCompanies({
type: 'customer'
},
(err, response) => {
console.log(err, response)
})
Get Company
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | id | for example: 58844 | Yes | None | | cb | optional callback (in case you don't want to use promises) | No | |
/* Async/Await */
const company = await mycompany.getCompany(58844)
/* Promise */
mycompany.getCompany(58844)
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getCompany(58844, (err, response) => {
console.log(err, response)
})
Get Comments
Call as shown above in the API Reference.
Options reference: #get-comments Sorting
Get Comment
Call as shown above in the API Reference.
Get Contacts People
Call as shown above in the API Reference.
Available options: #get-contacts-people Sorting
Get Contacts Person
Call as shown above in the API Reference.
Get Deals
Call as shown above in the API Reference.
Options reference: #get-deals Sorting
Get Deal
Call as shown above in the API Reference.
Get Deal Categories
Call as shown above in the API Reference.
Options reference: #get-deal_categories Sorting
Get Deal Category
Call as shown above in the API Reference.
Get Invoices
Call as shown above in the API Reference.
Options reference: #get-invoices Sorting
Get Invoice
Call as shown above in the API Reference.
Get Invoice Payments
Call as shown above in the API Reference.
Options reference: #get-invoice-payments Sorting
Get Invoice Payment
Call as shown above in the API Reference.
Get Offers
Call as shown above in the API Reference.
Options reference: #get-offers Sorting
Get Offer
Call as shown above in the API Reference.
Get Projects
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | options | for example: { include_archived: false } | No | None | | cb | optional callback (in case you don't want to use promises) | No | |
Options reference: #get-projects Sorting
/* Async/Await */
const projects = await mycompany.getProjects()
const projects = await mycompany.getProjects({
include_archived: false
})
/* Promise */
mycompany.getProjects()
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
mycompany.getProjects({
include_archived: false
})
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getProjects((err, response) => {
console.log(err, response)
})
mycompany.getProjects({
include_archived: false
},
(err, response) => {
console.log(err, response)
})
Get Project
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | id | for example: 58844 | Yes | None | | cb | optional callback (in case you don't want to use promises) | No | |
/* Async/Await */
const project = await mycompany.getProject(58844)
/* Promise */
mycompany.getProject(58844)
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getProject(58844, (err, response) => {
console.log(err, response)
})
Get Projects Assigned
Call as shown above in the API Reference.
Options reference: #get-projects-assigned
Get Projects Expenses
Call as shown above in the API Reference.
Options reference: #get-projects-expenses
Get Purchases
Call as shown above in the API Reference.
Options reference: #get-purchases Sorting
Get Purchase
Call as shown above in the API Reference.
Get Purchase Categories
Call as shown above in the API Reference.
Options reference: #get-purchases-categories Sorting
Get Purchase Category
Call as shown above in the API Reference.
Get Schedules
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | options | for example: { from: '2018-02-01' } | No | None | | cb | optional callback (in case you don't want to use promises) | No | |
Options reference: #get-schedules Sorting
/* Async/Await */
const schedules = await mycompany.getSchedules()
const schedules = await mycompany.getSchedules({
from: '2017-01-02'
to: '2017-01-02'
})
/* Promise */
mycompany.getSchedules()
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
mycompany.getSchedules({
from: '2017-01-02'
to: '2017-01-02'
})
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getSchedules((err, response) => {
console.log(err, response)
})
mycompany.getSchedules({
from: '2017-01-02'
to: '2017-01-02'
},
(err, response) => {
console.log(err, response)
})
Get Schedule
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | id | for example: 58844 | Yes | None | | cb | optional callback (in case you don't want to use promises) | No | |
/* Async/Await */
const schedule = await mycompany.getSchedule(58844)
/* Promise */
mycompany.getSchedule(58844)
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getSchedule(58844, (err, response) => {
console.log(err, response)
})
Get Units
Call as shown above in the API Reference.
Options reference: #get-units Sorting
Get Unit
Call as shown above in the API Reference.
Get Users
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | options | | No | None | | cb | optional callback (in case you don't want to use promises) | No | |
Options reference: #get-users Sorting
/* Async/Await */
const users = await mycompany.getUsers()
/* Promise */
mycompany.getUsers()
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getUsers((err, response) => {
console.log(err, response)
})
Get User
Available options:
| | | Required | Default | | ------ | ----------- | ------ | ----- | | id | for example: 58844 | Yes | None | | cb | optional callback (in case you don't want to use promises) | No | |
/* Async/Await */
const user = await mycompany.getUser(58844)
/* Promise */
mycompany.getUser(58844)
.then((results) => {
console.log(results)
})
.catch((err) => {
console.log(err)
})
/* Callback */
mycompany.getUser(58844, (err, response) => {
console.log(err, response)
})
Get User Employments
Call as shown above in the API Reference.
Options reference: #get-user-employments Sorting
Get User Employment
Call as shown above in the API Reference.
Get User Holidays
Call as shown above in the API Reference.
Options reference: #get-user-holidays Sorting
Get User Holiday
Call as shown above in the API Reference.
Sorting
You can sort your results by adding sort_by
to your options object.
sort_by: 'title'
sort_by: 'date desc'
Read more: #sorting
Setup / Install
Use npm install @burnett01/node-moco
const Moco = require('@burnett01/node-moco')
Unit-Tests
The testing-framework used in this module is Mocha with the BDD / TDD assertion library Chai.
- test/test.default.js | Source
Output using Mocha list
reporter:
Default reporter: list
Make
make test
NPM
npm test
Contributing
You're very welcome and free to contribute. Thank you.