SDKs

Ruby

Idiomatische Ruby-Patterns für die Thunderbit Open API

Verwende Net::HTTP (eingebaut) oder Faraday für Middleware-style Retries und Timeouts. Beide funktionieren — Net::HTTP wird unten gezeigt.

Konfigurieren

require 'net/http'
require 'json'
require 'uri'

API = 'https://openapi.thunderbit.com/openapi/v1'
HEADERS = {
  'Authorization' => "Bearer #{ENV.fetch('THUNDERBIT_API_KEY')}",
  'Content-Type'  => 'application/json'
}.freeze

def post(path, body)
  uri = URI("#{API}#{path}")
  res = Net::HTTP.post(uri, body.to_json, HEADERS)
  raise res.body if res.code.to_i >= 400
  JSON.parse(res.body)
end

Eine Seite distillen

result = post('/distill', { url: 'https://thunderbit.com/playground' })
puts result['data']['markdown']

Strukturierte Daten extrahieren

result = post('/extract', {
  url: 'https://example.com/product/iphone-15-pro',
  schema: {
    type: 'object',
    properties: {
      name:  { type: 'string' },
      price: { type: 'number' }
    },
    required: %w[name price]
  }
})
puts result['data']

Batch + Sidekiq

Für asynchrones Fan-out stellst du Submissions in die Queue und lässt Sidekiq-Worker die Webhook-Callbacks abwickeln:

class DistillBatchJob
  include Sidekiq::Worker

  def perform(urls)
    job = post('/batch/distill', {
      urls: urls,
      webhook: {
        url:    "#{ENV['APP_HOST']}/webhooks/distill",
        secret: ENV['WEBHOOK_SECRET']
      }
    })
    Rails.logger.info "Batch submitted: #{job['data']['id']}"
  end
end

Verifiziere die Webhook-Signatur in deinem Rails-Controller — siehe Webhooks.

Ein offizielles Ruby SDK ist in Entwicklung — schau bald wieder rein.