view mod_atom/mod_atom.lua @ 3258:85e3117b2b60

mod_pubsub_github/README: Note that it might work with Gitlab as well Guess based on looking at this documentation: https://developer.github.com/v3/activity/events/types/#pushevent https://docs.gitlab.com/ee/system_hooks/system_hooks.html#push-events
author Kim Alvefur <zash@zash.se>
date Fri, 24 Aug 2018 16:28:48 +0200
parents 4b52cafd5811
children 119e22ccd64a
line wrap: on
line source

-- HTTP Access to PEP -> microblog
-- By Kim Alvefur <zash@zash.se>

local mod_pep = module:depends"pep";

local nodeprep = require "util.encodings".stringprep.nodeprep;
local st = require "util.stanza";

module:depends("http")
module:provides("http", {
	route = {
		["GET /*"] = function (event, user)
			local actor = event.request.ip;

			user = nodeprep(user);
			if not user then return 400; end

			local pubsub_service = mod_pep.get_pep_service(user);
			local ok, items = pubsub_service:get_items("urn:xmpp:microblog:0", actor);
			if ok then
				event.response.headers.content_type = "application/atom+xml";
				local feed = st.stanza("feed", { xmlns = "http://www.w3.org/2005/Atom" });
				for i = #items, 1, -1 do
					feed:add_direct_child(items[items[i]].tags[1]);
				end
				return tostring(feed);
			elseif items == "forbidden" then
				return 403;
			elseif items == "item-not-found" then
				return 404;
			end
		end;
	}
});