FeedAPI developers' guide

You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!
Aron Novak's picture
public
Aron Novak - Wed, 2007-07-25 11:51

The purpose of this wiki page is to provide help for developing for FeedAPI.

Documentation

Generated regularily from source code.
http://aggregation.novaak.net/documentation/

Concept

The FeedAPI provides a simple user interface for managing feeds and handles submodules.
There are two types of submodules:

  • Parsers
  • Processors

Life of a feed at FeedAPI:
Creating
1) Incoming URL from the user
2) Auto-detect a compatible parser ( feedapi_feed('compatible') ), the user has ability to adjust this auto-detection: per content-type there are presets to do this - this value is the order of probing: if all of the parsers is compatible with the feed, the lightest parser will be assigned as the primary parser, the others will be secondary parsers. The parser (if compatible) have to tell what is the type of the feed.
3) Auto-detect a compatible processor. The weight-system is the same for parsers.
4) Store the feed as a node. The nodeapi here offers various ways to involve for external modules.
Refreshing
Via cron or via direct user command for 1 feed
FeedAPI handles refreshing, the modules only have to implement the standard hooks (see below)
Deleting
Same for refreshing, standard hooks are used.

Writing a parser

Required hook feedapi_feed. Examples: example1, example2
Required operations ($op) parameter within the hook:

  • 'type'
  • 'parse'
  • 'compatible'

The parser is: able to detect if the URL has such a data that can be parsed, able to parse the data into the standard data structure (see above)

Writing a processor

Required hook: feedapi_item. Examples: example1
At this example the operations are in private "_foo" functions because of the complexity of each operation. To see what to do in the operations, check out these functions.
Required operations ($op) parameter within the hook:

  • 'type'
  • 'save'
  • 'update'
  • 'delete'
  • 'load'
  • 'unique'
  • 'fetch'
  • 'expire'

The item processor is: responsible to handle basic feed item operations, store, show the items.

Feed

Your module can involve in the feed mechanism fully with the nodeapi.

Storing add on module specific presets and settings


FeedAPI provides a settings_form hook that expects a FormsAPI-style associative array that describes the add on modules settings. The storage of per content type presets and per feed settings is handled entirely by FeedAPI.

See how this is implemented in the feedapi_node module (function feedapi_node_feedapi_settings_form($type) ).

Other possibilities of extension

There are important milestones in the feed's life, where any of the external modules can involve:

  • feedapi_after_refresh - it is called after the feed is refreshed. Use case: promote the node items.
  • feedapi_after_parse - it is called immediately after the parsers. Use case: http://drupal.org/node/160692
  • feedapi_after_settings - it is called after the FeedAPI internal settings handler finished its job. Use case: feedapi_aggregator fill category_feed table

With the help of these hooks, your module is able to react to these operations.