Twittex v0.2.0 Twittex.Aggregator behaviour

A behaviour module for implementing stream aggregators.

Example

To create a stream aggregator, create a new module and use Twittex.Aggregator as follow:

defmodule TagAggregator do
  use Twittex.Aggregator

  def map(stream) do
    stream
    |> Stream.flat_map(& &1["entities"]["hashtags"])
    |> Stream.map(& &1["text"])
  end

  def reduce(tag, acc) do
    Map.update(acc, tag, 1, & &1 + 1)
  end
end

And this is how you may use it:

iex> "#elixir-lang" |> TagAggregator.new |> TagAggregator.run

Summary

Types

accumulator :: %{}

Functions

new(aggregator, query, options \\ [])

Specs

new(module, String.t, Keyword.t) :: Stream.t

Returns a new stream of tags matching the given query.

See Twittex.Client.stream/2 for more detailed information.

next(aggregator, stream, duration \\ 1, duration_unit \\ :seconds)

Specs

next(module, Stream.t, Integer.t, System.time_unit) :: %{}

Returns the next batch of tweets from the stream.

run(aggregator, stream, print_fun \\ nil, sort_fun \\ nil, max \\ 10, frame_duration \\ 1, duration_unit \\ :seconds)

Specs

run(module, Stream.t, (any -> :ok), (any -> any), Integer.t, Integer.t, System.time_unit) :: :ok

Runs the given stream.

Callbacks

map(arg0)

Specs

map(Stream.t) :: Stream.t
reduce(any, accumulator)

Specs

reduce(any, accumulator) :: accumulator