SDKs

Ruby

Patterns Ruby idiomatiques pour la Thunderbit Open API

Utilise Net::HTTP (intégré) ou Faraday pour des retries et timeouts façon middleware. Les deux marchent — Net::HTTP montré ci-dessous.

Configuration

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

Distill une page

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

Extract de données structurées

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

Pour le fan-out asynchrone, mets les soumissions en file et laisse les workers Sidekiq gérer les callbacks webhook :

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

Vérifie la signature du webhook dans ton contrôleur Rails — voir Webhooks.

Un SDK Ruby officiel est en développement — reviens bientôt.