Class: Posthubify::Client

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

Overview

PostHubify /v1 API client. All resource groups are exposed as snake_case readers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, base_url: Transport::DEFAULT_BASE, timeout: 30, transport: nil) ⇒ Client

transport: injectable for tests (Node opts.fetch equivalent).



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/posthubify/client.rb', line 14

def initialize(api_key: nil, base_url: Transport::DEFAULT_BASE, timeout: 30, transport: nil)
  @http = transport || Transport.new(api_key: api_key, base_url: base_url, timeout: timeout)

  @profiles = ProfilesResource.new(@http)
  @accounts = AccountsResource.new(@http)
  @posts = PostsResource.new(@http)
  @media = MediaResource.new(@http)
  @tools = ToolsResource.new(@http)
  @ads = AdsResource.new(@http)
  @insights = InsightsResource.new(@http)
  @platform_analytics = PlatformAnalyticsResource.new(@http)
  @inbox_analytics = InboxAnalyticsResource.new(@http)
  @inbox = InboxResource.new(@http)
  @comments = CommentsResource.new(@http)
  @reviews = ReviewsResource.new(@http)
  @contacts = ContactsResource.new(@http)
  @automations = AutomationsResource.new(@http)
  @comment_automations = CommentAutomationsResource.new(@http)
  @workflows = WorkflowsResource.new(@http)
  @broadcasts = BroadcastsResource.new(@http)
  @sequences = SequencesResource.new(@http)
  @webhooks = WebhooksResource.new(@http)
  @api_keys = ApiKeysResource.new(@http)
  @queue = QueueResource.new(@http)
  @account_groups = AccountGroupsResource.new(@http)
  @engagement = EngagementResource.new(@http)
  @users = UsersResource.new(@http)
  @invite_tokens = InviteTokensResource.new(@http)
  @numbers = NumbersResource.new(@http)
  @senders = SendersResource.new(@http)
  @sms = SmsResource.new(@http)
  @otp = OtpResource.new(@http)
  @custom_fields = CustomFieldsResource.new(@http)
  @whatsapp = WhatsAppResource.new(@http)
  @gmb = GmbResource.new(@http)
  @discord = DiscordResource.new(@http)
  @discovery = DiscoveryResource.new(@http)
end

Instance Attribute Details

#account_groupsObject (readonly)

Returns the value of attribute account_groups.



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

def 
  @account_groups
end

#accountsObject (readonly)

Returns the value of attribute accounts.



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

def accounts
  @accounts
end

#adsObject (readonly)

Returns the value of attribute ads.



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

def ads
  @ads
end

#api_keysObject (readonly)

Returns the value of attribute api_keys.



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

def api_keys
  @api_keys
end

#automationsObject (readonly)

Returns the value of attribute automations.



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

def automations
  @automations
end

#broadcastsObject (readonly)

Returns the value of attribute broadcasts.



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

def broadcasts
  @broadcasts
end

#comment_automationsObject (readonly)

Returns the value of attribute comment_automations.



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

def comment_automations
  @comment_automations
end

#commentsObject (readonly)

Returns the value of attribute comments.



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

def comments
  @comments
end

#contactsObject (readonly)

Returns the value of attribute contacts.



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

def contacts
  @contacts
end

#custom_fieldsObject (readonly)

Returns the value of attribute custom_fields.



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

def custom_fields
  @custom_fields
end

#discordObject (readonly)

Returns the value of attribute discord.



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

def discord
  @discord
end

#discoveryObject (readonly)

Returns the value of attribute discovery.



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

def discovery
  @discovery
end

#engagementObject (readonly)

Returns the value of attribute engagement.



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

def engagement
  @engagement
end

#gmbObject (readonly)

Returns the value of attribute gmb.



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

def gmb
  @gmb
end

#inboxObject (readonly)

Returns the value of attribute inbox.



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

def inbox
  @inbox
end

#inbox_analyticsObject (readonly)

Returns the value of attribute inbox_analytics.



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

def inbox_analytics
  @inbox_analytics
end

#insightsObject (readonly)

Returns the value of attribute insights.



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

def insights
  @insights
end

#invite_tokensObject (readonly)

Returns the value of attribute invite_tokens.



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

def invite_tokens
  @invite_tokens
end

#mediaObject (readonly)

Returns the value of attribute media.



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

def media
  @media
end

#numbersObject (readonly)

Returns the value of attribute numbers.



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

def numbers
  @numbers
end

#otpObject (readonly)

Returns the value of attribute otp.



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

def otp
  @otp
end

#platform_analyticsObject (readonly)

Returns the value of attribute platform_analytics.



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

def platform_analytics
  @platform_analytics
end

#postsObject (readonly)

Returns the value of attribute posts.



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

def posts
  @posts
end

#profilesObject (readonly)

Returns the value of attribute profiles.



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

def profiles
  @profiles
end

#queueObject (readonly)

Returns the value of attribute queue.



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

def queue
  @queue
end

#reviewsObject (readonly)

Returns the value of attribute reviews.



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

def reviews
  @reviews
end

#sendersObject (readonly)

Returns the value of attribute senders.



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

def senders
  @senders
end

#sequencesObject (readonly)

Returns the value of attribute sequences.



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

def sequences
  @sequences
end

#smsObject (readonly)

Returns the value of attribute sms.



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

def sms
  @sms
end

#toolsObject (readonly)

Returns the value of attribute tools.



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

def tools
  @tools
end

#usersObject (readonly)

Returns the value of attribute users.



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

def users
  @users
end

#webhooksObject (readonly)

Returns the value of attribute webhooks.



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

def webhooks
  @webhooks
end

#whatsappObject (readonly)

Returns the value of attribute whatsapp.



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

def whatsapp
  @whatsapp
end

#workflowsObject (readonly)

Returns the value of attribute workflows.



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

def workflows
  @workflows
end

Instance Method Details

#analyticsObject



107
108
109
# File 'lib/posthubify/client.rb', line 107

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

#analytics_posts(platform: nil, account_id: nil, source: nil, limit: nil, cursor: nil) ⇒ Object

Post analytics list — source: ‘external’ is synced from the platform, not PostHubify (B5).



112
113
114
115
116
117
# File 'lib/posthubify/client.rb', line 112

def analytics_posts(platform: nil, account_id: nil, source: nil, limit: nil, cursor: nil)
  @http.req('GET', '/analytics/posts', query: {
              'platform' => platform, 'accountId' => , 'source' => source,
              'limit' => limit, 'cursor' => cursor
            })
end

#analytics_timeseries(days: nil, platform: nil, account_id: nil, from_date: nil, to_date: nil, source: nil) ⇒ Object

Stored daily metric time series (account/post/inbox aggregates).



120
121
122
123
124
125
# File 'lib/posthubify/client.rb', line 120

def analytics_timeseries(days: nil, platform: nil, account_id: nil, from_date: nil, to_date: nil, source: nil)
  @http.data('GET', '/analytics/timeseries', query: {
               'days' => days, 'platform' => platform, 'accountId' => ,
               'fromDate' => from_date, 'toDate' => to_date, 'source' => source
             })
end

#generate(command, platforms, variants: nil, context: nil, max_chars: nil) ⇒ Object

AI content generation (F1) — command → per-platform draft + variants (multi-language).



67
68
69
70
71
72
# File 'lib/posthubify/client.rb', line 67

def generate(command, platforms, variants: nil, context: nil, max_chars: nil)
  @http.data('POST', '/generate', body: {
    'command' => command, 'platforms' => platforms, 'variants' => variants,
    'context' => context, 'maxChars' => max_chars,
  })
end

#logs(limit: nil, category: nil, status: nil, platform: nil, days: nil) ⇒ Object



131
132
133
134
135
136
# File 'lib/posthubify/client.rb', line 131

def logs(limit: nil, category: nil, status: nil, platform: nil, days: nil)
  @http.data('GET', '/logs', query: {
               'limit' => limit, 'category' => category, 'status' => status,
               'platform' => platform, 'days' => days
             })
end

#meObject



62
63
64
# File 'lib/posthubify/client.rb', line 62

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

#openapiObject

— top-level endpoints —



54
55
56
# File 'lib/posthubify/client.rb', line 54

def openapi
  @http.req('GET', '/openapi.json')
end

#pingObject



58
59
60
# File 'lib/posthubify/client.rb', line 58

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

#subtitles(text, format: 'srt', duration_sec: nil, max_chars_per_line: nil, max_lines_per_cue: nil, chars_per_sec: nil, gap_ms: nil) ⇒ Object

Subtitle generation (F4) — text → timed SRT/VTT (pure conversion, no AI/charge; a read key is enough).

Parameters:

  • text (String)

    text to turn into subtitles (≤20000 characters)

  • format (String) (defaults to: 'srt')

    ‘srt’ or ‘vtt’ (default ‘srt’)

  • duration_sec (Float, nil) (defaults to: nil)

    if given, cues are distributed proportionally over this duration (audio-synced; ≤86400)

  • max_chars_per_line (Integer, nil) (defaults to: nil)

    max characters per line (10–120, default 42)

  • max_lines_per_cue (Integer, nil) (defaults to: nil)

    max lines per cue (1–4, default 2)

  • chars_per_sec (Float, nil) (defaults to: nil)

    reading speed when no duration is given (may be fractional, e.g. 15.5)

  • gap_ms (Integer, nil) (defaults to: nil)

    gap between cues (ms, default 80)



82
83
84
85
86
87
88
89
# File 'lib/posthubify/client.rb', line 82

def subtitles(text, format: 'srt', duration_sec: nil, max_chars_per_line: nil,
              max_lines_per_cue: nil, chars_per_sec: nil, gap_ms: nil)
  @http.data('POST', '/subtitles', body: {
    'text' => text, 'format' => format, 'durationSec' => duration_sec,
    'maxCharsPerLine' => max_chars_per_line, 'maxLinesPerCue' => max_lines_per_cue,
    'charsPerSec' => chars_per_sec, 'gapMs' => gap_ms,
  })
end

#usageObject



127
128
129
# File 'lib/posthubify/client.rb', line 127

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

#videos(image_url, format, audio_url: nil, subtitle_text: nil, subtitle_rtl: nil, bumper_duration_sec: nil, main_duration_sec: nil) ⇒ Object

Promo video render (F4) — remote image (+optional audio/subtitle) → branded video (ffmpeg) → R2 URL. HEAVY operation (write permission + low rate limit). Media is downloaded SSRF-protected (https + type + ≤25MB).

Parameters:

  • image_url (String)

    publicly-accessible https image URL

  • format (String)

    video ratio: ‘9:16’ | ‘1:1’ | ‘16:9’

  • audio_url (String, nil) (defaults to: nil)

    voiceover (mp3) URL; if given, the video duration is matched to the audio

  • subtitle_text (String, nil) (defaults to: nil)

    subtitle text to burn into the video

  • subtitle_rtl (Boolean, nil) (defaults to: nil)

    whether the subtitle is right-to-left (Arabic, etc.)



98
99
100
101
102
103
104
105
# File 'lib/posthubify/client.rb', line 98

def videos(image_url, format, audio_url: nil, subtitle_text: nil, subtitle_rtl: nil,
           bumper_duration_sec: nil, main_duration_sec: nil)
  @http.data('POST', '/videos', body: {
    'imageUrl' => image_url, 'format' => format, 'audioUrl' => audio_url,
    'subtitleText' => subtitle_text, 'subtitleRtl' => subtitle_rtl,
    'bumperDurationSec' => bumper_duration_sec, 'mainDurationSec' => main_duration_sec,
  })
end