6. Tools
Tools
Tools are services that run on your Data. Like the Sentiment Analysis tool that tells you when your social media posts are positive, negative or neutral. There are a few Tools available but many more are to come. Working with Tools is pretty similar with the Applications and Data Plugs.
Getting Existing Tools
You can easily fetch the available tools using the following function:
HATToolsService().getAvailableTools(
userDomain: userDomain,
userToken: userToken,
completion: gotAppsFromDex,
failCallBack: errorGettingApps)userDomainis the user'sPDA addressused to form the url to fetch the availableToolsuserTokenis the user's token to authenticate with thePDAcompletionis a callback function that is used when the request is successful with a type of((List<HATToolsObject>, String?) -> Unit).The first parameter is an array of
HATToolsObject. This is the structure ofTools. More on that in the next section.The second parameter is an optional
String, the refreshed user token that thePDAreturns.failCallBackis a callback that is used when the request has failed. The type of the function is((HATError) -> Unit).HATErroris 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:
[
{
"id": "sentiment-tracker",
"info": {
"version": "1.0.0",
"versionReleaseDate": "2018-01-01T12:00:00.000Z",
"name": "Sentiment Tracker",
"headline": "Sentiment in your words",
"description": {
"text": "Sentiment Tracker analyses your texts on Facebook, Twitter and Notables to work out how negative or positive your postings are."
},
"termsUrl": "https://hatdex.org/terms-of-service-hat-owner-agreement",
"supportContact": "[email protected]",
"graphics": {
"banner": {
"normal": ""
},
"logo": {
"normal": "https://github.com/Hub-of-all-Things/exchange-assets/blob/master/Sentiments/logo.png?raw=true"
},
"screenshots": [
{
"normal": "https://github.com/Hub-of-all-Things/exchange-assets/blob/master/Sentiments/Screenshot1.jpg?raw=true"
},
{
"normal": "https://github.com/Hub-of-all-Things/exchange-assets/blob/master/Sentiments/Screenshot2.jpg?raw=true"
}
]
},
"dataPreviewEndpoint": "/she/feed/she/sentiments"
},
"developer": {
"id": "hatdex",
"name": "Dataswift Ltd",
"url": "https://hatdex.org",
"country": "United Kingdom"
},
"trigger": {
"triggerType": "individual"
},
"dataBundle": {
"name": "data-feed-counter",
"bundle": {
"she/insights/emotions": {
"endpoints": [
{
"endpoint": "she/insights/emotions",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
},
"notables/feed": {
"endpoints": [
{
"endpoint": "rumpel/notablesv1",
"mapping": {
"message": "message",
"timestamp": "created_time"
}
}
],
"orderBy": "created_time",
"ordering": "descending",
"limit": 20
},
"she/insights/emotions/negative": {
"endpoints": [
{
"endpoint": "she/insights/emotions/negative",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
},
"twitter/tweets": {
"endpoints": [
{
"endpoint": "twitter/tweets",
"mapping": {
"message": "text",
"timestamp": "lastUpdated"
}
}
],
"orderBy": "lastUpdated",
"ordering": "descending",
"limit": 20
},
"facebook/feed": {
"endpoints": [
{
"endpoint": "facebook/feed",
"mapping": {
"message": "message",
"timestamp": "created_time"
}
}
],
"orderBy": "created_time",
"ordering": "descending",
"limit": 20
},
"she/insights/emotions/neutral": {
"endpoints": [
{
"endpoint": "she/insights/emotions/neutral",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
},
"she/insights/emotions/positive": {
"endpoints": [
{
"endpoint": "she/insights/emotions/positive",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
}
}
},
"status": {
"available": true,
"enabled": true,
"lastExecution": "2018-11-12T10:29:36.724Z"
}
}
]idis theToolid on thePDA. You need this when you want to enable or disable aTool.infoHas all the information you will need to present theTool. It is been formed by 10 values:versionis the version number of theTool.ToolslikeApplicationsandData Plugscan be updated. This will result a new version.versionReleaseDateis the date that the latest version was pushed inISOformat.nameis the official name of theTool.headlineis a small text to compliment thename. Used like a subtitle.descriptionallows you to describe your app better with longer text. Also, it has support for different formats of text,text,markdownandhtml.termsUrlis aURLof the terms and conditions. Users must be able to read them if they wish.supportContacta support email. Users will use this email to contact you.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. Optionalgraphicsis 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.
HATimages can be categorised assmall,normal,largeandxlarge. Exceptnormal, all are optional values.
dataPreviewEndpointis aURLthat you can use to fetch the 'feed' of theTool. You have to form theURLlike .this:"https://$hatAddress/api/v2.6$dataPreviewEndpoint"
developerconsists of some basic info about the developer. This includes:id,name,urlandcountry.statusis formed by 4 values describing the state of theTool:availableindicates if theToolis available. AToolcan be unavailable, for example, when in testing. Default value is false.enabledindicates if theToolis enabled by the user. Default value is false.lastExecutionis an optionalStringthat has a date in anISOformat indicating the date that theToolrun for the last time.executionStartedis an optionalStringthat has a date in anISOformat indicating the date that theToolstarted running for the last time.
dataBundleis out of the scope for this guide. Here you can find the permissions needed in order for theToolto run.triggerdescribes the frequency that theToolwill be executed.Toolsare not running all the time. The possible values are:periodic,individualandmanual.
A request that has failed will look like this:
{
"error": "Not Authenticated",
"message": "Not Authenticated"
}erroris the error that has occurredmessageis a more descriptive message about theerrorthat has occurred
Enabling / Disabling Tools
Enable Tool
You can easily enable a tool by using the function below:
HATToolsService().enableTool(
toolName: selectedTool.id,
userDomain: userDomain,
userToken: userToken,
completion: toolStatusChanged,
failCallBack: errorInteractingWithTool)toolNameis theidof the tool. It can be the same as thenameor not.userDomainis the user'sHAT addressused to form the url to enable theTool.userTokenis the user's token to authenticate with thePDA.completionis a callback. It is called when the request is successful with a type of((HATToolsObject, String?) -> Unit).The first parameter is the now enabled
HATToolsObject. The second parameter is an optionalString, the refreshed user token that thePDAreturns.failCallBackis a callback that is used when the request has failed. The type of the function is((HATError) -> Unit).HATErroris 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:
{
"id": "sentiment-tracker",
"info": {
"version": "1.0.0",
"versionReleaseDate": "2018-01-01T12:00:00.000Z",
"name": "Sentiment Tracker",
"headline": "Sentiment in your words",
"description": {
"text": "Sentiment Tracker analyses your texts on Facebook, Twitter and Notables to work out how negative or positive your postings are."
},
"termsUrl": "https://hatdex.org/terms-of-service-hat-owner-agreement",
"supportContact": "[email protected]",
"graphics": {
"banner": {
"normal": ""
},
"logo": {
"normal": "https://github.com/Hub-of-all-Things/exchange-assets/blob/master/Sentiments/logo.png?raw=true"
},
"screenshots": [
{
"normal": "https://github.com/Hub-of-all-Things/exchange-assets/blob/master/Sentiments/Screenshot1.jpg?raw=true"
},
{
"normal": "https://github.com/Hub-of-all-Things/exchange-assets/blob/master/Sentiments/Screenshot2.jpg?raw=true"
}
]
},
"dataPreviewEndpoint": "/she/feed/she/sentiments"
},
"developer": {
"id": "hatdex",
"name": "Dataswift Ltd",
"url": "https://hatdex.org",
"country": "United Kingdom"
},
"trigger": {
"triggerType": "individual"
},
"dataBundle": {
"name": "data-feed-counter",
"bundle": {
"she/insights/emotions": {
"endpoints": [
{
"endpoint": "she/insights/emotions",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
},
"notables/feed": {
"endpoints": [
{
"endpoint": "rumpel/notablesv1",
"mapping": {
"message": "message",
"timestamp": "created_time"
}
}
],
"orderBy": "created_time",
"ordering": "descending",
"limit": 20
},
"she/insights/emotions/negative": {
"endpoints": [
{
"endpoint": "she/insights/emotions/negative",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
},
"twitter/tweets": {
"endpoints": [
{
"endpoint": "twitter/tweets",
"mapping": {
"message": "text",
"timestamp": "lastUpdated"
}
}
],
"orderBy": "lastUpdated",
"ordering": "descending",
"limit": 20
},
"facebook/feed": {
"endpoints": [
{
"endpoint": "facebook/feed",
"mapping": {
"message": "message",
"timestamp": "created_time"
}
}
],
"orderBy": "created_time",
"ordering": "descending",
"limit": 20
},
"she/insights/emotions/neutral": {
"endpoints": [
{
"endpoint": "she/insights/emotions/neutral",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
},
"she/insights/emotions/positive": {
"endpoints": [
{
"endpoint": "she/insights/emotions/positive",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
}
}
},
"status": {
"available": true,
"enabled": true,
"lastExecution": "2018-11-13T12:36:59.061Z"
}
}A request that has failed will look like this:
{
"error": "Not Authenticated",
"message": "Not Authenticated"
}erroris the error that has occurredmessageis a more descriptive message about theerrorthat has occurred
Disable Tool
HATToolsService().disableTool(
toolName: selectedTool.id,
userDomain: userDomain,
userToken: userToken,
completion: toolStatusChanged,
failCallBack: errorInteractingWithTool)toolNameis theidof the tool. It can be the same as thenameor not.userDomainis the user'sPDA addressused to form the url to disable theTool.userTokenis the user's token to authenticate with thePDA.completionis a callback function that is used when the request was successful with a type of((HATToolsObject, String?) -> Unit).The first parameter is the now disabled
HATToolsObject. The second parameter is an optionalString, the refreshed user token that thePDAreturns.failCallBackis a callback that is used when the request has failed. They type of the function is((HATError) -> Unit).HATErroris 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:
{
"id": "sentiment-tracker",
"info": {
"version": "1.0.0",
"versionReleaseDate": "2018-01-01T12:00:00.000Z",
"name": "Sentiment Tracker",
"headline": "Sentiment in your words",
"description": {
"text": "Sentiment Tracker analyses your texts on Facebook, Twitter and Notables to work out how negative or positive your postings are."
},
"termsUrl": "https://hatdex.org/terms-of-service-hat-owner-agreement",
"supportContact": "[email protected]",
"graphics": {
"banner": {
"normal": ""
},
"logo": {
"normal": "https://github.com/Hub-of-all-Things/exchange-assets/blob/master/Sentiments/logo.png?raw=true"
},
"screenshots": [
{
"normal": "https://github.com/Hub-of-all-Things/exchange-assets/blob/master/Sentiments/Screenshot1.jpg?raw=true"
},
{
"normal": "https://github.com/Hub-of-all-Things/exchange-assets/blob/master/Sentiments/Screenshot2.jpg?raw=true"
}
]
},
"dataPreviewEndpoint": "/she/feed/she/sentiments"
},
"developer": {
"id": "hatdex",
"name": "Dataswift Ltd",
"url": "https://hatdex.org",
"country": "United Kingdom"
},
"trigger": {
"triggerType": "individual"
},
"dataBundle": {
"name": "data-feed-counter",
"bundle": {
"she/insights/emotions": {
"endpoints": [
{
"endpoint": "she/insights/emotions",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
},
"notables/feed": {
"endpoints": [
{
"endpoint": "rumpel/notablesv1",
"mapping": {
"message": "message",
"timestamp": "created_time"
}
}
],
"orderBy": "created_time",
"ordering": "descending",
"limit": 20
},
"she/insights/emotions/negative": {
"endpoints": [
{
"endpoint": "she/insights/emotions/negative",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
},
"twitter/tweets": {
"endpoints": [
{
"endpoint": "twitter/tweets",
"mapping": {
"message": "text",
"timestamp": "lastUpdated"
}
}
],
"orderBy": "lastUpdated",
"ordering": "descending",
"limit": 20
},
"facebook/feed": {
"endpoints": [
{
"endpoint": "facebook/feed",
"mapping": {
"message": "message",
"timestamp": "created_time"
}
}
],
"orderBy": "created_time",
"ordering": "descending",
"limit": 20
},
"she/insights/emotions/neutral": {
"endpoints": [
{
"endpoint": "she/insights/emotions/neutral",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
},
"she/insights/emotions/positive": {
"endpoints": [
{
"endpoint": "she/insights/emotions/positive",
"mapping": {
"message": "text",
"timestamp": "timestamp"
}
}
],
"orderBy": "timestamp",
"ordering": "descending",
"limit": 20
}
}
},
"status": {
"available": true,
"enabled": false,
"lastExecution": "2018-11-13T12:36:59.061Z"
}
}You can read more about the structure here.
A request that has failed will look like this:
{
"error": "Not Authenticated",
"message": "Not Authenticated"
}erroris the error that has occurredmessageis a more descriptive message about theerrorthat has occurred
Last updated
Was this helpful?