공식 패키지 · 프레임워크

Sinatra에서 실시간 이벤트

Hibira 호스트를 가리키는 pusher gem으로 Sinatra 앱에서 Hibira 이벤트를 보내고, 채널 구독에 서명하고, 웹훅을 검증합니다.

가장 빠른 방법: Hibira 플러그인과 프롬프트 하나

AI 코딩 에이전트에 플러그인을 설치하고 프롬프트를 붙여 넣으세요. 에이전트가 로그인하고, 필요하면 무료 앱을 만들고, 코드를 작성한 뒤 테스트 이벤트를 보냅니다. GitHub ↗

  1. 플러그인 설치

    claude plugin marketplace add hibira-io/agent-plugin
    claude plugin install hibira@hibira
  2. 이 프롬프트 붙여 넣기

    Add Hibira Sinatra (pusher) to this project.
    Follow https://hibira.io/guides/sinatra, adapted to how this project is already set up.
    If I have no Hibira app yet, create a Free one that allows http://localhost so I can test right away.
    Keep the app key and secret in environment variables, add placeholders to .env.example, and never commit real values or send the secret to a browser.
    When you are done, send a test event, show me it arriving, and list the files you changed.

직접 하고 싶다면 아래 단계는 다음과 같습니다:

  1. 설치
  2. 사용하기

다른 AI 도구와 플러그인 구성 →

  • pusher gem이 이벤트를 보내고 비공개·presence 채널에 서명합니다.
  • 웹훅은 코드가 실행되기 전에 App secret으로 검증됩니다.

로그인하면 예제 코드에 내 클러스터 호스트가 채워집니다. 로그인

  1. 설치

    bundle add pusher
  2. 사용하기

    require "sinatra"
    require "pusher"
    
    HIBIRA = Pusher::Client.new(
      app_id: ENV.fetch("HIBIRA_APP_ID"), key: ENV.fetch("HIBIRA_APP_KEY"), secret: ENV.fetch("HIBIRA_APP_SECRET"),
      host: "ws.hibira.io", port: 443, use_tls: true
    )
    
    post "/orders/:id/ship" do
      HIBIRA.trigger("orders", "order.shipped", { id: params[:id].to_i })
      204
    end
    
    post "/pusher/auth" do
      halt 403 unless session[:user_id] # check the user may join params[:channel_name]
      content_type :json
      HIBIRA.authenticate(params[:channel_name], params[:socket_id]).to_json
    end
    
    post "/hibira/webhooks" do
      webhook = Pusher::WebHook.new(request, HIBIRA)
      halt 401 unless webhook.valid?
      webhook.events.each { |event| logger.info(event["name"]) }
      200
    end

시작하기 전에

  • 앱 시크릿은 앱을 만들거나 시크릿을 교체할 때 한 번만 표시됩니다. 서버에만 두고, 브라우저나 게임 빌드에는 절대 넣지 마세요.
  • Free 요금제에서는 페이지를 불러오는 모든 오리진을 앱의 허용 오리진에 등록하세요(개발 중에는 http://localhost:3000, 이후에는 내 도메인). "*"는 유료 요금제에서 쓸 수 있습니다.

대시보드의 앱 키를 사용하세요. 시크릿은 서버에만 둡니다. 채널, 이벤트, 인가 엔드포인트는 Pusher와 똑같이 동작합니다. 무료 계정 만들기 →