clix/publish_atom.lua

Fri, 17 Aug 2012 17:29:21 +0200

author
Kim Alvefur <zash@zash.se>
date
Fri, 17 Aug 2012 17:29:21 +0200
changeset 93
8ab81c304073
parent 72
0f69e1902f5b
child 94
6f038202a502
permissions
-rw-r--r--

clix.publish_atom: Don't load pubsub plugin ourself, instead pass to clix_connect

69
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local new_uuid = require "util.uuid".generate;
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local datetime = require "util.datetime".datetime;
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 return function (opts, arg)
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 if opts.short_help then
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 print("Publish an Atom entry to a pubsub node");
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 return;
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 end
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 --if (#arg == 0 or opts.help) then -- why?
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 if opts.help then
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 print("clix publish_atom \\");
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 print("","--service=pubsub.shakespeare.lit \\");
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 print("","--node=princely_musings \\");
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 print("","--id=123 \\");
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 print("","--author=Hamlet \\");
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 print("","--title=Soliloquy \\");
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 print("","--summary=\"To be, or not to be: that is the question\"");
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 return 0;
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 end
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local function on_connect(conn)
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 -- Required: id, title, updated, author (which must have a name)
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 local entry_id = opts.entry_id or ("clix-"..new_uuid());
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 local atom_entry = verse.stanza("entry", { xmlns="http://www.w3.org/2005/Atom" })
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 :tag("id"):text(entry_id):up(id)
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 :tag("title"):text(opts.title or ""):up()
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 :tag("updated"):text(opts.updated or datetime()):up();
72
0f69e1902f5b clix.publish_atom: Use the $USER environment variable as fallback for author.
Kim Alvefur <zash@zash.se>
parents: 71
diff changeset
27 atom_entry:tag("author"):tag("name"):text(opts.author or os.getenv("USER") or "Unknown author"):up();
69
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 atom_entry:up();
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 if opts.summary then
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 atom_entry:tag("summary"):text(opts.summary):up();
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 end
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 if opts.content then
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 atom_entry:tag("content"):text(opts.content):up();
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 end
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36
71
075ecfa46484 clix.publish_atom: Don't quit until the server responds to our publish request.
Kim Alvefur <zash@zash.se>
parents: 69
diff changeset
37 conn.pubsub(opts.service, opts.node):publish(entry_id, nil, atom_entry
075ecfa46484 clix.publish_atom: Don't quit until the server responds to our publish request.
Kim Alvefur <zash@zash.se>
parents: 69
diff changeset
38 , function(ok)
075ecfa46484 clix.publish_atom: Don't quit until the server responds to our publish request.
Kim Alvefur <zash@zash.se>
parents: 69
diff changeset
39 -- TODO Report success?
075ecfa46484 clix.publish_atom: Don't quit until the server responds to our publish request.
Kim Alvefur <zash@zash.se>
parents: 69
diff changeset
40 conn:close();
075ecfa46484 clix.publish_atom: Don't quit until the server responds to our publish request.
Kim Alvefur <zash@zash.se>
parents: 69
diff changeset
41 end);
69
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 --conn:send(verse.message({ to = opts.to, type = "chat" }) :body(text));
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 end
93
8ab81c304073 clix.publish_atom: Don't load pubsub plugin ourself, instead pass to clix_connect
Kim Alvefur <zash@zash.se>
parents: 72
diff changeset
45 clix_connect(opts, on_connect, {"pubsub"});
69
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 end

mercurial