Demoxi Widgets API Reference

Version 0.8.1.570
Copyright 2007-2008, Demoxi, Inc.

Table of Contents

Back to top

Getting Started

To get a quick start with Demoxi widgets, see the Demoxi Widgets Developer's Guide. It shows how to install the widget SDK and provides a detailed discussion of a fully functional Hello, World example widget.

Back to top

Using the Services

Demoxi widget services use the Representational State Transfer (REST) API style
(see http://en.wikipedia.org/wiki/Representational_State_Transfer).

Request Format

All server requests are requested presented to http://localhost:4073. These are typically GET requests
(although either GET or POST will work).
The URL should be of the form:
http://localhost:4073/Widget/[Command]/[Widget]?parameter1=value1&parameter2=value2 ....

Command is the name of a widget service like Open; Widget is a widget identifier
(either a widget handle or the widget bundle name without the DW ending); and parameter is a request parameter like skin.

For example, to open a widget the Hello, World widget, use http://localhost:4073/Widget/Open/Hello. And to close the Hello, World widget, use http://localhost:4073/Widget/Close/<TMPL_VAR handle>. For a description of the state variables that are served with each widget file, see State Variables.

Response Status Codes

Typical return status codes include the following:

Status CodeDescription
200 OKRequest processed successfully.
400 Bad Request The request could not be understood by the server due to malformed syntax.
401 UnauthorizedThe request requires user authentication.
500 Internal Server ErrorThe server encountered an unexpected condition which prevented it from fulfilling the request.

Return status codes do not cover all possible HTTP status codes that could be returned, but only those returned from the server. For example, if the request cannot reach the server, you will likely get a 503 Service Unavailable response. So, do not write your code just to handle just the documented response codes.

Response Data

JSON is used to return data from functions. JSON (JavaScript Object Notation) is a lightweight data format based on the object notation of the JavaScript language. It does not require JavaScript to read or write; it is easy to parse by any language; and libraries and tools exist in many languages to handle JSON. For a complete description of JSON and its many uses, we suggest Douglas Crockford's JSON.org (http://json.org) and JSON: The Fat-Free Alternative to XML (http://json.org/xml.html).

A typical JSON return data structure might look like this:

   jsonResult = '{ 
      "personal" : { 
         "language" : "eng" 
      } 
   }';

Accessing this JSON data structure from JavaScript is easy:

   result = eval ("(" + jsonResult + ")");
   alert (result.personal.language);

The jQuery getJSON function calls eval for you so you can access the data directly:

   $.getJSON (
      "http://localhost:4073/Widget/GetVaultAttribute/<TMPL_VAR handle>"
      ,{name: "personal.language"}
      ,function (result) {
         alert (result.personal.language);
      }
   );

Back to top

State Variables

Widgets use a template mechanism to inject state variables into widget files. To access these variables within your widget HTML or JavaScript files, use the <TMPL_VAR> prefix.

For example, to access the name of the current user via userName from an HTML widget file:

   <html>
      <body>
            Welcome <TMPL_VAR userName>!
      </body>
   </html>

The following state variables are available to all widgets:

State VariableDescription
apiServerThe demoxi.net webserver URL.
handleThe widget handle.
serverAuthThe demoxi.net server authorization handle for the currently signed-in user.
userNameThe currently signed-in user.

Back to top

Widget Services

The widget commands allow the manipulation of widget appearance programmatically. It should be noted that since a widget's appearance is largely defined by its skin(s), making significant alterations to the appearance (e.g. changing a widget's color) is handled by resetting its skin. As such, most of the remaining commands have to do with size and visibility.

Close

Closes the specified widget.

Request

http://localhost:4073/Widget/Close/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.

See also State Variables and Request Format.

Response

BeginDrag

Puts the widget into drag mode, locking its motion to the mouse until the mouse button is released.

Request

http://localhost:4073/Widget/BeginDrag/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.

See also State Variables and Request Format.

Response

EndDrag

Ends dragging that was begun with BeginDrag.

Request

http://localhost:4073/Widget/EndDrag/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.

See also State Variables and Request Format.

Response

Move

Repositions a widget.

Request

http://localhost:4073/Widget/Move/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
xYesThe x coordinate for the upper left corner of the widget. If unsigned, this coordinate is absolute. If signed (+ or -), it is relative to the previous coordinate.
yYesThe y coordinate for the upper left corner of the widget. If unsigned, this coordinate is absolute. If signed (+ or -), it is relative to the previous coordinate.

As an example, assume a Hello, World widget whose current upper left coordinate is (200, 200). Move(Hello, 300, 400) (or more properly, http://localhost:4073/Widget/Move/Hello/[handle]?x=300&y=400) would move the Hello, World widget to the absolute screen coordinates of (300,400). On the other hand, Move(300, +50) would move the widget to (300, 250). A positional arguments of 0 (zero) will always be interpreted as an offset to the current coordinate; Move(300, 0) would result in a widget at (300, 200).

See also State Variables and Request Format.

Response

Open

Opens the specified widget.

Request

http://localhost:4073/Widget/Open/[widget bundle]

ParameterRequiredDescription
widget bundleYesThe name of a widget bundle without the .dw ending.
skinNoThe skin, if specified, must be present in the widget's manifest. If it is not, or if the argument is omitted, then the default skin listed in the widget manifest will be used to render the widget.

See also State Variables and Request Format.

Response

GetProperties

Gets widget properties.

Request

http://localhost:4073/Widget/GetProperties/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
namesYesThe property names.
sectionNoA section within the properties area.

See also State Variables and Request Format.

Sample Request

http://localhost:4073/Widget/GetProperties/12345678?section=defaults&property1&property2

Response

ParameterDescription
valuesThe property values.

If there is no existing value or name does not exist, then null will be returned.

See also Response Status Codes and Response Data.

Sample Response

   {
     "property1" : "true",
     "property2" : "shazzam"
   }

SetProperties

Sets widget properties.

Request

http://localhost:4073/Widget/SetProperties/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
name/value pairsYesThe property names and values.
sectionNoA section within the properties area.

See also State Variables and Request Format.

Sample Request

http://localhost:4073/Widget/SetProperties/12345678?section=defaults&property1=true&property2=shazzam

Response

Resize

Changes the height and width of a widget. (coming soon)

Switches the widget to a different skin, or with a variable-sized skin, resizes the current skin. This command may be invoked with either a skin argument, or width and height arguments. With a skin argument, the skin (i.e., mask) of the widget is replaced, and the window is changed to the new shape. With width and height arguments, the widget shape is transformed according to the description in the widget manifest, and the window is changed to the new shape.

Note that the content of the widget is unchanged, so it is up to you to make the widget look correct in its new skin.

Widgets also may have multiple skins, each describing a different size (e.g. small, medium, and large). If you want to resize the widget to one of these predefined sizes, you should use the SetSkin command instead.

Finally, note that a skin can have an arbitrary shape, as defined by its skin's mask. This command alters the height and width of the widget, so changing the width of a circular widget would result in an ellipse.

Request

http://localhost:4073/Widget/Resize/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
skinNoThe new skin, if specified, must be present in the widget's manifest.
widthNoThe new widget width.
heightNoThe new widget height.

See also State Variables and Request Format.

Response

Show

Shows or hides the widget.

Request

http://localhost:4073/Widget/Show/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
showYes1 to show the widget; 0 to hide it.

See also State Variables and Request Format.

Response

SetSkin

Changes the widget skin. (coming soon)

Request

http://localhost:4073/Widget/SetSkin/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
skinNoThe new skin, if specified, must be present in the widget's manifest.

See also State Variables and Request Format.

Response

PlaySound

Plays a sound file stored in the widget bundle.

Request

http://localhost:4073/Widget/PlaySound/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
soundYesThe name of the sound file stored in the widget bundle.

Currently the only supported sound file format is WAV. Support for additional formats may be added in the future.

See also State Variables and Request Format.

Response

SetTitle

Sets the window title for the widget.

All widgets should have a title, even if it is not displayed in the widget window. This allows the title to be shown in other useful places; for example, the title would be shown when a Windows user is Alt-Tabbing through a series of windows.

Request

http://localhost:4073/Widget/SetTitle/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
titleNoA short string defining the title of the widget.

The length of title is limited to 255 characters, but having so long a title is highly inadvisable from a UI point of view; short strings are the most appropriate. UTF-8 is supported, so titles in non-Roman character sets are OK.

See also State Variables and Request Format.

Response

GetVersion

Gets the Demoxi platform version.

Request

http://localhost:4073/Widget/GetVersion/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.

See also State Variables and Request Format.

Sample Request

http://localhost:4073/Widget/GetVersion/12345678

Response

ParameterDescription
majorMajor version number.
minorMinor version number.
revisionRevision number.
buildBuild number.

See also Response Status Codes and Response Data.

Sample Response

   {
     "major" : 0,
     "minor" : 8,
     "revision" : 1,
     "build" : 555,
   }

Back to top

Identity Services

The identity commands allow the access to the user's identity information.

GetVaultAttributes

Returns the value of public attributes in the user's identity vault.

Request

http://localhost:4073/Widget/GetVaultAttributes/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
vaultNoThe specific vault within the set user's identity vaults. Defaults to wallet.
namesYesThe attribute names in category.name format.

See also State Variables and Request Format.

Sample Request

http://localhost:4073/Widget/GetVaultAttributes/12345678?personal.yob&personal.language&personal.
gender&address.co&address.postcode

Response

FieldDescription
valuesThe attribute values.
Error CodeDescription
401 UnauthorizedThe request requires user authentication.
403 ForbiddenThe user has refused access to the attribute.

If there is no existing value or name does not exist, then null will be returned.

If a requested value is not public, then the call will fail. Error code 401 means you should wait and retry as the user may be asked to confirm that your widget should be allowed to access the attribute. Error code 403 means the user has refused access to the attribute.

See also Response Status Codes and Response Data.

Sample Response

   {
      "personal" : {
         "yob" : "1963",
         "language" : "English",
         "gender" : "M"
      },
      "address" : {
         "co" : "United States",
         "postcode" : "98004"
      }
   }

SetVaultAttributes

Sets the value of public attributes in the user's identity vault.

Request

http://localhost:4073/Widget/SetVaultAttributes/[widget handle]

ParameterRequiredDescription
widget handleYesThe widget handle.
vaultNoThe specific vault within the set user's identity vaults. Defaults to wallet.
name/value pairsYesThe attribute names and values.

See also State Variables and Request Format.

Sample Request

http://localhost:4073/Widget/SetVaultAttributes/12345678?personal.language=French&personal.yob=1992&address.
co= United States&personal.gender=M&address.postcode=98001

Response

Error CodeDescription
401 UnauthorizedThe request requires user authentication.
403 ForbiddenThe user has refused access to the attribute.

If a requested value is not public, then the call will fail. Error code 401 means you should wait and retry as the user may be asked to confirm that your widget should be allowed to access the attribute. Error code 403 means the user has refused access to the attribute.

See also Response Status Codes.

Back to top