The official Elixir SDK for the FoPost API.
Connect social accounts once, then compose, schedule, and publish from your own application.
client = FoPost.new(api_key: "fp_...")
{:ok, workspaces} = FoPost.Workspaces.list(client)
workspace = hd(workspaces)
{:ok, accounts} = FoPost.Accounts.list(client, workspace_id: workspace.id)
{:ok, post} =
FoPost.Posts.create(client,
workspace_id: workspace.id,
content: "Hello from Elixir",
accounts: Enum.map(accounts, & &1.id)
)
{:ok, _result} = FoPost.Posts.publish(client, post.id)Results
Every function answers {:ok, result} or {:error, %FoPost.Error{}}, and every one has
a bang variant that returns the result or raises the same error:
post = FoPost.Posts.create!(client, workspace_id: id, content: "Hello")Resources
FoPost.Posts, FoPost.Workspaces, FoPost.Accounts, FoPost.Communities,
FoPost.Labels, FoPost.Webhooks, FoPost.Analytics, FoPost.Automations,
FoPost.Media. Anything they do not wrap is reachable through request/4.
Summary
Functions
Builds a client.
Calls an endpoint the SDK does not wrap yet.
request/4 that returns the body or raises FoPost.Error.
The SDK version, as reported in the User-Agent header.
Functions
@spec new(keyword()) :: FoPost.Client.t()
Builds a client.
Options
:api_key— the key to authenticate with. Falls back toconfig :fopost, :api_keyand then to theFOPOST_API_KEYenvironment variable. Required: without one this raisesArgumentError.:base_url— defaults tohttps://api.fopost.com/v1, overridable throughconfig :fopost, :base_urlor theFOPOST_BASE_URLenvironment variable.:timeout— how long one request may take to answer, in milliseconds. Defaults to30_000.:max_retries— retries after the first attempt. Defaults to2, so three attempts in total.0disables retrying.:user_agent— replaces the defaultfopost-elixir/<version>.:req_options— options merged last into every Req request, so they win over everything above. Use it for a custom Finch pool, a proxy, or a test stub.
Explicit options beat application config, which beats the environment.
client = FoPost.new(api_key: "fp_...")
client = FoPost.new() # reads config or FOPOST_API_KEY
@spec request(FoPost.Client.t(), atom(), String.t(), keyword()) :: {:ok, term()} | {:error, FoPost.Error.t()}
Calls an endpoint the SDK does not wrap yet.
The decoded body is returned exactly as the API sent it, envelope included. Pass
unwrap: true to peel a {"data": ...} wrapper off it.
{:ok, body} = FoPost.request(client, :get, "/platforms")
{:ok, body} = FoPost.request(client, :post, "/posts/#{id}/publish", json: %{})
{:ok, body} = FoPost.request(client, :get, "/posts", params: [per_page: 5])Options are Req options, so :params, :json, and :form_multipart all work.
@spec request!(FoPost.Client.t(), atom(), String.t(), keyword()) :: term()
request/4 that returns the body or raises FoPost.Error.
@spec version() :: String.t()
The SDK version, as reported in the User-Agent header.