Streamex v0.3.0 Streamex.Activities

The Streamex.Activities module defines functions for working with feed activities.

Summary

Functions

Adds activities to the given feed. Accepts a single Map or a List of Maps. Returns {:ok, activity | activities}, or {:error, message} if something went wrong. Activities have a number of required fields. Refer to Streamex.Activity for a complete list

Adds an activity to a List of feeds. Returns {:ok, nil}, or {:error, message} if something went wrong. Activities have a number of required fields. Refer to Streamex.Activity for a complete list

Lists the given feed’s activities. Returns {:ok, activities}, or {:error, message} if something went wrong

Removes activities. Accepts an id or foreign_id string value. Returns {:ok, removed_id}, or {:error, message}

Updates activities. Accepts a single Map or a List of Maps. Returns {:ok, nil}, or {:error, message} Activities have a number of required fields. Refer to Streamex.Activity for a complete list

Functions

add(feed, activity)

Adds activities to the given feed. Accepts a single Map or a List of Maps. Returns {:ok, activity | activities}, or {:error, message} if something went wrong. Activities have a number of required fields. Refer to Streamex.Activity for a complete list.

Examples

iex> {_, feed} = Streamex.Feed.new("user", "eric")
{:ok, %Streamex.Feed{...}}

iex> activity = %{"actor" => "Tony", "verb" => "like", "object" => "Elixir", "foreign_id" => "tony:1"}
%{...}

iex> Streamex.Activities.add(feed, activity)
{:ok, %Streamex.Activity{...}}

iex> activity_b = %{"actor" => "Anna", "verb" => "like", "object" => "Hiking", "foreign_id" => "anna:1"}
%{...}

iex> Streamex.Activities.add(feed, [activity, activity_b])
{:ok, [%Streamex.Activity{...}, %Streamex.Activity{...}]}
add_to_many(feeds, activity)

Adds an activity to a List of feeds. Returns {:ok, nil}, or {:error, message} if something went wrong. Activities have a number of required fields. Refer to Streamex.Activity for a complete list.

Examples

iex> {_, feed} = Streamex.Feed.new("user", "eric")
{:ok, %Streamex.Feed{...}}

iex> {_, feed_b} = Streamex.Feed.new("user", "deborah")
{:ok, %Streamex.Feed{...}}

iex> activity = %{"actor" => "Tony", "verb" => "like", "object" => "Elixir", "foreign_id" => "tony:1"}
%{...}

iex> Streamex.Activities.add_to_many([feed, feed_b], activity)
{:ok, nil}
get(feed, opts \\ [])

Lists the given feed’s activities. Returns {:ok, activities}, or {:error, message} if something went wrong.

Available options are:

  • limit - limits the number of results. Defaults to 25
  • offset - offsets the results
  • id_gte - filter the feed on ids greater than or equal to the given value
  • id_gt - filter the feed on ids greater than the given value
  • id_lte - filter the feed on ids smaller than or equal to the given value
  • id_lt - filter the feed on ids smaller than the given value

Examples

iex> {_, feed} = Streamex.Feed.new("user", "eric")
{:ok, %Streamex.Feed{...}}

iex> Streamex.Activities.get(feed)
{:ok, [%Streamex.Activity{}...]}
handle_response(map)
remove(feed, id, opts \\ [])

Removes activities. Accepts an id or foreign_id string value. Returns {:ok, removed_id}, or {:error, message}

Available options are:

  • foreign_id - if set to true, removes the activity by foreign_id

Examples

iex> {_, feed} = Streamex.Feed.new("user", "eric")
{:ok, %Streamex.Feed{...}}

iex> Streamex.Activities.remove(feed, "d2d6fc2c-5e5a-11e6-8080-80017383369d")
{:ok, "d2d6fc2c-5e5a-11e6-8080-80017383369d"}

iex> Streamex.Activities.remove(feed, "tony:1", foreign_id: true)
{:ok, "tony:1"}
update(feed, activity)

Updates activities. Accepts a single Map or a List of Maps. Returns {:ok, nil}, or {:error, message} Activities have a number of required fields. Refer to Streamex.Activity for a complete list.

Examples

iex> {_, feed} = Streamex.Feed.new("user", "eric")
{:ok, %Streamex.Feed{...}}

iex> activity = %{"actor" => "Tony", "verb" => "like", "object" => "Elixir", "foreign_id" => "tony:1", "time" => "2016-08-09T19:38:12.241758"}
%{...}

iex> Streamex.Activities.update(feed, activity)
{:ok, nil}