feed_parser/lib/parser.ex

23 lines
937 B
Elixir

defmodule FeedParser.Parser do
@moduledoc """
This behaviour defines the functions required to implement a feed parser.
"""
@doc """
Determines whether this Parser supports parsing a feed from the given data and MIME type.
If this parser can handle the data, it should return a tuple of `true` and the any object (usually the parsed form of the data). The returned object will then be passed to the `parse_feed` function.
Otherwise, it should return `false`.
"""
@callback accepts(data :: String.t(), content_type :: String.t()) ::
{true, parsed_data :: any()} | false
@doc """
Creates a `FeedParser.Feed` from the parsed data returned by the accepts function.
Returns either a tuple of `:ok` and the parsed Feed or `:error` and the reason for the error.
"""
@callback parse_feed(parsed_data :: any()) ::
{:ok, feed :: FeedParser.Feed.t()} | {:error, reason :: String.t()}
end