(Original Blog Post from Adrian Hara, coresuite mobile expert, posted at the 06.06.2014)
This series of blog posts aims to provide an introduction to using the Coresuite.com API. After reading through it you should have enough confidence to go ahead and build your own app that leverages it.
You can jump to any of the posts in the series here:
- Part 1 – Intro
- Part 2 – Setting up Coresuite.com
- Part 3 – Setting up the development environment (this blog post)
- Part 4 – App structure and AngularJS
- Part 5 - Equipment list
- Part 6 – Equipment list tweaks & Equipment details
- Part 7 – Request service
- Part 8 – Wrap-up and future ideas
The previous post in the series left us off with a functional (and responsive) web application, but without any real data. It’s time to remedy this.
To find out how we can get the real data from the Coresuite.com cloud, let’s head over to http://docs.coresuite.com/ and read about it
As it turns out, it’s pretty simple:
- The actual data for our company can be stored in any of several Data Server Nodes (e.g. in US, Europe etc) so we first need to find out where it is
- Once we know which DSN to use we simply make a HTTP GET call to it, appending “/Equipment” as the type of object we’re interested in
- Additionally for all calls we need to supply some authentication information which, for the sake of brevity, will be the credentials of one of the users we got by email when originally creating the Coresuite.com account
Before we get the data though, let’s take a look at (a simplified, from our application’s point of view) conceptual domain model of the Coresuite.com cloud.
“Translated” in our app’s domain model:
- BusinessPartner – end user of our app, probably a circus manager
- Equipment – any circus thing (e.g. tent, trampoline etc)
- ServiceCall – a request for service for a circus thing
As you can see, the Equipment is linked to its BusinessPartner and a ServiceCall has links to both the BusinessPartner who requested it and the Equipment for which service is needed.
Getting the Equipment data
As described above, we need some “infrastructure” code to find out what the URL of the DSN is before we can actually call it to actually get data.
As documented here http://docs.coresuit.../reference.html we call a specific endpoint on the Master Server Node (MSN), passing in our user’s credentials and we get back an object with information about our company, including its name and DSN URL which we’ll both need for actual data requests.
Sidenote: please keep in mind to NEVER store user credentials like this in a production app, as anyone can simply “View Source” of the web page and get access to your data. One good alternative to do it would be to provide a login screen for the user to enter their credentials themselves first or, even better, use some server-side framework like Asp.Net for such purposes.
So now that we have the company information, we can call the DSN to get the Equipment data:
The “getAllFromDSN” function is a generic function that we can use to get a list of any kind of object. In our case we call it for “Equipment” and afterwards simply expose the received data on the Scope, to be consumed/displayed in HTML. The data object looks like so:
Showing the Equipment list
If getting the data from the cloud took some doing, showing it is a formality:
This brings us to the end of this part. In the next one we’ll take a look at how to make this list nicer and customize it to better suit our needs.