feeder
1.0.0RSS, Atom and general feed parsing and generating
About Feeder
Feeder is a syndication feed library. It presents a general protocol for representation of feed items, as well as a framework to translate these objects from and to external formats. It also implements the RSS 2.0 and Atom formats within this framework.
Translating Feeds
During this document code examples will assume that org.shirakumo.feeder
has the local nickname feeder
.
In order to parse a feed, simply call parse-feed
:
(feeder:parse-feed "<rss><channel><title>Test</title><description>test</description><guid>1</guid><link>http://example.com</link>" T)
It should determine the format used automatically and construct standardised feed
instances out of the source. In order to reverse the process and turn a feed
into an external format again, simply call serialize-feed
:
(feeder:serialize-feed (first *) 'feeder:atom)
Note that while parsing is very lenient, serialising is not, and it will error if certain attributes are missing or malformed. You therefore cannot always round-trip feeds like this.
For xml-format
s, the resulting value of serialize-feed
will be a plump:node
that can be turned into a string with plump:serialize
:
(plump:serialize * NIL)
Generating Feeds
In order to generate feeds, you need to translate whatever internal representation of your items you have into entry
instances, and then bundle them together into a feed
instance. Both feed
and entry
instances require in the very least an :id
, :link
, :title
, and :summary
. The :id
can be whatever you want it to be, but it should be an ID that uniquely identifies your item for all time, preferably even globally so. If the link to your item can be used as a unique identifier, you can supply the same link
instance to :id
and :link
. The :summary
can either be a string of plain text content, or a plump:node
for HTML content.
You should also strongly consider filling in the :authors
and :published-on
fields, as well as the :content
field on entry
instances. For the :content
, you may supply either plain text or HTML, just as for the :summary
.
In order to bundle the entry
instances into the feed
, simply put them into a list and set that as the feed
's :content
.
When generating and feed objects and serialising them, the system will check for validity of elements to some limited extent. For instance, required slots that are missing will be reported with errors. Generally whenever an error is signalled, plenty of restarts will be available to help deal with the problem both interactively and in an automated fashion.
Please see the descriptions of feed-condition
's subtypes for more information on the error circumstances and possible restarts.
Extending Feeds and Formats
If you need to extend the feed objects or add new feed formats, the functions you should look at are parse-to
and serialize-to
. In both cases you should add methods to them that specialise on all three arguments, at least one of which must be on a class you control.
Assuming for instance you define an extended person
that has an additional location
field. Ensuring this field is output into the atom
format, you would do something like this:
(defclass extended-person (feeder:person)
((location :initarg :location :initform NIL :accessor location)))
(defmethod feeder:serialize-to ((target plump:element) (person extended-person) (format feeder:atom))
(call-next-method)
(when (location person)
(feeder:make-element target :location - (location person))))
When parsing we need to substitute our new class for the instance to use when creating person
s. To do so, we require a new format
subclass, and a method on instance-for-type
:
(defclass extended-format (feeder:atom)
())
(defmethod feeder:instance-for-type ((type (eql 'person)) (format extended-format))
(feeder:instance-for-type 'extended-person format))
Finally we can read out the field in a parse-to
method:
(defmethod feeder:parse-to ((person extended-person) (node plump:element) (format extended-format))
(call-next-method)
(feeder:with-child (child node :location)
(setf (location person) (feeder:text child))))
Naturally, it is also possible to define entirely new formats that don't necessarily serialise to XML.
System Information
Definition Index
-
ORG.SHIRAKUMO.FEEDER
No documentation provided.-
EXTERNAL CLASS ATOM
Atom Feed Format As defined in RFC4287 https://tools.ietf.org/html/rfc4287 . As opposed to RSS, Atom is rather strict, and as such parsing of the feed data does not attempt to guess either. However, just as with RSS, parsing a feed should not signal an error. See XML-FORMAT
-
EXTERNAL CLASS AUTHORED-ITEM
Representation of a basic feed item. This is used as the base class for FEEDs and ENTRYs in a feed. See REMOTE-ITEM See ID See CATEGORIES See AUTHORS See CONTRIBUTORS See PUBLISHED-ON See UPDATED-ON See RIGHTS See LANGUAGE See LINK See TITLE See SUMMARY See CONTENT
-
EXTERNAL CLASS ENTRY
Representation of a feed item. See AUTHORED-ITEM See COMMENT-SECTION See SOURCE
-
EXTERNAL CLASS FEED
Representation of a syndication feed. See AUTHORED-ITEM See CACHE-TIME See GENERATOR See LOGO See WEBMASTER
-
EXTERNAL CLASS FORMAT
Base class for an external format for a feed. See SOURCE-HAS-FORMAT-P See PARSE-FEED See SERIALIZE-FEED See PARSE-TO See SERIALIZE-TO
-
EXTERNAL CLASS GENERATOR
Representation of a feed generator. See REMOTE-ITEM See NAME See VERSION
-
EXTERNAL CLASS LINK
Representation of a link to an external resource. See URL See RELATION See CONTENT-TYPE See LANGUAGE See TITLE
-
EXTERNAL CLASS PERSON
Representation of a person. See REMOTE-ITEM See NAME See EMAIL
-
EXTERNAL CLASS REMOTE-ITEM
-
EXTERNAL CLASS RSS
RSS 2.0 Feed Format As defined in https://validator.w3.org/feed/docs/rss2.html with select extensions such as content:encoded. RSS is a very "web" format, which is to say that the files claiming to be RSS that can be found out there all do not adhere to any strict specifications, or anything at all for that matter. This makes parsing and dealing with RSS a pain in the ass. This parser performs a best-effort at parsing the content you hand it, and attempts to standardise and culminate certain features together as appropriate. It should not error when parsing a feed, but may miss or misinterpret certain values present in the raw feed data. For instance, of duplicated tags that should only exist once, only the last tag is actually preserved in the generated objects. Serialising to RSS will follow the description as closely as possible without touching undefined parts. See XML-FORMAT
-
EXTERNAL CLASS XML-FORMAT
Base class for formats based on XML. See FORMAT
-
EXTERNAL CONDITION ARGUMENT-MISSING
Error signalled when a required argument is missing. This usually happens when you try to create an instance of an object but omitted an argument that is required to create a valid feed. When this condition is signalled, the following restarts are available - USE-VALUE Requires an argument that is then used for the missing argument. - CONTINUE Set the slot to NIL anyway. See FEED-CONDITION
-
EXTERNAL CONDITION FEED-CONDITION
Base condition for all feed related conditions. See ARGUMENT-MISSING See NIL-VALUE See UNKNOWN-FORMAT See UNKNOWN-ATOM-CONTENT-TYPE
-
EXTERNAL CONDITION NIL-VALUE
Error signalled when a form returns NIL that should not be NIL. This usually happens during feed serialisation when a slot is empty that is required to generate a valid feed. When this condition is signalled, the following restarts are available - USE-VALUE Requires an argument that is then returned in place of the NIL. See FEED-CONDITION
-
EXTERNAL CONDITION UNKNOWN-ATOM-CONTENT-TYPE
Error signalled on an unknown content type. When this condition is signalled, the following restarts are available - USE-TYPE Requires an argument that specifies the alternate content-type to use. - USE-VALUE Requires an argument that specifies the content to use in its place. - TREAT-AS-PLAINTEXT Treats the content as plaintext and returns it. - CONTINUE Ignores the content and returns NIL See FEED-CONDITION See ATOM
-
EXTERNAL CONDITION UNKNOWN-FORMAT
Error signalled when the given feed source has an unknown format. When this condition is signalled, the following restarts are available - USE-VALUE Requires an argument that designates the format to use. See FEED-CONDITION See PARSE-FEED
-
EXTERNAL FUNCTION CONTINUE
- &OPTIONAL
- CONDITION
Transfer control to a restart named CONTINUE, or return NIL if none exists.
-
EXTERNAL FUNCTION TEXT
- ENTITY
Returns the trimmed text contents of the given node. This is like PLUMP:TEXT, but with ASCII whitespace trimmed off the front and end of the text. See PLUMP:TEXT
-
EXTERNAL FUNCTION USE-VALUE
- VALUE
- &OPTIONAL
- CONDITION
Transfer control and VALUE to a restart named USE-VALUE, or return NIL if none exists.
-
EXTERNAL GENERIC-FUNCTION AUTHORS
- OBJECT
Accessor to the list of persons that authored the item. See PERSON See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF AUTHORS)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION CACHE-TIME
- OBJECT
Accessor to the amount of time the feed can be cached. This value should be an integer representing the cache time in minutes. See FEED
-
EXTERNAL GENERIC-FUNCTION (SETF CACHE-TIME)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION CATEGORIES
- OBJECT
Accessor to the list of categories that the item relates to. Each category should be a simple string. See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF CATEGORIES)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION COMMENT-SECTION
- OBJECT
Accessor to the link for a comment section for this item. Should be a LINK or URL. See LINK (type) See ENTRY
-
EXTERNAL GENERIC-FUNCTION (SETF COMMENT-SECTION)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION CONTENT
- OBJECT
Accessor to the content of the item. For FEEDs, the content should be a list of ENTRYs. For ENTRYs this may be a plaintext string or a PLUMP:NODE. See FEED See ENTRY See PLUMP:NODE See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF CONTENT)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION CONTENT-TYPE
- OBJECT
Accessor to the content mime-type at the end of the link. See LINK (type)
-
EXTERNAL GENERIC-FUNCTION (SETF CONTENT-TYPE)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION CONTRIBUTORS
- OBJECT
Accessor to the list of persons that contributed to the item. See PERSON See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF CONTRIBUTORS)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION EMAIL
- OBJECT
Accessor to the email address of the person. No address validation is performed. See PERSON
-
EXTERNAL GENERIC-FUNCTION (SETF EMAIL)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION GENERATOR
- OBJECT
Accessor to the generator that created this feed. See GENERATOR (type) See FEED
-
EXTERNAL GENERIC-FUNCTION (SETF GENERATOR)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION ID
- OBJECT
Accessor to the unique ID of the item. This should either be a value that can be PRINCed to obtain a string representation of the unique identifier, or a LINK. See LINK (type) See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF ID)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION INSTANCE-FOR-TYPE
- TYPE
- FORMAT
Returns an appropriate instance for the requested type under the specified format. By default this constructs an empty (all slots set to NIL) instance using the given type as a class name. See FORMAT
-
EXTERNAL GENERIC-FUNCTION LANGUAGE
- OBJECT
Accessor to the language of the item This should be a two or three letter code name of the language in which the item's content is written, though no validation to this effect is performed. See LINK (type) See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF LANGUAGE)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION LINK
- OBJECT
Accessor to the link of the item. See LINK (type) See REMOTE-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF LINK)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION LOGO
- OBJECT
Accessor to the logo for the feed This should be a LINK See FEED
-
EXTERNAL GENERIC-FUNCTION (SETF LOGO)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION NAME
- OBJECT
Accessor to the name of the item. See PERSON See GENERATOR (type)
-
EXTERNAL GENERIC-FUNCTION (SETF NAME)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION PARSE-FEED
- SOURCE
- FORMAT
Parses the given source into standardised feed objects according to the specified format. If FORMAT is T, the format is determined automatically depending on the source's contents. Returns a list of FEED instances. This function should construct the appropriate base object and then call PARSE-TO. See FEED See FORMAT
-
EXTERNAL GENERIC-FUNCTION PARSE-TO
- TARGET
- THING
- FORMAT
Fills the target with content from thing according to format. This is used internally in the parsing process. See FORMAT
-
EXTERNAL GENERIC-FUNCTION PUBLISHED-ON
- OBJECT
Accessor to the date on which this item was first published. The date should be a LOCAL-TIME:TIMESTAMP See LOCAL-TIME:TIMESTAMP See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF PUBLISHED-ON)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION RELATION
- OBJECT
Accessor to the relation of the link. The following values are typically recognised: - "alternate" - "related" - "self" - "enclosure" - "via" See RFC4287 for more information. See LINK (type)
-
EXTERNAL GENERIC-FUNCTION (SETF RELATION)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION RIGHTS
- OBJECT
Accessor to copyright information relating to the item. This may be a plaintext string or a PLUMP:NODE See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF RIGHTS)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION SERIALIZE-FEED
- FEED
- FORMAT
Turns the given feed into the specified format. Returns the encoded feed. For XML-FORMATs this will be a PLUMP:NODE This function should construct the appropriate base object and then call SERIALIZE-TO. See PLUMP:NODE See XML-FORMAT See FORMAT
-
EXTERNAL GENERIC-FUNCTION SERIALIZE-TO
- TARGET
- THING
- FORMAT
Fills the target with content from thing according to format. This is used internally in the serialisation process. See FORMAT
-
EXTERNAL GENERIC-FUNCTION SOURCE
- OBJECT
Accessor to the source of this item. This is used if the entry is aggregated from elsewhere. Should be a LINK. See LINK (type) See ENTRY
-
EXTERNAL GENERIC-FUNCTION (SETF SOURCE)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION SOURCE-HAS-FORMAT-P
- SOURCE
- FORMAT
Returns T if the given source is encoded in the given format See FORMAT
-
EXTERNAL GENERIC-FUNCTION SUMMARY
- OBJECT
Accessor to the summary describing the item in short. This may be a plaintext string or a PLUMP:NODE In absence of a CONTENT value, it may also represent the full content. See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF SUMMARY)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION TITLE
- OBJECT
Accessor to the title of the item This may be a plaintext string or a PLUMP:NODE See LINK (type) See AUTHORED-ITEM See PLUMP:NODE
-
EXTERNAL GENERIC-FUNCTION (SETF TITLE)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION UPDATED-ON
- OBJECT
Accessor to the date on which this item was last updated. The date should be a LOCAL-TIME:TIMESTAMP See LOCAL-TIME:TIMESTAMP See AUTHORED-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF UPDATED-ON)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION URL
- ITEM
Accessor to the URL of a link or remote item. The URL should be encoded as a string, and no URL validation is performed. See LINK (type) See REMOTE-ITEM
-
EXTERNAL GENERIC-FUNCTION (SETF URL)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION VERSION
- OBJECT
Accessor to the generator version. See GENERATOR (type)
-
EXTERNAL GENERIC-FUNCTION (SETF VERSION)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION WEBMASTER
- OBJECT
Accessor to the webmaster responsible for this feed. This should be a PERSON See FEED
-
EXTERNAL GENERIC-FUNCTION (SETF WEBMASTER)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL MACRO MAKE-ELEMENT
- PARENT
- TAG-NAME
- &BODY
- ATTRIBUTES
Construct a new XML element. ATTRIBUTES should be a plist of alternating keys and values. A key may either be a string or a symbol. If a symbol, it is treated as the attribute name in lowercase. The attribute is only set if the value is non-NIL. If the key is a symbol with the name "-", the value is used as the text content of the element. For example, constructing an element like <foo bar="baz">bam</foo> would be (make-element parent "foo" :bar "baz" - "bam") See PLUMP:MAKE-ELEMENT See PLUMP:ATTRIBUTE See PLUMP:MAKE-TEXT-NODE
-
EXTERNAL MACRO WITH-CHILDREN
- NAME
- ROOT
- &BODY
- CLAUSES
Scans through the immediate children of ROOT and executes bodies as matching. The format should be as follows: CLAUSES ::= (TAG . form*)* TAG --- A string designator The forms of a clause are executed with NAME bound to a PLUMP:ELEMENT whose tag-name matches that specified in the clause. Tag names are matched case-insensitively. See PLUMP:CHILDREN See PLUMP:TAG-NAME See PLUMP:ELEMENT
-