Docs BETA
/

Vend

Lets make this machine move


With each vend the machine will attempt to vend the channel given until either an item is vended or a full revolution of the drive belt has occurred. When a full revolution of a channel's drive belt occurs with no stock found. The machine then sets that channel to "Out of Stock" and won't attempt to vend from it again. If there are more channels to try, the machine will move onto them and carry out the same procedure until there are no channels left in its instruction.

Channel Status

Channels that are set to "Out of Stock" will be reset back to their original state when the door has been opened and closed. This is regardless of whether it has actually been restocked. This means that, in most cases, stock control is not required. For example if you have the machine full of the same products then you can just automatically vend the most optimal row until the machine has been emptied.

Attempts

All vend methods accept an attempts property. This is the number of attempts at vending a channel the machine is allowed to make before it gives up.

API

Optimal

Machine.vend.optimal is the simplest form of vending. It quite simply selects the active channel that's closest to the bottom of the machine. This means the elevator has the shortest possible trip and thus is the fastest channel to vend.

Although it is fast, it is not ideal for a machine with different types of products in stock, as you have no control as to which channel the machine will vend from.

OS.Machine.vend.optimal({
  attempts: 20 // Optional
})

Properties

PropTypeDefaultDescription
attemptsinteger80Amount of attempts until we reject the promise. If no value is passed then the machine will continue to attempt all the channels it has been instructed to

Channel

Machine.vend.channel is the most configurable form of vending. You pass a channel number (1-80) to vend from and it will return a success/fail. If you would like the machine to attempt more then one channel, pass an array instead of a string and it will work through the channels in the order given.

Single channel

OS.Machine.vend.channel({
  channel: '21' // Required
})

Multi channel

OS.Machine.vend.channel({
  channel: ['21','22'] // Required
})

Properties

PropTypeDefaultDescription
channel

Required
string or arrayN/AChannel number (1-80) or numbers in an array to vend from.
attemptsinteger80Amount of attempts until we reject the promise. If no value is passed then the machine will continue to attempt all the channels it has been instructed to

Random

Machine.vend.random is fully random vending. All channels that are connected and not marked as "Out of Stock" will be chosen in random order and attempted to vend from. They will continue to be attempted until stock is found, or until attempts have run out.

OS.Machine.vend.random({
  attempts: 20 // Optional
})

Properties

PropTypeDefaultDescription
attemptsinteger80Amount of attempts until we reject the promise. If no value is passed then the machine will continue to attempt all the channels it has been instructed to

Error codes

vendOS DevTools currently only supports two error codes for Machine.vend, but more granular codes will be added soon.

CodeDescription
VEND_REJECTEDThe data passed to the method is malformed. Perhaps a required argument is missing. Check the message property for more details.
VEND_FAILEDSomething went wrong. Check the message property for more details.

Roadmap

We will be adding other vending methods to our Machine.vend api shortly. These will work to make certain common tasks easier for you to perform. Until then, everything you need to work with should be here.