Wed, 20 Aug 2014 12:05:46 +0200
new sendfilecontent plugin
- todo: add full or relative path possibility. not only current path
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"; |
97
83cd777fb294
clix.publish_atom: Add a way to attach Activitystrea.ms metadata to the entry
Kim Alvefur <zash@zash.se>
parents:
96
diff
changeset
|
5 | local xmlns_activitystreams = "http://activitystrea.ms/spec/1.0/"; |
83cd777fb294
clix.publish_atom: Add a way to attach Activitystrea.ms metadata to the entry
Kim Alvefur <zash@zash.se>
parents:
96
diff
changeset
|
6 | local activitystreams_schema_base = "http://activitystrea.ms/schema/1.0/"; |
94
6f038202a502
clix.publish_atom: Move xmlns into a variable
Kim Alvefur <zash@zash.se>
parents:
93
diff
changeset
|
7 | |
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
|
8 | 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
|
9 | 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
|
10 | 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
|
11 | 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
|
12 | 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
|
13 | --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
|
14 | 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
|
15 | 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
|
16 | 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
|
17 | 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
|
18 | 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
|
19 | 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
|
20 | 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
|
21 | 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
|
22 | 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
|
23 | 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
|
24 | 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
|
25 | -- 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
|
26 | 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
|
27 | 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
|
28 | :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
|
29 | :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
|
30 | :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
|
31 | 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
|
32 | atom_entry:up(); |
96
a2214d821394
clix.publish_atom: Attach a <source/> element
Kim Alvefur <zash@zash.se>
parents:
95
diff
changeset
|
33 | atom_entry:tag("source") |
a2214d821394
clix.publish_atom: Attach a <source/> element
Kim Alvefur <zash@zash.se>
parents:
95
diff
changeset
|
34 | :tag("id"):text(opts.node):up() |
a2214d821394
clix.publish_atom: Attach a <source/> element
Kim Alvefur <zash@zash.se>
parents:
95
diff
changeset
|
35 | :tag("link", { rel = "self", href = opts.node }):up() |
a2214d821394
clix.publish_atom: Attach a <source/> element
Kim Alvefur <zash@zash.se>
parents:
95
diff
changeset
|
36 | :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
|
37 | 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
|
38 | 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
|
39 | 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
|
40 | |
4b65a9a0229b
clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 | 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
|
42 | 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
|
43 | 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
|
44 | |
97
83cd777fb294
clix.publish_atom: Add a way to attach Activitystrea.ms metadata to the entry
Kim Alvefur <zash@zash.se>
parents:
96
diff
changeset
|
45 | for opt, optval in pairs(opts) do |
83cd777fb294
clix.publish_atom: Add a way to attach Activitystrea.ms metadata to the entry
Kim Alvefur <zash@zash.se>
parents:
96
diff
changeset
|
46 | if opt:match"^as_" then |
83cd777fb294
clix.publish_atom: Add a way to attach Activitystrea.ms metadata to the entry
Kim Alvefur <zash@zash.se>
parents:
96
diff
changeset
|
47 | atom_entry:tag(opt:sub(4):gsub("_", "-"), { xmlns = xmlns_activitystreams } ) |
83cd777fb294
clix.publish_atom: Add a way to attach Activitystrea.ms metadata to the entry
Kim Alvefur <zash@zash.se>
parents:
96
diff
changeset
|
48 | :text(activitystreams_schema_base..optval):up(); |
83cd777fb294
clix.publish_atom: Add a way to attach Activitystrea.ms metadata to the entry
Kim Alvefur <zash@zash.se>
parents:
96
diff
changeset
|
49 | end |
83cd777fb294
clix.publish_atom: Add a way to attach Activitystrea.ms metadata to the entry
Kim Alvefur <zash@zash.se>
parents:
96
diff
changeset
|
50 | end |
83cd777fb294
clix.publish_atom: Add a way to attach Activitystrea.ms metadata to the entry
Kim Alvefur <zash@zash.se>
parents:
96
diff
changeset
|
51 | |
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
|
52 | 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
|
53 | , 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
|
54 | -- 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
|
55 | 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
|
56 | 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
|
57 | |
4b65a9a0229b
clix.publish_atom: Publish Atom entries into PubSub nodes. (Thanks MattJ for the unfinished code)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 | --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
|
59 | 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
|
60 | 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
|
61 | end |