4.2.0 • Published 2 years ago

node-moco v4.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
2 years ago

node-moco

GitHub license Build Status npm version

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

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:

PropertyDescription
detailsAn object containing configuration details
domainThe first part of your MOCO domain (eg. mycompany)
apikeyYour MOCO integration API Key
debugWhether to debug requests

Method reference:

Create a Moco instance

Available options:

RequiredDefault
domainmycompanyYes
apikeyyour keyYes
debugenable debuggingNofalse
const company = new Moco({
  domain: 'mycompany',
  apikey: '<key here>'
})

Get Activities

Available options:

RequiredDefault
optionsfor example: { from: '2018-02-01' }NoNone
cboptional 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:

RequiredDefault
idfor example: 58844YesNone
cboptional 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:

RequiredDefault
optionsfor example: { type: 'customer' }NoNone
cboptional 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:

RequiredDefault
idfor example: 58844YesNone
cboptional 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:

RequiredDefault
optionsfor example: { include_archived: false }NoNone
cboptional 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:

RequiredDefault
idfor example: 58844YesNone
cboptional 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:

RequiredDefault
optionsfor example: { from: '2018-02-01' }NoNone
cboptional 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:

RequiredDefault
idfor example: 58844YesNone
cboptional 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:

RequiredDefault
optionsNoNone
cboptional 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:

RequiredDefault
idfor example: 58844YesNone
cboptional 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.

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.


License

MIT

4.2.0

2 years ago

4.1.0

4 years ago

4.0.0

4 years ago

3.9.0

4 years ago

3.8.2

4 years ago

3.8.0

4 years ago

3.8.1

4 years ago

3.3.0

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago