Class: Posthubify::PostsResource

Inherits:
Object
  • Object
show all
Defined in:
lib/posthubify/resources/posts.rb

Overview

Post lifecycle — create/list/update/retry/unpublish (Node sdk .posts).

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ PostsResource

Returns a new instance of PostsResource.



6
7
8
# File 'lib/posthubify/resources/posts.rb', line 6

def initialize(http)
  @http = http
end

Instance Method Details

#bulk_upload(csv, dry_run: nil) ⇒ Object

Bulk CSV upload (max 200 rows). dry_run=true only validates.



57
58
59
# File 'lib/posthubify/resources/posts.rb', line 57

def bulk_upload(csv, dry_run: nil)
  @http.data('POST', '/posts/bulk-upload', body: { 'csv' => csv, 'dryRun' => dry_run })
end

#create(input, idempotency_key: nil) ⇒ Object

Create a post. scheduled_at → schedule; publish:true → publish immediately; neither → draft. input = camelCase-keyed Hash (accountIds, content, captions, mediaAssetId, scheduledAt, publish, queue, options).



22
23
24
# File 'lib/posthubify/resources/posts.rb', line 22

def create(input, idempotency_key: nil)
  @http.data('POST', '/posts', body: input, idempotency_key: idempotency_key)
end

#delete(id) ⇒ Object

Cancels unpublished targets (rejected); 409 if all are published.



32
33
34
# File 'lib/posthubify/resources/posts.rb', line 32

def delete(id)
  @http.data('DELETE', "/posts/#{id}")
end

#edit_published(id, input) ⇒ Object

Edits the text of a published post on the platform (input: content/captions).



52
53
54
# File 'lib/posthubify/resources/posts.rb', line 52

def edit_published(id, input)
  @http.data('POST', "/posts/#{id}/edit-published", body: input)
end

#get(id) ⇒ Object

Get a single post.



16
17
18
# File 'lib/posthubify/resources/posts.rb', line 16

def get(id)
  @http.data('GET', "/posts/#{id}")
end

#listObject

List all posts.



11
12
13
# File 'lib/posthubify/resources/posts.rb', line 11

def list
  @http.data('GET', '/posts')
end

#retry(id) ⇒ Object

Retries failed targets; returns a per-target result.



37
38
39
# File 'lib/posthubify/resources/posts.rb', line 37

def retry(id)
  @http.data('POST', "/posts/#{id}/retry")
end

#unpublish(id) ⇒ Object

Removes the live post from the platform (platforms with deletePost capability).



47
48
49
# File 'lib/posthubify/resources/posts.rb', line 47

def unpublish(id)
  @http.data('POST', "/posts/#{id}/unpublish")
end

#update(id, input) ⇒ Object

Edits the content/timing of unpublished targets (input: content/captions/scheduledAt).



42
43
44
# File 'lib/posthubify/resources/posts.rb', line 42

def update(id, input)
  @http.data('PUT', "/posts/#{id}", body: input)
end

#validate(input) ⇒ Object

Validate content against per-platform character limits (input: { ‘content’ => …, ‘platforms’ => […] }).



27
28
29
# File 'lib/posthubify/resources/posts.rb', line 27

def validate(input)
  @http.data('POST', '/validate', body: input)
end