Skip to content

Commit

Permalink
Merge pull request #3 from vikramezhil/wellness-api-filter
Browse files Browse the repository at this point in the history
Wellness api filter
  • Loading branch information
vikramezhil authored Jan 4, 2019
2 parents 1bc90c5 + 5bc907b commit e381831
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 6 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cordova-plugin-humanapi v1.0.3
# cordova-plugin-humanapi v1.0.4
humanapi cordova plugin for android & ios

<b><h2>Plugin installation</h2></b>
Expand Down Expand Up @@ -49,6 +49,12 @@ For a detailed documentation 📔, please have a look at the [Wiki](https://gith
alert("Error = " + error)
})

window.plugin.humanapi.executeByFilter("WELLNESS_NAME", "ACCESS_TOKEN", "FILTER_NAME", function(result) {
alert("Result = " + result)
}, function(error) {
alert("Error = " + error)
})

<b>Sources Data</b>

window.plugin.humanapi.execute("sources", "ACCESS_TOKEN", function(result) {
Expand Down Expand Up @@ -77,6 +83,12 @@ For a detailed documentation 📔, please have a look at the [Wiki](https://gith
alert("Error = " + error)
})

human.plugin.humanapi.executeByFilter("WELLNESS_NAME", "ACCESS_TOKEN", "FILTER_NAME", (result) => {
alert("Result = " + result)
}, (error) => {
alert("Error = " + error)
})

<b>Sources Data</b>

var human: any = window
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-humanapi",
"version": "1.0.3",
"version": "1.0.4",
"description": "Human API Plugin for Android and IOS",
"cordova": {
"id": "cordova-plugin-humanapi",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-humanapi" version="1.0.3" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="cordova-plugin-humanapi" version="1.0.4" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>Human API Plugin</name>
<description>Human API Plugin for Android and IOS</description>
<author>Vikram Ezhil</author>
Expand Down
4 changes: 4 additions & 0 deletions src/android/HumanAPIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("execute")) {
this.humanAPIService.execute(callbackContext, args.getString(0), args.getString(1));

return true;
} else if (action.equals("executeByFilter")) {
this.humanAPIService.executeByFilter(callbackContext, args.getString(0), args.getString(1), args.getString(2));

return true;
}

Expand Down
28 changes: 27 additions & 1 deletion src/android/human/HumanAPIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onServiceError(CallbackContext callbackContext, String passBackKey,
}

/**
* Executes the human API wellness services based on key
* Executes the human API services based on key
*
* @param callbackContext The callback context
* @param key The human api service key
Expand All @@ -79,4 +79,30 @@ public void execute(CallbackContext callbackContext, String key, String accessTo
}
}
}

/**
* Executes the human API services based on key and filter
*
* @param callbackContext The callback context
* @param key The human api service key
* @param accessToken The access token
* @param filterName The filter name
*/
public void executeByFilter(CallbackContext callbackContext, String key, String accessToken, String filterName) {
if(accessToken == null || accessToken.isEmpty()) {
humanAPIListener.onHumanAPIUpdate(callbackContext, false, humanAPIModel.getHumanAPIHybridData("", key, "Access token is empty"));
} else {
// Getting the data url
String url = this.humanAPIModel.getDataURL(key);

if(url == null || url.isEmpty()) {
humanAPIListener.onHumanAPIUpdate(callbackContext, false, humanAPIModel.getHumanAPIHybridData("", key, "Unknown data key, unable to generate url"));
} else {
// Saving the access token in the human api model
this.humanAPIModel.setAccessToken(accessToken);

service.get(callbackContext, key, url + ("?source=" + filterName), humanAPIModel.getDataHeader());
}
}
}
}
14 changes: 13 additions & 1 deletion src/ios/HumanAPIPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import UIKit
}

///
/// Executes the human API wellness services
/// Executes the human API services
///
/// :param: command The cdv url command instance
///
Expand All @@ -77,6 +77,18 @@ import UIKit
}
}

///
/// Executes the human API services based on filter
///
/// :param: command The cdv url command instance
///
@objc(executeByFilter:)
func executeByFilter(command: CDVInvokedUrlCommand) {
if let wellnessKey = command.arguments[0] as? String, let token = command.arguments[1] as? String, let filter = command.arguments[2] as? String {
humanAPIService?.executeByFilter(command: command, key: wellnessKey, accessToken: token, filterName: filter)
}
}

// @Override HumanAPIVCDelegate Methods

func onHumanAPIUpdate(command: CDVInvokedUrlCommand?, success: Bool, humanAPIData: String) {
Expand Down
26 changes: 25 additions & 1 deletion src/ios/human/HumanAPIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HumanAPIService: NSObject, ServiceDelegate {
}

///
/// Executes the human API wellness services based on key
/// Executes the human API services based on key
///
/// :param: command The callback context
/// :param: key The human api service key
Expand All @@ -45,6 +45,30 @@ class HumanAPIService: NSObject, ServiceDelegate {
}
}

///
/// Executes the human API services based on key & filter
///
/// :param: command The callback context
/// :param: key The human api service key
/// :param: accessToken The access token
/// :param: filterName The filter name
///
func executeByFilter(command: CDVInvokedUrlCommand, key: String, accessToken: String, filterName: String) {
if(accessToken.count == 0) {
humanAPIServiceDelegate?.onHumanAPIUpdate(command: command, success: false, humanAPIData: humanAPIModel.getHumanAPIHybridData(humanAPIData: "", key: key, pluginMsg: "Access token is empty"))
} else {
if let url = humanAPIModel.getDataURL(dataKey: key) {
// Saving the access token in the human api model
humanAPIModel.accessToken = accessToken

let filterUrl: String = "\(url)?source=\(filterName)"
service.get(command: command, passbackKey: key, requestLink: filterUrl, customHeaders: humanAPIModel.dataHeader)
} else {
humanAPIServiceDelegate?.onHumanAPIUpdate(command: command, success: false, humanAPIData: humanAPIModel.getHumanAPIHybridData(humanAPIData: "", key: key, pluginMsg: "Unknown data key, unable to generate url"))
}
}
}

// @Override ServiceDelegate Methods

func onServiceRunning(command: CDVInvokedUrlCommand?, passBackKey: String, serviceRunning: Bool) {
Expand Down
4 changes: 4 additions & 0 deletions www/humanapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ HumanAPIPlugin.prototype.execute = function (type, accessToken, success, error)
exec(success, error, pluginName, 'execute', [type, accessToken]);
};

HumanAPIPlugin.prototype.executeByFilter = function (type, accessToken, filterName, success, error) {
exec(success, error, pluginName, 'executeByFilter', [type, accessToken, filterName]);
};

// Installation constructor that binds HumanAPIPlugin to window
HumanAPIPlugin.install = function() {
if(!window.plugin) {
Expand Down

0 comments on commit e381831

Please sign in to comment.