Changeset

69:4b65a9a0229b

clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
author Kim Alvefur <zash@zash.se>
date Sun, 12 Feb 2012 02:22:58 +0100
parents 68:b7d92ed9c268
children 70:5e93cfc73444
files clix/publish_atom.lua
diffstat 1 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clix/publish_atom.lua	Sun Feb 12 02:22:58 2012 +0100
@@ -0,0 +1,44 @@
+local new_uuid = require "util.uuid".generate;
+local datetime = require "util.datetime".datetime;
+
+return function (opts, arg)
+	if opts.short_help then
+		print("Publish an Atom entry to a pubsub node");
+		return;
+	end
+	--if (#arg == 0 or opts.help) then -- why?
+	if opts.help then
+		print("clix publish_atom \\");
+		print("","--service=pubsub.shakespeare.lit \\");
+		print("","--node=princely_musings \\");
+		print("","--id=123 \\");
+		print("","--author=Hamlet \\");
+		print("","--title=Soliloquy \\");
+		print("","--summary=\"To be, or not to be: that is the question\"");
+		return 0;
+	end
+	local function on_connect(conn)
+		conn:add_plugin"pubsub";
+		-- Required: id, title, updated, author (which must have a name)
+		local entry_id = opts.entry_id or ("clix-"..new_uuid());
+		local atom_entry = verse.stanza("entry", { xmlns="http://www.w3.org/2005/Atom" })
+			:tag("id"):text(entry_id):up(id)
+			:tag("title"):text(opts.title or ""):up()
+			:tag("updated"):text(opts.updated or datetime()):up();
+		atom_entry:tag("author"):tag("name"):text(opts.author or "Unknown author"):up();
+		atom_entry:up();
+		if opts.summary then
+			atom_entry:tag("summary"):text(opts.summary):up();
+		end
+
+		if opts.content then
+			atom_entry:tag("content"):text(opts.content):up();
+		end
+
+		conn.pubsub(opts.service, opts.node):publish(entry_id, nil, atom_entry);
+
+		--conn:send(verse.message({ to = opts.to, type = "chat" }) :body(text));
+		conn:close();
+	end
+	clix_connect(opts, on_connect);
+end