FoPost.Posts (FoPost v0.1.0)

Copy Markdown View Source

Create, schedule, publish, and inspect posts.

{:ok, post} =
  FoPost.Posts.create(client,
    workspace_id: workspace.id,
    content: "Hello from Elixir",
    accounts: [account.id]
  )

{:ok, result} = FoPost.Posts.publish(client, post.id)

:content takes a string for a single block, or a list for a thread. A block may also be a map of text plus media:

FoPost.Posts.create(client,
  workspace_id: workspace.id,
  accounts: [account.id],
  content: [
    "First post in the thread",
    %{text: "Second one, with an image", media: [%{type: "image", url: url}]}
  ]
)

:accounts takes account ids, FoPost.Account structs, or maps carrying an id.

:status is "draft" or "scheduled"; a scheduled post needs :schedule_at, which accepts a DateTime, a NaiveDateTime, or an ISO 8601 string. To send something out now, create it and call publish/3 — publishing answers when delivery is queued, not when the post is live.

Summary

Functions

A post's performance across the platforms it reached.

Removes a selection of posts in one transaction.

Relabels a selection.

Moves a selection's schedule by :offset_minutes, which may be negative but never zero.

Stops the deliveries that have not gone out yet.

Creates the posts a CSV describes. Keep the batch id to roll the import back.

Composes a draft or a scheduled post.

Same as create/2, but returns the post or raises FoPost.Error.

Removes a post.

The current delivery record for each account the post targets.

Copies a post into a new draft.

One post.

Same as get/2, but returns the post or raises FoPost.Error.

One page of posts.

Same as list/2, but returns the page or raises FoPost.Error.

Checks a post against every platform it targets, without publishing.

Queues a post for delivery to its accounts.

Every publish attempt made for a post, newest first.

Re-sends the deliveries that failed, leaving the successful ones alone.

Deletes every post a committed batch created.

Every matching post as a lazy stream, fetching one page at a time.

Edits a post that has not been published.

Same as update/3, but returns the post or raises FoPost.Error.

Dry-runs a CSV import and reports per-row results without creating anything.

Functions

analytics(client, id)

@spec analytics(FoPost.Client.t(), String.t()) ::
  {:ok, FoPost.PostAnalytics.t()} | {:error, FoPost.Error.t()}

A post's performance across the platforms it reached.

analytics!(client, id)

Same as analytics/2, but raises FoPost.Error.

bulk_delete(client, opts)

@spec bulk_delete(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.BulkResult.t()} | {:error, FoPost.Error.t()}

Removes a selection of posts in one transaction.

bulk_delete!(client, opts)

Same as bulk_delete/2, but raises FoPost.Error.

bulk_label(client, opts)

@spec bulk_label(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.BulkResult.t()} | {:error, FoPost.Error.t()}

Relabels a selection.

:mode is "replace" (the default, where an empty :label_ids clears them), "add", or "remove".

bulk_label!(client, opts)

Same as bulk_label/2, but raises FoPost.Error.

bulk_shift(client, opts)

@spec bulk_shift(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.BulkResult.t()} | {:error, FoPost.Error.t()}

Moves a selection's schedule by :offset_minutes, which may be negative but never zero.

Only drafts and scheduled posts can be shifted, and one ineligible post in the selection changes nothing at all.

bulk_shift!(client, opts)

Same as bulk_shift/2, but raises FoPost.Error.

cancel(client, id, opts \\ [])

@spec cancel(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.PublishResult.t()} | {:error, FoPost.Error.t()}

Stops the deliveries that have not gone out yet.

Pass :account_ids to cancel only some of them.

cancel!(client, id, opts \\ [])

Same as cancel/3, but raises FoPost.Error.

commit_bulk_import(client, opts)

@spec commit_bulk_import(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.BulkImportResult.t()} | {:error, FoPost.Error.t()}

Creates the posts a CSV describes. Keep the batch id to roll the import back.

commit_bulk_import!(client, opts)

Same as commit_bulk_import/2, but raises FoPost.Error.

create(client, opts)

@spec create(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.Post.t()} | {:error, FoPost.Error.t()}

Composes a draft or a scheduled post.

Required: :workspace_id, :content, :accounts. Optional: :status, :schedule_at, :content_type, :artifact_type, :labels, :title, :internal_title, :summary, :auto_plug, :auto_plug_content, :settings, :repeatable, :repeatable_times, :repeatable_gap, :repeatable_gap_unit, :source_ids, :companion_of.

create!(client, opts)

Same as create/2, but returns the post or raises FoPost.Error.

delete(client, id)

@spec delete(FoPost.Client.t(), String.t()) ::
  {:ok, FoPost.Message.t()} | {:error, FoPost.Error.t()}

Removes a post.

delete!(client, id)

Same as delete/2, but raises FoPost.Error.

deliveries(client, id)

@spec deliveries(FoPost.Client.t(), String.t()) ::
  {:ok, [FoPost.Delivery.t()]} | {:error, FoPost.Error.t()}

The current delivery record for each account the post targets.

deliveries!(client, id)

Same as deliveries/2, but raises FoPost.Error.

duplicate(client, id)

@spec duplicate(FoPost.Client.t(), String.t()) ::
  {:ok, FoPost.Post.t()} | {:error, FoPost.Error.t()}

Copies a post into a new draft.

duplicate!(client, id)

Same as duplicate/2, but raises FoPost.Error.

get(client, id)

@spec get(FoPost.Client.t(), String.t()) ::
  {:ok, FoPost.Post.t()} | {:error, FoPost.Error.t()}

One post.

get!(client, id)

Same as get/2, but returns the post or raises FoPost.Error.

list(client, opts \\ [])

@spec list(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.Page.t()} | {:error, FoPost.Error.t()}

One page of posts.

Filters: :workspace_id, :status, :search, :platform, :label, :account_id, :date, :from, :to, :sort. Paging: :page, :per_page. Anything left out keeps the API's own default.

{:ok, page} = FoPost.Posts.list(client, workspace_id: id, status: "published")
page.meta.total

list!(client, opts \\ [])

Same as list/2, but returns the page or raises FoPost.Error.

preflight(client, id)

@spec preflight(FoPost.Client.t(), String.t()) ::
  {:ok, FoPost.PreflightResult.t()} | {:error, FoPost.Error.t()}

Checks a post against every platform it targets, without publishing.

preflight!(client, id)

Same as preflight/2, but raises FoPost.Error.

publish(client, id, opts \\ [])

@spec publish(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.PublishResult.t()} | {:error, FoPost.Error.t()}

Queues a post for delivery to its accounts.

Nothing reaches a platform without this call or a schedule the user set. Options:

  • :account_ids — publish to a subset of the post's accounts
  • :dry_run — validate everything without sending anything to a platform

publish!(client, id, opts \\ [])

Same as publish/3, but raises FoPost.Error.

publish_runs(client, id)

@spec publish_runs(FoPost.Client.t(), String.t()) ::
  {:ok, [FoPost.PublishRun.t()]} | {:error, FoPost.Error.t()}

Every publish attempt made for a post, newest first.

publish_runs!(client, id)

Same as publish_runs/2, but raises FoPost.Error.

retry(client, id, opts \\ [])

@spec retry(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.PublishResult.t()} | {:error, FoPost.Error.t()}

Re-sends the deliveries that failed, leaving the successful ones alone.

Options: :account_ids, :include_published.

retry!(client, id, opts \\ [])

Same as retry/3, but raises FoPost.Error.

rollback_bulk_import(client, batch_id)

@spec rollback_bulk_import(FoPost.Client.t(), String.t()) ::
  {:ok, FoPost.Message.t()} | {:error, FoPost.Error.t()}

Deletes every post a committed batch created.

rollback_bulk_import!(client, batch_id)

Same as rollback_bulk_import/2, but raises FoPost.Error.

stream(client, opts \\ [])

@spec stream(
  FoPost.Client.t(),
  keyword()
) :: Enumerable.t()

Every matching post as a lazy stream, fetching one page at a time.

Takes the same filters as list/2. Because a stream cannot answer with an error tuple, a failed page raises FoPost.Error.

client
|> FoPost.Posts.stream(workspace_id: id)
|> Stream.filter(&(&1.status == "published"))
|> Enum.take(10)

update(client, id, opts)

@spec update(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.Post.t()} | {:error, FoPost.Error.t()}

Edits a post that has not been published.

Only the keys you pass are sent, so this stays a partial update. Passing a key as nil sends null, which is how a field is cleared.

update!(client, id, opts)

Same as update/3, but returns the post or raises FoPost.Error.

validate_bulk_import(client, opts)

@spec validate_bulk_import(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.BulkImportValidation.t()} | {:error, FoPost.Error.t()}

Dry-runs a CSV import and reports per-row results without creating anything.

:file is a path, a {filename, content} tuple, or a map of :filename and :content.

validate_bulk_import!(client, opts)

Same as validate_bulk_import/2, but raises FoPost.Error.