Skip to content
Jason Dentler edited this page Jul 20, 2011 · 2 revisions

Topic

getId() returns the string id of the topic.

Name is a string field for the name of the topic.

Description is a string field for the topic description.

Delete() sends a request to delete the topic and returns a promise.

	topic.Delete()
	.done(function () {
		console.log('Just making sure the delete request worked.');
	})
	.fail(function (xhr, status, ex) {
		console.log('The delete request failed.');
	});

SaveChanges() updates the server with changes made to the Name and Description fields.

	topic.Name = 'New topic name';
	topic.Description = 'New topic description';
	topic.SaveChanged()
	.done(function () {
		console.log('Making sure the update request worked.');
	})
	.fail(function (xhr, status, ex) {
		console.log('The update failed.');
	});

getLinks() returns a hashmap of links for this topic. The ref attribute is used as the key. This is provided in case the Hermes REST service has been extended to return additional links. It is not typically used.

PostMessage(data, contentType) posts a message to the Hermes REST service and returns a promise. data should be a string or some other type readily understood by the jQuery ajax method. contentType is the Content-Type header to be used for this message.

	topic.PostMessage('{"Name":"John Smith", "Username":"jsmith1"}', 'application/json')
	.done(function (location) {
		console.log('Message url: ' + location);
	})
	.fail(function (xhr, status, ex) {
		console.log('Failed to post message.');
	});

PostStringMessage(message) posts a message to the Hermes REST service with a Content-Type of text/plain. PostStringMessage returns a promise.

	topic.PostStringMessage('Knock. Knock')
	.done(function (location) {
		console.log('Message url: ' + location);
	})
	.fail(function (xhr, status, ex) {
		console.log('Failed to post message.');
	});

GetAllMessages() returns a Reactive Extensions observable. This observable contains all the messages for this topic, but will not subscribe to new messages.

	topic.GetAllMessages()
		.Subscribe(function (message) {
			console.log('Topic contains message: ' + message);
		});

PollFeed(interval) returns a Reactive Extensions observable. The topic will be polled for new messages every {interval} milliseconds.

	topic.PollFeed(500)
		.Subscribe(function (message) {
			$("<li />").text(message).appendTo("#messages");
		});