Class: OmniSocials::Resources::Posts
- Inherits:
-
Object
- Object
- OmniSocials::Resources::Posts
- Defined in:
- lib/omnisocials/resources/posts.rb
Overview
Posts resource: create, schedule, publish, update, and list posts.
content is a plain String, or a per-platform Hash with a "default" key.
media_ids / media_urls are a flat Array, or a per-platform Hash.
Instance Method Summary collapse
-
#create(content:, channels: nil, scheduled_at: nil, media_ids: nil, media_urls: nil, type: nil, source: nil, link_url: nil, link_title: nil, link_description: nil, link_thumbnail_url: nil, location_id: nil, collaborators: nil, user_tags: nil, pinterest: nil, youtube: nil, instagram: nil, facebook: nil, linkedin: nil, linkedin_page: nil, tiktok: nil, x: nil, bluesky: nil, mastodon: nil, google_business: nil) ⇒ Object
POST /posts/create - create a post (draft, or scheduled when scheduled_at is set).
-
#create_and_publish(content:, channels: nil, media_ids: nil, media_urls: nil, type: nil, source: nil, link_url: nil, link_title: nil, link_description: nil, link_thumbnail_url: nil, location_id: nil, collaborators: nil, user_tags: nil, pinterest: nil, youtube: nil, instagram: nil, facebook: nil, linkedin: nil, linkedin_page: nil, tiktok: nil, x: nil, bluesky: nil, mastodon: nil, google_business: nil) ⇒ Object
POST /posts/create-and-publish - create and publish immediately.
-
#delete(post_id) ⇒ Object
DELETE /posts/id - delete a post.
-
#get(post_id) ⇒ Object
GET /posts/id - fetch a single post.
-
#initialize(client) ⇒ Posts
constructor
A new instance of Posts.
-
#list(status: nil, limit: nil, offset: nil) ⇒ Object
GET /posts - list posts (status: draft, scheduled, posted, failed).
-
#publish(post_id) ⇒ Object
POST /posts/id/publish - publish a draft or scheduled post now.
-
#recent_platform(limit: nil, platforms: nil) ⇒ Object
GET /posts/recent-platform - recent posts fetched live from the connected platform APIs (including content published outside OmniSocials).
-
#update(post_id, content: nil, scheduled_at: nil, channels: nil, media_ids: nil, media_urls: nil, type: nil, location_id: nil, collaborators: nil, user_tags: nil, pinterest: nil, youtube: nil, instagram: nil, facebook: nil, linkedin: nil, linkedin_page: nil, tiktok: nil, x: nil, bluesky: nil, mastodon: nil, google_business: nil) ⇒ Object
PATCH /posts/id - update a draft or scheduled post.
Constructor Details
#initialize(client) ⇒ Posts
Returns a new instance of Posts.
10 11 12 |
# File 'lib/omnisocials/resources/posts.rb', line 10 def initialize(client) @client = client end |
Instance Method Details
#create(content:, channels: nil, scheduled_at: nil, media_ids: nil, media_urls: nil, type: nil, source: nil, link_url: nil, link_title: nil, link_description: nil, link_thumbnail_url: nil, location_id: nil, collaborators: nil, user_tags: nil, pinterest: nil, youtube: nil, instagram: nil, facebook: nil, linkedin: nil, linkedin_page: nil, tiktok: nil, x: nil, bluesky: nil, mastodon: nil, google_business: nil) ⇒ Object
POST /posts/create - create a post (draft, or scheduled when scheduled_at is set).
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/omnisocials/resources/posts.rb', line 39 def create(content:, channels: nil, scheduled_at: nil, media_ids: nil, media_urls: nil, type: nil, source: nil, link_url: nil, link_title: nil, link_description: nil, link_thumbnail_url: nil, location_id: nil, collaborators: nil, user_tags: nil, pinterest: nil, youtube: nil, instagram: nil, facebook: nil, linkedin: nil, linkedin_page: nil, tiktok: nil, x: nil, bluesky: nil, mastodon: nil, google_business: nil) body = create_body( content: content, channels: channels, scheduled_at: scheduled_at, media_ids: media_ids, media_urls: media_urls, type: type, source: source, link_url: link_url, link_title: link_title, link_description: link_description, link_thumbnail_url: link_thumbnail_url, location_id: location_id, collaborators: collaborators, user_tags: , pinterest: pinterest, youtube: youtube, instagram: instagram, facebook: facebook, linkedin: linkedin, linkedin_page: linkedin_page, tiktok: tiktok, x: x, bluesky: bluesky, mastodon: mastodon, google_business: google_business ) @client.request("POST", "/posts/create", json: body) end |
#create_and_publish(content:, channels: nil, media_ids: nil, media_urls: nil, type: nil, source: nil, link_url: nil, link_title: nil, link_description: nil, link_thumbnail_url: nil, location_id: nil, collaborators: nil, user_tags: nil, pinterest: nil, youtube: nil, instagram: nil, facebook: nil, linkedin: nil, linkedin_page: nil, tiktok: nil, x: nil, bluesky: nil, mastodon: nil, google_business: nil) ⇒ Object
POST /posts/create-and-publish - create and publish immediately.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/omnisocials/resources/posts.rb', line 61 def create_and_publish(content:, channels: nil, media_ids: nil, media_urls: nil, type: nil, source: nil, link_url: nil, link_title: nil, link_description: nil, link_thumbnail_url: nil, location_id: nil, collaborators: nil, user_tags: nil, pinterest: nil, youtube: nil, instagram: nil, facebook: nil, linkedin: nil, linkedin_page: nil, tiktok: nil, x: nil, bluesky: nil, mastodon: nil, google_business: nil) body = create_body( content: content, channels: channels, scheduled_at: nil, media_ids: media_ids, media_urls: media_urls, type: type, source: source, link_url: link_url, link_title: link_title, link_description: link_description, link_thumbnail_url: link_thumbnail_url, location_id: location_id, collaborators: collaborators, user_tags: , pinterest: pinterest, youtube: youtube, instagram: instagram, facebook: facebook, linkedin: linkedin, linkedin_page: linkedin_page, tiktok: tiktok, x: x, bluesky: bluesky, mastodon: mastodon, google_business: google_business ) @client.request("POST", "/posts/create-and-publish", json: body) end |
#delete(post_id) ⇒ Object
DELETE /posts/id - delete a post. Returns nil (204).
124 125 126 |
# File 'lib/omnisocials/resources/posts.rb', line 124 def delete(post_id) @client.request("DELETE", "/posts/#{post_id}") end |
#get(post_id) ⇒ Object
GET /posts/id - fetch a single post.
23 24 25 |
# File 'lib/omnisocials/resources/posts.rb', line 23 def get(post_id) @client.request("GET", "/posts/#{post_id}") end |
#list(status: nil, limit: nil, offset: nil) ⇒ Object
GET /posts - list posts (status: draft, scheduled, posted, failed).
15 16 17 18 19 20 |
# File 'lib/omnisocials/resources/posts.rb', line 15 def list(status: nil, limit: nil, offset: nil) @client.request( "GET", "/posts", query: { "status" => status, "limit" => limit, "offset" => offset } ) end |
#publish(post_id) ⇒ Object
POST /posts/id/publish - publish a draft or scheduled post now.
129 130 131 |
# File 'lib/omnisocials/resources/posts.rb', line 129 def publish(post_id) @client.request("POST", "/posts/#{post_id}/publish") end |
#recent_platform(limit: nil, platforms: nil) ⇒ Object
GET /posts/recent-platform - recent posts fetched live from the connected platform APIs (including content published outside OmniSocials). Requires the analytics:read scope.
30 31 32 33 34 35 |
# File 'lib/omnisocials/resources/posts.rb', line 30 def recent_platform(limit: nil, platforms: nil) @client.request( "GET", "/posts/recent-platform", query: { "limit" => limit, "platforms" => Internal.join_list(platforms) } ) end |
#update(post_id, content: nil, scheduled_at: nil, channels: nil, media_ids: nil, media_urls: nil, type: nil, location_id: nil, collaborators: nil, user_tags: nil, pinterest: nil, youtube: nil, instagram: nil, facebook: nil, linkedin: nil, linkedin_page: nil, tiktok: nil, x: nil, bluesky: nil, mastodon: nil, google_business: nil) ⇒ Object
PATCH /posts/id - update a draft or scheduled post.
Only top-level nils are dropped from the body, so passing e.g. x: { "thread_parts" => nil } still clears an X thread (reverts the post to single-tweet mode). The same applies to bluesky and mastodon thread parts.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/omnisocials/resources/posts.rb', line 90 def update(post_id, content: nil, scheduled_at: nil, channels: nil, media_ids: nil, media_urls: nil, type: nil, location_id: nil, collaborators: nil, user_tags: nil, pinterest: nil, youtube: nil, instagram: nil, facebook: nil, linkedin: nil, linkedin_page: nil, tiktok: nil, x: nil, bluesky: nil, mastodon: nil, google_business: nil) body = Internal.drop_nil( { "content" => content, "scheduled_at" => scheduled_at, "channels" => channels, "media_ids" => media_ids, "media_urls" => media_urls, "type" => type, "location_id" => location_id, "collaborators" => collaborators, "user_tags" => , "pinterest" => pinterest, "youtube" => youtube, "instagram" => instagram, "facebook" => facebook, "linkedin" => linkedin, "linkedin_page" => linkedin_page, "tiktok" => tiktok, "x" => x, "bluesky" => bluesky, "mastodon" => mastodon, "google_business" => google_business } ) @client.request("PATCH", "/posts/#{post_id}", json: body) end |