clix/publish_atom.lua

Fri, 17 Aug 2012 18:14:07 +0200

author
Kim Alvefur <zash@zash.se>
date
Fri, 17 Aug 2012 18:14:07 +0200
changeset 95
ea99e6653e18
parent 94
6f038202a502
child 96
a2214d821394
permissions
-rw-r--r--

clix.publish_atom: Fix --id option

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
94
6f038202a502 clix.publish_atom: Move xmlns into a variable
Kim Alvefur <zash@zash.se>
parents: 93
diff changeset
4 local xmlns_atom = "http://www.w3.org/2005/Atom";
6f038202a502 clix.publish_atom: Move xmlns into a variable
Kim Alvefur <zash@zash.se>
parents: 93
diff changeset
5
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
6 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
7 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
8 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
9 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
10 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
11 --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
12 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
13 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
14 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
15 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
16 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
17 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
18 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
19 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
20 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
21 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
22 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
23 -- Required: id, title, updated, author (which must have a name)
95
ea99e6653e18 clix.publish_atom: Fix --id option
Kim Alvefur <zash@zash.se>
parents: 94
diff changeset
24 local entry_id = opts.id or new_uuid();
94
6f038202a502 clix.publish_atom: Move xmlns into a variable
Kim Alvefur <zash@zash.se>
parents: 93
diff changeset
25 local atom_entry = verse.stanza("entry", { xmlns = xmlns_atom})
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
26 :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
27 :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
28 :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
29 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
30 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
31 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
32 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
33 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
34
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 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
36 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
37 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
38
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
39 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
40 , 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
41 -- 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
42 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
43 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
44
4b65a9a0229b clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 --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
46 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
47 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
48 end

mercurial