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
- 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
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 | 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 |
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>'
})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)
})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)
})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)
})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)
})Call as shown above in the API Reference.
Options reference:
#get-comments
Sorting
Call as shown above in the API Reference.
Call as shown above in the API Reference.
Available options:
#get-contacts-people
Sorting
Call as shown above in the API Reference.
Call as shown above in the API Reference.
Options reference:
#get-deals
Sorting
Call as shown above in the API Reference.
Call as shown above in the API Reference.
Options reference:
#get-deal_categories
Sorting
Call as shown above in the API Reference.
Call as shown above in the API Reference.
Options reference:
#get-invoices
Sorting
Call as shown above in the API Reference.
Call as shown above in the API Reference.
Options reference:
#get-invoice-payments
Sorting
Call as shown above in the API Reference.
Call as shown above in the API Reference.
Options reference:
#get-offers
Sorting
Call as shown above in the API Reference.
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)
})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)
})Call as shown above in the API Reference.
Options reference:
#get-projects-assigned
Call as shown above in the API Reference.
Options reference:
#get-projects-expenses
Call as shown above in the API Reference.
Options reference:
#get-purchases
Sorting
Call as shown above in the API Reference.
Call as shown above in the API Reference.
Options reference:
#get-purchases-categories
Sorting
Call as shown above in the API Reference.
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)
})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)
})Call as shown above in the API Reference.
Options reference:
#get-units
Sorting
Call as shown above in the API Reference.
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)
})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)
})Call as shown above in the API Reference.
Options reference:
#get-user-employments
Sorting
Call as shown above in the API Reference.
Call as shown above in the API Reference.
Options reference:
#get-user-holidays
Sorting
Call as shown above in the API Reference.
You can sort your results by adding sort_by
to your options object.
sort_by: 'title'
sort_by: 'date desc'
Read more: #sorting
Use npm install @burnett01/node-moco
const Moco = require('@burnett01/node-moco')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 test
npm test
You're very welcome and free to contribute. Thank you.
