Installing Omnivore API in Ruby on Rails Application
Omnivore API provides the universal Point of Sale (POS) API. It gives you access to every action and detail of the point of sale system in a restaurant. This includes menu information, orders, payments, tips, server and table information and historical sales data. You can find more details on omnivore here.
Omnivore’s cloud-based development platform enables a single integration through our API, seamlessly facilitating the connections to POS systems now and into the future. By lowering the technology integration barriers for app developers, Omnivore simplifies the process for restaurants to test and evaluate new technologies through a proven interface installed on their POS.
Setup Omnivore App
You can register on Omnivore using your Github account or by providing email address and other details. so let’s first create an account. Click here to register.
Once you get registered, you can see screen similar to below.
Click on the Applications link from the menu and you will find one demo application ready for use. You can also create your own application here. Inside API tools, you can trace your API activity with POS and you can test your requests and response on API console.
Here we are going to use this Virtual POS location. We have to use the location ID in each request, so note it down first. Now let’s move to the API console. You can simulate all requests mentioned here in your API console. It will respond based on the current virtual POS data.
Go to your demo application and note down the API key. You can find it at applications > API keys > [Your development API key]. We will use default development key here.
As you can see it provides different API key for accessing different version API so make sure that you are using the correct version of API key with that version of API.
Now, we have our account on Omnivore and an application with API key so let’s move to the Rails part.
Integrate with Rails App
Create a new Rails application first. We are going to access Omnivore API through HTTP requests so we need to add gem HTTParty.
Add below line to your gemfile and do bundle install.
To enable bootstrap css, you can also add bootstrap-sass gem in it.
First of all, we will display all the available items to user so that one can choose and buy. We will restrict the user to buy only one item at a time for this demo version but you can implement a cart and do same.
Now, create a tickets controller and an action to fetch all the items and display them. Before that, let’s create a base_url method so that we don’t need to write base URL every time on the HTTP call.
Now lets create a method which brings all the menu items for us.
We will also add a link to buy that food item. To identify each item, we will pass item id and price level id which is required to decide it’s price while generating a ticket.
Now, Let’s create a method to handle the order request.
Omnivore has APIs to open a ticket, then to add items to that ticket and at last to make the payment. If payment is successful, then the ticket status will be closed otherwise it will remain open.
We need a few details like location id, employee id, order type id, revenue center id, table id to open a ticket. You can make all these things dynamic by making different API calls but in this demo we are using some static values. Here is the code to open a ticket.
Once you open the ticket, you have to add items to that order. In our case, user will click on a link having item id and price level id as parameters so we can use these values to identify the item and then make a call to add that item to order.
In response you can see that your added item is embedded inside the order. Now it’s time to pay for what you bought from the home page. We have to make another API call with the open ticket id.
Once you finish the payment the ticket will be closed automatically. You can get list of all the tickets from the POS using its API.
You can display the ticket information from this response. It contains employee information, revenue area information, total charges, taxes, items details etc.
There is one more API which we can use to get individual ticket details.
You can also find the current status of the ticket and its open/close dates.
You can find more API related docs here. You can find fully functional Rails application with Omnivore API at this github repository.
That’s it for now. For more interesting stuff, Keep Reading!
At BoTree Technologies, we build enterprise applications with our RoR team of 25+ engineers.
Consulting is free – let us help you grow!
Choose Your Language
- Digital Marketing
- IT Consulting
- Project Management