clix/publish_atom.lua

changeset 69
4b65a9a0229b
child 71
075ecfa46484
equal deleted inserted replaced
68:b7d92ed9c268 69:4b65a9a0229b
1 local new_uuid = require "util.uuid".generate;
2 local datetime = require "util.datetime".datetime;
3
4 return function (opts, arg)
5 if opts.short_help then
6 print("Publish an Atom entry to a pubsub node");
7 return;
8 end
9 --if (#arg == 0 or opts.help) then -- why?
10 if opts.help then
11 print("clix publish_atom \\");
12 print("","--service=pubsub.shakespeare.lit \\");
13 print("","--node=princely_musings \\");
14 print("","--id=123 \\");
15 print("","--author=Hamlet \\");
16 print("","--title=Soliloquy \\");
17 print("","--summary=\"To be, or not to be: that is the question\"");
18 return 0;
19 end
20 local function on_connect(conn)
21 conn:add_plugin"pubsub";
22 -- Required: id, title, updated, author (which must have a name)
23 local entry_id = opts.entry_id or ("clix-"..new_uuid());
24 local atom_entry = verse.stanza("entry", { xmlns="http://www.w3.org/2005/Atom" })
25 :tag("id"):text(entry_id):up(id)
26 :tag("title"):text(opts.title or ""):up()
27 :tag("updated"):text(opts.updated or datetime()):up();
28 atom_entry:tag("author"):tag("name"):text(opts.author or "Unknown author"):up();
29 atom_entry:up();
30 if opts.summary then
31 atom_entry:tag("summary"):text(opts.summary):up();
32 end
33
34 if opts.content then
35 atom_entry:tag("content"):text(opts.content):up();
36 end
37
38 conn.pubsub(opts.service, opts.node):publish(entry_id, nil, atom_entry);
39
40 --conn:send(verse.message({ to = opts.to, type = "chat" }) :body(text));
41 conn:close();
42 end
43 clix_connect(opts, on_connect);
44 end

mercurial