5. Data Plugs
Data Plugs
In the PDA ecosystem, Data Plug is a minimal API-to-API web service with the primary purpose of fetching data from third party API and pushing it to the user's PDA. Due to the security considerations and limited scope of required functionality, each data plug is granted a write-only access to any particular PDA.
Fetch Data Plugs and Applications
HAT for iOS provides an API call for you to fetch all the available Data Plugs:
HATExternalAppsService.getExternalApps(
userToken: userToken,
userDomain: userDomain,
completion: availablePlugsReceived,
failCallBack: errorRetrievingDataPlugs)As you may have noticed, the function name is getExternalApps. Applications and Data Plugs are not only represented by the same structure but they have the same API as well.
userTokenis the user's token to authenticate with thePDA.userDomainis the user'sPDA addressused to form the url to fetch theData Plugs.completionis a callback that is called when the request was successful. It has type of@escaping (([HATApplicationObject], String?) -> Void).The first parameter is an array of
HATApplicationObject. This is the structure ofData PlugsandApplications. More on that in the next section.This array contains all the
Data PlugsandApplicationson thePDA. The second parameter is an optionalString, the refreshed user token that thePDAreturns.failCallBackis a callback that is called when the request has failed. The type of the function is@escaping ((HATTableError) -> Void).HATTableErroris a custom object describing the errors that have occurred during the querying of the tables in the database.
A successful response will have statusCode 200 and look like this:
applicationholds the most parts of the structure. It consists of the following 7 values:
idin theapplicationpart of the JSON is theidof theData Plugin theHAT.kindin theapplicationpart of the JSON has 4 values holding the various urls and the type of theData Plug:urlis the url of theData PlugorApplicationto use in webiosUrlis the iTunes url of theApplicationin theApp Store. It's optional and only there forApplicationtypeandroidUrlis the Play Store url of theApplicationin thePlay Store. It's optional and only there forApplicationtypekindis the kind. As we mentioned earlierData PlugandApplicationis represented by the same structure and use the same APIsTherefore, the
kindcan beApporData Plug. When for example you want only theApplicationsthen simply you are going to filter the array based on thekind.
infoin theapplicationpart of the JSON has 12 values:versionis the version number of the app in theHAT. This may be different from the version number of theApplicationin theApp StoreorPlay StoreupdateNotesis essentially the release notes for the latest version. It is formed by theheader, the title of the release notes, and thenotesan array ofStringto easily show the notes as an unordered list.publishedindicates if the app is published or not. It can be that the app is not yet published, so it's not yet live, and it's testing, beta, appnameis the official name of the appheadlineis the headline or subtitle of the app. It can be placed underneath the name for example, to provide more context for the app if needed.descriptionallows you to describe your app better with a longer text. Also, it has support for different formats of text,text,markdownandhtml.markdownandhtmlare optional.termsUrlis aURLof the terms and conditions. Users must be able to read them if they wish.dataUsePurposeis a text explaining why and how the app will use the datasupportContacta support email. Users will use this email to contact you.ratingis an optional object formed byscorewhich describes the permissions and the data use using a letter-based scoring system. You can read more here.dataPreviewis actually an array ofSheFeedstructures. This is used to preview items, if any, instead of making another network request to fetch those items. The array can be empty.
graphicsis a structure formed by 3 values:banneris theURLof the banner imagelogois theURLof the app logo imagescreenshotsis theURLof the app's screenshots used to showcase what this app offers.All the above 3 values use the same structure.
PDAimages can be categorised assmall,normal,largeandxlarge.Except
normalall are optional values.
developerconsists of some basic info about the developer. This includes:id,name,urlandcountry.permissionsincludes 3 values:rolesGrantedwhich is an array ofroleanddetail, optional, describing the roles granted in theApplication.dataRetrievedwhich is a type ofDataOfferRequiredDataDefinitionObjectV2. It describes the data that theApplicationwill retrieve. optional.rollingdescribes if the data have a rolling start datebundleYou can read more about it herestartDatethe start date of thebundle. optionalendDatethe end date of thebundle. optional
dataRequiredwhich is a type ofHATExternalAppsDataRequiredObject. optional
setupencapsulates all the urls that theApplicationneeds in order to setup. The structure is the same askindbut the urls can be differentstatusprovides some info about the status of the application:compatibility– the last version that is compatible with the current oneversionReleaseDate– the date, inISOformat, of the latest releasekind– the kind of the release. It can be eitherInternalorExternal.recentDataCheckEndpoint– aURLpointing on the most recent data point. optionalstatusUrl– aURLto check the status of theApplicationorData Plug. optionalexpectedStatus– the expected status number. optionaldataPreviewEndpoint– aURLpointing to the actual data on thePDAto show them as a preview. optional
setupBoolean value indicating if this app has been setup successfullyenabledBoolean value indicating if this app has been enabled successfullyactiveBoolean value indicating if this app is currently active or notneedsUpdatingBoolean value indicating if this app needs updating. AnApplicationmay need an update in case the termshave changed or a new version has been released.
A request that has failed will look like this:
erroris the error that has occurredmessageis a more descriptive message about theerrorthat has occurred
Set up an Application
Setting up an application is similar to the login process. First you have to check the kind; is it App, or Data Plug. The 2 of them are different in how you set them up.
In the case of an App you first have to check if the app is already installed on the user's device. To do that you have to check with:
where appURL is the iosUrl from the Application -> setup. If user has the app installed, then you have to form a URL like this:
hatAddressis the (fully qualified domain) address of the PDA, e.g.postman.hubat.netappIDis the id of the application to setup.appURLis the URL where the user should be sent to after completing authentication. In this case it is theiosURL.fallbackis the URL where the user should be sent to in case the authentication has failed. Optional. For aniOSapplication that would probably be:\(applicationName)://failedand has to be added in theinfo.plistfile of the project in Xcode as a known URL.
As you may have noticed this is exactly the same URL as the login URL and there is a reason for this. The setup process goes through web. Just like during the login process, the user will be asked to insert their password before continuing to the next step. The next step is accepting the terms and conditions and giving the permissions the app requires to function. After that if everything goes smoothly, PDA will redirect back to the success redirect. The redirect url will now include a parameter which is the token for the particular app. iOS will ask the user if they want to launch the particular app. If the user selects "yes" then the app will be launched. If there is a problem, DA will redirect to the fallback url and you have to hide Safari and show a message that something went wrong.
If you don't know how to handle SFSafariViewController you can read more here.
If the user does not have the app installed, you first have to redirect them to the App Store in order for them to download the app. The URL that you have to use the url in Application -> kind. Again the only thing you have to do is open it using Safari. When the user has installed the app they may then tap again to set up the Application.
Set up Data Plug
Setting up a Data Plug is a lot simpler than setting up an Application. You just open the url in Application -> kind with safari and follow the instructions. Again, the user will first have to enter the password. After that each Data Plug has a different way of asking permissions and registering with the PDA.
State of the Application and Data Plug
Application and Data Plug can be in multiple states. Setup, failing, need updating, disabled. To respond in state changes you can use the following snippet:
connectedis the case when theApplicationorData Plugisenabled,activeand it doesn'tneedsUpdating.fetchingis the case when theApplicationorData Plugisenabled,active, it's anAppand themostRecentDataisnil. This means that no data have been saved in thePDAyet.needsUpdatingis the case when theApplicationorData Plugis marked asneedsUpdatingin the API response. This means the user has to go through the setup process again.failingis the case when there is a problem in theApplicationorData Plug. Setting up again might or might not help. In case this persists please do contact us.notConnectedis the case when theApplicationorData Plughas never been set up before.
Disable Data Plug or Application
You can also disable a Data Plug or an Application. To do that you can call the next function:
appIDis the id, inApplicationstructure, of theApplicationorData PluguserDomainis the user'sPDA addressused to form the url to disable theData PlugorApplicationuserTokenis the user's token used to authenticate with thePDAcompletionis a callback function that is called when the request is successful with a type of@escaping @escaping ((HATApplicationObject, String?) -> Void). The first parameter is the disabledHATApplicationObject. The second parameter is an optionalString, the refreshed user token that thePDAreturns.failCallBackis a callback that is called when the request has failed. The type of the function is@escaping ((HATTableError) -> Void).HATTableErroris a custom object describing the errors that have occurred during the querying of the tables in the database.
A successful response will have statusCode 201 and look like this:
If you are not familiar with the structure you can read more here.
A request that has failed will look like this:
erroris the error that has occurredmessageis a more descriptive message about theerrorthat has occurred
Last updated
Was this helpful?