From 66cfdcf7a8302ec1e1ea5533e003966b18591850 Mon Sep 17 00:00:00 2001 From: Justin Unterreiner Date: Tue, 29 Sep 2015 20:56:33 -0700 Subject: [PATCH 1/2] Added type definitions for Ouralabs Cordova plugin --- .../cordova-plugin-ouralabs-tests.ts | 92 +++++++++++++++++++ .../cordova-plugin-ouralabs.d.ts | 39 ++++++++ 2 files changed, 131 insertions(+) create mode 100644 cordova-plugin-ouralabs/cordova-plugin-ouralabs-tests.ts create mode 100644 cordova-plugin-ouralabs/cordova-plugin-ouralabs.d.ts diff --git a/cordova-plugin-ouralabs/cordova-plugin-ouralabs-tests.ts b/cordova-plugin-ouralabs/cordova-plugin-ouralabs-tests.ts new file mode 100644 index 000000000..5f26cb77e --- /dev/null +++ b/cordova-plugin-ouralabs/cordova-plugin-ouralabs-tests.ts @@ -0,0 +1,92 @@ +/// + +var traceLevel: number = OuralabsPlugin.LogLevel.TRACE; +var debugLevel: number = OuralabsPlugin.LogLevel.DEBUG; +var infoLevel: number = OuralabsPlugin.LogLevel.INFO; +var warnLevel: number = OuralabsPlugin.LogLevel.WARN; +var errorLevel: number = OuralabsPlugin.LogLevel.ERROR; +var fatalLevel: number = OuralabsPlugin.LogLevel.FATAL; + +OuralabsPlugin.init("a"); +OuralabsPlugin.init("a", () => {}); +OuralabsPlugin.init("a", () => {}, (error: string) => {}); + +OuralabsPlugin.setAttributes("a"); +OuralabsPlugin.setAttributes("a", "b"); +OuralabsPlugin.setAttributes("a", "b", "c"); +OuralabsPlugin.setAttributes("a", null, "c"); +OuralabsPlugin.setAttributes("a", "b", "c"); +OuralabsPlugin.setAttributes("a", "b", "c", () => {}); +OuralabsPlugin.setAttributes("a", "b", "c", () => {}, (error: string) => {}); + +OuralabsPlugin.logTrace("a", "b"); +OuralabsPlugin.logTrace("a", "b", { "whoa": "yep" }); +OuralabsPlugin.logTrace("a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.logTrace("a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.logTrace("a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.logDebug("a", "b"); +OuralabsPlugin.logDebug("a", "b", { "whoa": "yep" }); +OuralabsPlugin.logDebug("a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.logDebug("a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.logDebug("a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.logInfo("a", "b"); +OuralabsPlugin.logInfo("a", "b", { "whoa": "yep" }); +OuralabsPlugin.logInfo("a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.logInfo("a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.logInfo("a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.logWarn("a", "b"); +OuralabsPlugin.logWarn("a", "b", { "whoa": "yep" }); +OuralabsPlugin.logWarn("a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.logWarn("a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.logWarn("a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.logError("a", "b"); +OuralabsPlugin.logError("a", "b", { "whoa": "yep" }); +OuralabsPlugin.logError("a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.logError("a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.logError("a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.logFatal("a", "b"); +OuralabsPlugin.logFatal("a", "b", { "whoa": "yep" }); +OuralabsPlugin.logFatal("a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.logFatal("a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.logFatal("a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.log(OuralabsPlugin.LogLevel.TRACE, "a", "b"); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.TRACE, "a", "b", { "whoa": "yep" }); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.TRACE, "a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.TRACE, "a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.TRACE, "a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.log(OuralabsPlugin.LogLevel.DEBUG, "a", "b"); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.DEBUG, "a", "b", { "whoa": "yep" }); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.DEBUG, "a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.DEBUG, "a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.DEBUG, "a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.log(OuralabsPlugin.LogLevel.INFO, "a", "b"); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.INFO, "a", "b", { "whoa": "yep" }); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.INFO, "a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.INFO, "a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.INFO, "a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.log(OuralabsPlugin.LogLevel.WARN, "a", "b"); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.WARN, "a", "b", { "whoa": "yep" }); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.WARN, "a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.WARN, "a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.WARN, "a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.log(OuralabsPlugin.LogLevel.ERROR, "a", "b"); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.ERROR, "a", "b", { "whoa": "yep" }); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.ERROR, "a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.ERROR, "a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.ERROR, "a", "b", null, () => {}, (error: string) => {}); + +OuralabsPlugin.log(OuralabsPlugin.LogLevel.FATAL, "a", "b"); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.FATAL, "a", "b", { "whoa": "yep" }); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.FATAL, "a", "b", { "whoa": "yep" }, () => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.FATAL, "a", "b", { "whoa": "yep" }, () => {}, (error: string) => {}); +OuralabsPlugin.log(OuralabsPlugin.LogLevel.FATAL, "a", "b", null, () => {}, (error: string) => {}); \ No newline at end of file diff --git a/cordova-plugin-ouralabs/cordova-plugin-ouralabs.d.ts b/cordova-plugin-ouralabs/cordova-plugin-ouralabs.d.ts new file mode 100644 index 000000000..d079ded7b --- /dev/null +++ b/cordova-plugin-ouralabs/cordova-plugin-ouralabs.d.ts @@ -0,0 +1,39 @@ +// Type definitions for cordova-plugin-ouralabs 1.0.0 +// Project: https://github.com/Justin-Credible/cordova-plugin-ouralabs +// Definitions by: Justin Unterreiner +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module OuralabsPlugin { + + interface OuralabsStatic { + + LogLevel: { + TRACE: number, + DEBUG: number, + INFO: number, + WARN: number, + ERROR: number, + FATAL: number + } + + init(channelId: string, successCallback?: () => void, failureCallback?: (error: string) => void): void; + + setAttributes(attribute1?: string, attribute2?: string, attribute3?: string, successCallback?: () => void, errorCallback?: (error: string) => void): void; + + logTrace(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + + logDebug(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + + logInfo(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + + logWarn(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + + logError(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + + logFatal(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + + log(logLevel: number, tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + } +} + +declare var OuralabsPlugin: OuralabsPlugin.OuralabsStatic \ No newline at end of file From ebfe028e66d3d8e895e70b2a356104895016ef4d Mon Sep 17 00:00:00 2001 From: Justin Unterreiner Date: Wed, 30 Sep 2015 17:17:48 -0700 Subject: [PATCH 2/2] Update for version 1.1.0 and added API docs --- .../cordova-plugin-ouralabs-tests.ts | 4 + .../cordova-plugin-ouralabs.d.ts | 104 +++++++++++++++++- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/cordova-plugin-ouralabs/cordova-plugin-ouralabs-tests.ts b/cordova-plugin-ouralabs/cordova-plugin-ouralabs-tests.ts index 5f26cb77e..eed76253c 100644 --- a/cordova-plugin-ouralabs/cordova-plugin-ouralabs-tests.ts +++ b/cordova-plugin-ouralabs/cordova-plugin-ouralabs-tests.ts @@ -19,6 +19,10 @@ OuralabsPlugin.setAttributes("a", "b", "c"); OuralabsPlugin.setAttributes("a", "b", "c", () => {}); OuralabsPlugin.setAttributes("a", "b", "c", () => {}, (error: string) => {}); +OuralabsPlugin.setLogToBrowserConsole(true); + +OuralabsPlugin.setHookBrowserConsole(true); + OuralabsPlugin.logTrace("a", "b"); OuralabsPlugin.logTrace("a", "b", { "whoa": "yep" }); OuralabsPlugin.logTrace("a", "b", { "whoa": "yep" }, () => {}); diff --git a/cordova-plugin-ouralabs/cordova-plugin-ouralabs.d.ts b/cordova-plugin-ouralabs/cordova-plugin-ouralabs.d.ts index d079ded7b..6596c7f0c 100644 --- a/cordova-plugin-ouralabs/cordova-plugin-ouralabs.d.ts +++ b/cordova-plugin-ouralabs/cordova-plugin-ouralabs.d.ts @@ -1,4 +1,4 @@ -// Type definitions for cordova-plugin-ouralabs 1.0.0 +// Type definitions for cordova-plugin-ouralabs 1.1.0 // Project: https://github.com/Justin-Credible/cordova-plugin-ouralabs // Definitions by: Justin Unterreiner // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -7,6 +7,10 @@ declare module OuralabsPlugin { interface OuralabsStatic { + /** + * Log levels designate the severity of the log; used with the log() function. + * Log levels are ordered from least severe to most severe. + */ LogLevel: { TRACE: number, DEBUG: number, @@ -16,24 +20,120 @@ declare module OuralabsPlugin { FATAL: number } + /** + * Initialize the Ourlabs plugin with the given channel ID string value. + * You can obtain your channel ID from the Ouralabs dashboard. + * + * @param channelId The ID of the channel that logs will be written to. + * @param successCallback The success callback for this asynchronous function. + * @param failureCallback The failure callback for this asynchronous function; receives an error string. + */ init(channelId: string, successCallback?: () => void, failureCallback?: (error: string) => void): void; + /** + * Used to ensure values logged via the plugin are also displayed in the browser's console. + * + * @param enable True to enable logs to show up in the browser's console, false to disable. + */ + setLogToBrowserConsole(enable: boolean): void; + + /** + * Used to enable hooking of the browser's console logging functions (eg console.log, + * console.error, etc) to ensure that these logs get logged via Ouralabs. + * + * @param enable True to enable hooking of the console log functions, false to disable. + */ + setHookBrowserConsole(enable: boolean): void; + + /** + * Allows setting of the three arbitrary attribute values that are stored with the device information. + * + * @param [string] attribute1 - The (optional) attribute value to set for the first attribute. + * @param [string] attribute2 - The (optional) attribute value to set for the first attribute. + * @param [string] attribute3 - The (optional) attribute value to set for the first attribute. + * @param [function] successCallback - The success callback for this asynchronous function. + * @param [function] failureCallback - The failure callback for this asynchronous function; receives an error string. + */ setAttributes(attribute1?: string, attribute2?: string, attribute3?: string, successCallback?: () => void, errorCallback?: (error: string) => void): void; + /** + * Logs a log message of level TRACE with the given information. + * + * @param tag The tag for the log entry. + * @param message The body of the log message. + * @param metadata An optional object to be appended to the log message in JSON format. If the object cannot be serialized into JSON it will be flattened into key/value pairs. + * @param successCallback The success callback for this asynchronous function. + * @param failureCallback The failure callback for this asynchronous function; receives an error string. + */ logTrace(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + /** + * Logs a log message of level DEBUG with the given information. + * + * @param tag The tag for the log entry. + * @param message The body of the log message. + * @param metadata An optional object to be appended to the log message in JSON format. If the object cannot be serialized into JSON it will be flattened into key/value pairs. + * @param successCallback The success callback for this asynchronous function. + * @param failureCallback The failure callback for this asynchronous function; receives an error string. + */ logDebug(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + /** + * Logs a log message of level INFO with the given information. + * + * @param tag The tag for the log entry. + * @param message The body of the log message. + * @param metadata An optional object to be appended to the log message in JSON format. If the object cannot be serialized into JSON it will be flattened into key/value pairs. + * @param successCallback The success callback for this asynchronous function. + * @param failureCallback The failure callback for this asynchronous function; receives an error string. + */ logInfo(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + /** + * Logs a log message of level WARN with the given information. + * + * @param tag The tag for the log entry. + * @param message The body of the log message. + * @param metadata An optional object to be appended to the log message in JSON format. If the object cannot be serialized into JSON it will be flattened into key/value pairs. + * @param successCallback The success callback for this asynchronous function. + * @param failureCallback The failure callback for this asynchronous function; receives an error string. + */ logWarn(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + /** + * Logs a log message of level ERROR with the given information. + * + * @param tag The tag for the log entry. + * @param message The body of the log message. + * @param metadata An optional object to be appended to the log message in JSON format. If the object cannot be serialized into JSON it will be flattened into key/value pairs. + * @param successCallback The success callback for this asynchronous function. + * @param failureCallback The failure callback for this asynchronous function; receives an error string. + */ logError(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + /** + * Logs a log message of level FATAL with the given information. + * + * @param tag The tag for the log entry. + * @param message The body of the log message. + * @param metadata An optional object to be appended to the log message in JSON format. If the object cannot be serialized into JSON it will be flattened into key/value pairs. + * @param successCallback The success callback for this asynchronous function. + * @param failureCallback The failure callback for this asynchronous function; receives an error string. + */ logFatal(tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; + /** + * Logs a message with the given information. + * + * @param logLevel The level of the log; see OuralabsPlugin.LogLevels for possible values. + * @param tag The tag for the log entry. + * @param message The body of the log message. + * @param metadata An optional object to be appended to the log message in JSON format. If the object cannot be serialized into JSON it will be flattened into key/value pairs. + * @param successCallback The success callback for this asynchronous function. + * @param failureCallback The failure callback for this asynchronous function; receives an error string. + */ log(logLevel: number, tag: string, message: string, metadata?: any, successCallback?: () => void, failureCallback?: (error: string) => void): void; } } -declare var OuralabsPlugin: OuralabsPlugin.OuralabsStatic \ No newline at end of file +declare var OuralabsPlugin: OuralabsPlugin.OuralabsStatic;