Packages

Auto-generated Elixir client for the X (Twitter) API v2

Current section

Files

Jump to
xdk_elixir lib xdk posts.ex
Raw

lib/xdk/posts.ex

# AUTO-GENERATED FILE - DO NOT EDIT
# This file was automatically generated by the XDK build tool.
# Any manual changes will be overwritten on the next generation.
defmodule Xdk.Posts do
@moduledoc "Auto-generated client for posts operations"
@doc """
Search all Posts
GET /2/tweets/search/all
Retrieves Posts from the full archive matching a search query.
"""
@spec search_all(Xdk.t(), opts :: keyword()) :: {:ok, map()} | {:error, Xdk.Errors.error()}
def search_all(client, opts \\ []) do
query =
[
{"query", Keyword.get(opts, :query)},
{"start_time", Keyword.get(opts, :start_time)},
{"end_time", Keyword.get(opts, :end_time)},
{"since_id", Keyword.get(opts, :since_id)},
{"until_id", Keyword.get(opts, :until_id)},
{"max_results", Keyword.get(opts, :max_results)},
{"next_token", Keyword.get(opts, :next_token)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"sort_order", Keyword.get(opts, :sort_order)},
{"tweet.fields", Keyword.get(opts, :tweet_fields)},
{"expansions", Keyword.get(opts, :expansions)},
{"media.fields", Keyword.get(opts, :media_fields)},
{"poll.fields", Keyword.get(opts, :poll_fields)},
{"user.fields", Keyword.get(opts, :user_fields)},
{"place.fields", Keyword.get(opts, :place_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/search/all", query: query)
end
@doc """
Get Reposts
GET /2/tweets/{id}/retweets
Retrieves a list of Posts that repost a specific Post by its ID.
"""
@spec get_reposts(Xdk.t(), id :: String.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_reposts(client, id, opts \\ []) do
query =
[
{"max_results", Keyword.get(opts, :max_results)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"tweet.fields", Keyword.get(opts, :tweet_fields)},
{"expansions", Keyword.get(opts, :expansions)},
{"media.fields", Keyword.get(opts, :media_fields)},
{"poll.fields", Keyword.get(opts, :poll_fields)},
{"user.fields", Keyword.get(opts, :user_fields)},
{"place.fields", Keyword.get(opts, :place_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/{id}/retweets",
params: %{
"id" => id
},
query: query
)
end
@doc """
Get Liking Users
GET /2/tweets/{id}/liking_users
Retrieves a list of Users who liked a specific Post by its ID.
"""
@spec get_liking_users(Xdk.t(), id :: String.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_liking_users(client, id, opts \\ []) do
query =
[
{"max_results", Keyword.get(opts, :max_results)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"user.fields", Keyword.get(opts, :user_fields)},
{"expansions", Keyword.get(opts, :expansions)},
{"tweet.fields", Keyword.get(opts, :tweet_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/{id}/liking_users",
params: %{
"id" => id
},
query: query
)
end
@doc """
Get Post by ID
GET /2/tweets/{id}
Retrieves details of a specific Post by its ID.
"""
@spec get_by_id(Xdk.t(), id :: String.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_by_id(client, id, opts \\ []) do
query =
[
{"tweet.fields", Keyword.get(opts, :tweet_fields)},
{"expansions", Keyword.get(opts, :expansions)},
{"media.fields", Keyword.get(opts, :media_fields)},
{"poll.fields", Keyword.get(opts, :poll_fields)},
{"user.fields", Keyword.get(opts, :user_fields)},
{"place.fields", Keyword.get(opts, :place_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/{id}",
params: %{
"id" => id
},
query: query
)
end
@doc """
Delete Post
DELETE /2/tweets/{id}
Deletes a specific Post by its ID, if owned by the authenticated user.
"""
@spec delete(Xdk.t(), id :: String.t()) :: {:ok, map()} | {:error, Xdk.Errors.error()}
def delete(client, id) do
Xdk.request(client, :delete, "/2/tweets/{id}",
params: %{
"id" => id
}
)
end
@doc """
Get historical Post insights
GET /2/insights/historical
Retrieves historical engagement metrics for specified Posts within a defined time range.
"""
@spec get_insights_historical(Xdk.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_insights_historical(client, opts \\ []) do
query =
[
{"tweet_ids", Keyword.get(opts, :tweet_ids)},
{"end_time", Keyword.get(opts, :end_time)},
{"start_time", Keyword.get(opts, :start_time)},
{"granularity", Keyword.get(opts, :granularity)},
{"requested_metrics", Keyword.get(opts, :requested_metrics)},
{"engagement.fields", Keyword.get(opts, :engagement_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/insights/historical", query: query)
end
@doc """
Get Reposted by
GET /2/tweets/{id}/retweeted_by
Retrieves a list of Users who reposted a specific Post by its ID.
"""
@spec get_reposted_by(Xdk.t(), id :: String.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_reposted_by(client, id, opts \\ []) do
query =
[
{"max_results", Keyword.get(opts, :max_results)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"user.fields", Keyword.get(opts, :user_fields)},
{"expansions", Keyword.get(opts, :expansions)},
{"tweet.fields", Keyword.get(opts, :tweet_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/{id}/retweeted_by",
params: %{
"id" => id
},
query: query
)
end
@doc """
Get Post analytics
GET /2/tweets/analytics
Retrieves analytics data for specified Posts within a defined time range.
"""
@spec get_analytics(Xdk.t(), opts :: keyword()) :: {:ok, map()} | {:error, Xdk.Errors.error()}
def get_analytics(client, opts \\ []) do
query =
[
{"ids", Keyword.get(opts, :ids)},
{"end_time", Keyword.get(opts, :end_time)},
{"start_time", Keyword.get(opts, :start_time)},
{"granularity", Keyword.get(opts, :granularity)},
{"analytics.fields", Keyword.get(opts, :analytics_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/analytics", query: query)
end
@doc """
Get count of recent Posts
GET /2/tweets/counts/recent
Retrieves the count of Posts from the last 7 days matching a search query.
"""
@spec get_counts_recent(Xdk.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_counts_recent(client, opts \\ []) do
query =
[
{"query", Keyword.get(opts, :query)},
{"start_time", Keyword.get(opts, :start_time)},
{"end_time", Keyword.get(opts, :end_time)},
{"since_id", Keyword.get(opts, :since_id)},
{"until_id", Keyword.get(opts, :until_id)},
{"next_token", Keyword.get(opts, :next_token)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"granularity", Keyword.get(opts, :granularity)},
{"search_count.fields", Keyword.get(opts, :search_count_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/counts/recent", query: query)
end
@doc """
Search recent Posts
GET /2/tweets/search/recent
Retrieves Posts from the last 7 days matching a search query.
"""
@spec search_recent(Xdk.t(), opts :: keyword()) :: {:ok, map()} | {:error, Xdk.Errors.error()}
def search_recent(client, opts \\ []) do
query =
[
{"query", Keyword.get(opts, :query)},
{"start_time", Keyword.get(opts, :start_time)},
{"end_time", Keyword.get(opts, :end_time)},
{"since_id", Keyword.get(opts, :since_id)},
{"until_id", Keyword.get(opts, :until_id)},
{"max_results", Keyword.get(opts, :max_results)},
{"next_token", Keyword.get(opts, :next_token)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"sort_order", Keyword.get(opts, :sort_order)},
{"tweet.fields", Keyword.get(opts, :tweet_fields)},
{"expansions", Keyword.get(opts, :expansions)},
{"media.fields", Keyword.get(opts, :media_fields)},
{"poll.fields", Keyword.get(opts, :poll_fields)},
{"user.fields", Keyword.get(opts, :user_fields)},
{"place.fields", Keyword.get(opts, :place_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/search/recent", query: query)
end
@doc """
Get Quoted Posts
GET /2/tweets/{id}/quote_tweets
Retrieves a list of Posts that quote a specific Post by its ID.
"""
@spec get_quoted(Xdk.t(), id :: String.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_quoted(client, id, opts \\ []) do
query =
[
{"max_results", Keyword.get(opts, :max_results)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"exclude", Keyword.get(opts, :exclude)},
{"tweet.fields", Keyword.get(opts, :tweet_fields)},
{"expansions", Keyword.get(opts, :expansions)},
{"media.fields", Keyword.get(opts, :media_fields)},
{"poll.fields", Keyword.get(opts, :poll_fields)},
{"user.fields", Keyword.get(opts, :user_fields)},
{"place.fields", Keyword.get(opts, :place_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/{id}/quote_tweets",
params: %{
"id" => id
},
query: query
)
end
@doc """
Get Posts by IDs
GET /2/tweets
Retrieves details of multiple Posts by their IDs.
"""
@spec get_by_ids(Xdk.t(), opts :: keyword()) :: {:ok, map()} | {:error, Xdk.Errors.error()}
def get_by_ids(client, opts \\ []) do
query =
[
{"ids", Keyword.get(opts, :ids)},
{"tweet.fields", Keyword.get(opts, :tweet_fields)},
{"expansions", Keyword.get(opts, :expansions)},
{"media.fields", Keyword.get(opts, :media_fields)},
{"poll.fields", Keyword.get(opts, :poll_fields)},
{"user.fields", Keyword.get(opts, :user_fields)},
{"place.fields", Keyword.get(opts, :place_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets", query: query)
end
@doc """
Create or Edit Post
POST /2/tweets
Creates a new Post for the authenticated user, or edits an existing Post when edit_options are provided.
"""
@spec create(Xdk.t(), body :: map()) :: {:ok, map()} | {:error, Xdk.Errors.error()}
def create(client, body) do
Xdk.request(client, :post, "/2/tweets", json: body)
end
@doc """
Hide reply
PUT /2/tweets/{tweet_id}/hidden
Hides or unhides a reply to a conversation owned by the authenticated user.
"""
@spec hide_reply(Xdk.t(), tweet_id :: String.t(), body :: map()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def hide_reply(client, tweet_id, body) do
Xdk.request(client, :put, "/2/tweets/{tweet_id}/hidden",
params: %{
"tweet_id" => tweet_id
},
json: body
)
end
@doc """
Get 28-hour Post insights
GET /2/insights/28hr
Retrieves engagement metrics for specified Posts over the last 28 hours.
"""
@spec get_insights28hr(Xdk.t(), opts :: keyword()) ::
{:ok, map()} | {:error, Xdk.Errors.error()}
def get_insights28hr(client, opts \\ []) do
query =
[
{"tweet_ids", Keyword.get(opts, :tweet_ids)},
{"granularity", Keyword.get(opts, :granularity)},
{"requested_metrics", Keyword.get(opts, :requested_metrics)},
{"engagement.fields", Keyword.get(opts, :engagement_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/insights/28hr", query: query)
end
@doc """
Get count of all Posts
GET /2/tweets/counts/all
Retrieves the count of Posts matching a search query from the full archive.
"""
@spec get_counts_all(Xdk.t(), opts :: keyword()) :: {:ok, map()} | {:error, Xdk.Errors.error()}
def get_counts_all(client, opts \\ []) do
query =
[
{"query", Keyword.get(opts, :query)},
{"start_time", Keyword.get(opts, :start_time)},
{"end_time", Keyword.get(opts, :end_time)},
{"since_id", Keyword.get(opts, :since_id)},
{"until_id", Keyword.get(opts, :until_id)},
{"next_token", Keyword.get(opts, :next_token)},
{"pagination_token", Keyword.get(opts, :pagination_token)},
{"granularity", Keyword.get(opts, :granularity)},
{"search_count.fields", Keyword.get(opts, :search_count_fields)}
]
|> Xdk.Query.build()
Xdk.request(client, :get, "/2/tweets/counts/all", query: query)
end
end