Class: Posthubify::MediaResource

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

Overview

Media assets — upload + signed presign URL (Node sdk .media).

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ MediaResource

Returns a new instance of MediaResource.



64
65
66
# File 'lib/posthubify/resources/posts.rb', line 64

def initialize(http)
  @http = http
end

Instance Method Details

#presign(input) ⇒ Object

Signed PUT URL for direct-to-storage upload (5GB; requires R2, otherwise 501). input: { ‘fileName’ => …, ‘contentType’ => … }.



76
77
78
# File 'lib/posthubify/resources/posts.rb', line 76

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

#upload(content, filename = 'upload.bin') ⇒ Object

Upload an image/video (max 64MB) → use the assetId with posts.create({ mediaAssetId }). content = raw byte string (binary string).



70
71
72
# File 'lib/posthubify/resources/posts.rb', line 70

def upload(content, filename = 'upload.bin')
  @http.data('POST', '/media', files: ['file', content, filename])
end