RssWatcher v0.1.0 RssWatcher View Source
A small worker that watches a single RSS feed, parses the changes, and dispatches updates.
Installation
Dependencies
Add the following to your dependencies:
{:rss_watcher, "~> 0.1.0"}
For easy mode, you can use the default adapters to fetch and parse RSS feeds. Just add the following to your dependancies, and you should be good to go.
{:tesla, "~> 1.2.1"}, # For HTTP requests
{:fiet, "~> 0.2.1"}, # For RSS parsing
{:timex, "~> 3.0"}, # For timestamp parsing
And add Timex to your list of applications.
extra_applications: [ ..., :timex]
Adapters
RssWatcher.HTTP.Tesla is provided by default. To use, add the following
dependancies to your dependency list. See module configuration around middleware, and additional
adapter options.
{:tesla, "~> 1.2.1"}
For RSS parsing, RssWatcher.Feed.Fiet is provided by default,
and handles parsing XML and timestamps. To use, add the following dependencies
to your dependency list.
{:fiet, "~> 0.2.1"},
{:timex, "~> 3.0"}
And add timex to your list of applications.
extra_applications: [ ... :timex]
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
RssWatcher is a worker, so the recommended usage is to add it as a child to your supervisor.
Link to this section Types
callback() View Source
options()
View Source
options() :: [{:refresh_interval, integer()}]
options() :: [{:refresh_interval, integer()}]
url()
View Source
url() :: String.t()
url() :: String.t()
Link to this section Functions
child_spec(init_arg) View Source
Returns a specification to start this module under a supervisor.
See Supervisor.
start_link(options) View Source (since 0.1.0)
RssWatcher is a worker, so the recommended usage is to add it as a child to your supervisor.
API Example
children = [
{RssWatcher,
url: "http://example.com/rss",
callback: {Notifications, broadcast, ["#channel_id"]}
}
]
Supervisor.start_link(children, strategy: :one_for_one))
Or, with a dynamic supervisor:
children = [
{DynamicSupervisor, strategy: :one_for_one, name: MyApp.RssSupervisor}
]
Supervisor.start_link(children, strategy: :one_for_one)
...
DynamicSupervisor.start_child(
MyApp.RssSupervisor,
{
RssWatcher,
url: "http://example.com/rss",
callback: {Notifications, broadcast, ["#channel_id"]}
}
)
Each RssWatcher worker requires at least a url, and a callback. Additional
configuration can be provided to use alternate adapters.
Url (required)
The url should be a string, which resolves to an RSS feed.
Callback (required)
The callback can be in the form of {module, function, arguments}, or
an anonymous/suspended function.
If {module, function, arguments} format, the callback will be dispatched with
an additional argument - the parsed XML. Otherwise, the parsed XML will be
the only argument provided. See below for examples.
Additional Configuration
The configuration is provided as a keyword list. The available options (and their defaults) are listed below
:refresh_interval- integer. How often the feed is checked, in seconds. Defautls to60.:rss_parser- Atom/RSS 2.0 parser module. Defaults toRssWatcher.Feed.Fiet,:rss_parser_options- options for the above parser. Defaults to[],:http_client- HTTP client for fetching updates. Defaults toRssWatcher.HTTP.Tesla,:http_client_options- options for the above client. Default to[]. See adapter module for configuration options.
Examples
{RssWatcher,
url: "http://example.com/rss",
callback: {Notifications, broadcast, ["#channel_id"]},
refresh_interval: 60
}
{RssWatcher,
url: "http://example.com/rss",
callback: fn xml -> Notifications.broadcast(xml) end,
refresh_interval: 60
}
{RssWatcher,
url: "http://example.com/rss",
callback: &Notifications.broadcast/1,
refresh_interval: 60
}