GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - FlightByte-dev/flightbyte-ruby: Official Ruby SDK for the FlightByte flight status API: live flight status, flight tracking and signed webhooks with a ready Rack receiver for Rails and Sinatra. Zero dependencies.

BranchesTags
Open more actions menu

Latest commit

 

History

3 Commits
3 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
assets
assets
 
 
examples
examples
 
 
lib
lib
 
 
sig
sig
 
 
spec
spec
 
 
test
test
 
 
tool
tool
 
 
.gitignore
.gitignore
 
 
.rubocop.yml
.rubocop.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Gemfile
Gemfile
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
Rakefile
Rakefile
 
 
SECURITY.md
SECURITY.md
 
 
flightbyte.gemspec
flightbyte.gemspec
 
 

Repository files navigation

FlightByte

FlightByte for Ruby

The official Ruby client for the FlightByte flight status API.
Look flights up, watch them with signed webhooks and verify every delivery,
from a Rails app, a background job or a script.

gem version Ruby 3.1+ No dependencies MIT license

Docs · Get a free key · API reference · Webhook docs · Support


Quick start

  1. Get a free API key at app.flightbyte.dev/signup.

  2. Add the gem:

    Command
    Bundler bundle add flightbyte
    RubyGems gem install flightbyte
  3. Look a flight up:

    require "flightbyte"
    
    client = FlightByte::Client.new(api_key: ENV.fetch("FLIGHTBYTE_API_KEY"))
    
    flight = client.flights.get(
      carrier: "TK",
      flight_number: "1848",
      date: "2026-09-08" # local departure date at the origin
    )
    
    puts flight.status.label            # Scheduled
    puts flight.departure.gate          # A11
    puts flight.departure.delay_minutes # 15

Every field reads as a snake_case method, flight["departure"]["delayMinutes"] reads it by the API's own key, and flight.to_h is the JSON exactly as received. date: takes a Date too, and FlightByte.format_date(time) gives the YYYY-MM-DD the API expects, from a Time already in the origin airport's offset. To try it from a terminal, run the example in this repository:

git clone https://github.com/FlightByte-dev/flightbyte-ruby.git && cd flightbyte-ruby
FLIGHTBYTE_API_KEY=frk_live_... ruby -Ilib examples/lookup.rb TK 1 2026-11-15
TK1:2026-11-15@IST-JFK  IST → JFK
Status     Scheduled (scheduled)
Departure  2026-11-15T15:20:00.000 +03, gate D15
Arrival    2026-11-15T18:20:00.000 EST, baggage -
Quota      23 of 30 left this minute

What you can do

You want to You call
Show a passenger their gate and delay client.flights.get(...) returns the live snapshot: phase, gate, terminal, baggage belt, scheduled, estimated and actual times, delay, aircraft and codeshares.
Look up TK1 tomorrow, which flies two legs Pass origin: "IST". Without it the snapshot lists every leg in alternates, and a subscription refuses to guess: the BadRequestError carries the legs to choose from.
Be told when anything changes client.subscriptions.create(...) starts the watch and returns the signing secret, shown once.
Find out why webhooks stopped arriving client.subscriptions.get(id) and deliveries(id) show the status and the HTTP code and error of every recent attempt.
Trust a webhook on your server FlightByte::Webhook::RackApp.new(secret) { |event| ... } verifies the signature against the raw body, decodes the event and calls you.

API

Flights: read-only.

Method What it does
flights.get Live status of one flight leg, and every leg the number flies that day.
GET /v1/flights/{carrier}/{flightNumber}/{date}
flights.timeline The airline's own change history for a leg, newest first.
GET /v1/flights/{carrier}/{flightNumber}/{date}/timeline

Subscriptions

Method What it does Access
subscriptions.create Watch a flight and get a signed webhook for every change. Counts as a watched flight on your plan; pass idempotency_key: so a retry never counts twice.
POST /v1/subscriptions
writes
subscriptions.list One page of your subscriptions, filtered by status, carrier, number or date.
GET /v1/subscriptions
read-only
subscriptions.list_all Every matching subscription, fetched page by page as you iterate; without a block it is a lazy Enumerator.
GET /v1/subscriptions
read-only
subscriptions.get One subscription with its status and delivery counters.
GET /v1/subscriptions/{id}
read-only
subscriptions.update Change the webhook URL, event filter, delay threshold, headers or metadata.
PATCH /v1/subscriptions/{id}
writes
subscriptions.pause Stop polling and deliveries without losing anything.
POST /v1/subscriptions/{id}/pause
writes
subscriptions.resume Resume a paused or auto-suspended subscription.
POST /v1/subscriptions/{id}/resume
writes
subscriptions.delete Delete a subscription for good.
DELETE /v1/subscriptions/{id}
destructive
subscriptions.send_test Send a signed subscription.test webhook to the subscription's URL.
POST /v1/subscriptions/{id}/test
writes
subscriptions.deliveries Recent delivery attempts with HTTP status and errors.
GET /v1/subscriptions/{id}/deliveries
read-only
subscriptions.events Recent events with the exact payloads that were sent.
GET /v1/subscriptions/{id}/events
read-only
subscriptions.secret Reveal the signing secret again.
GET /v1/subscriptions/{id}/secret
read-only
subscriptions.rotate_secret Generate a new signing secret. Previous signatures stop validating.
POST /v1/subscriptions/{id}/secret/rotate
writes

Countries: read-only.

Method What it does
countries.list Every country with its name in any language, emoji and flag URLs.
GET /v1/countries
countries.get One country by its ISO 3166-1 alpha-2 code.
GET /v1/countries/{code}
countries.flag_url The URL of a country's SVG flag, 4:3 or square. Needs no key, so it can go straight into an <img>.
GET /v1/flags/{code}.svg

Every method takes a timeout: of its own. Parameters are keywords named after the API's own, in snake_case (carrier:, flight_number:, date:, origin:, webhook_url:, …), and responses come back exactly as the API sent them, as frozen objects: timestamps are ISO 8601 strings, phases and statuses are strings, and no field is renamed or dropped. Each shape has its class, such as FlightByte::FlightSnapshot or FlightByte::Subscription, and they match patterns too: in { status: { phase: "landed" } }. The full snapshot is documented under Flights.

Watch a flight

created = client.subscriptions.create(
  carrier: "TK",
  flight_number: "1848",
  date: "2026-09-08",
  webhook_url: "https://api.example.com/hooks/flights",
  events: %w[departure.gate.changed delay.increased flight.departed],
  metadata: { bookingId: "BK-1042" },
  idempotency_key: "BK-1042" # safe to retry
)

# Shown in full only now: store it where your webhook receiver can read it.
signing_secret = created.secret

FlightByte only delivers to public HTTPS addresses. To receive on your machine, expose the port with a tunnel (cloudflared tunnel --url http://localhost:3000 or ngrok http 3000) and use that URL. subscriptions.send_test(id) sends a signed subscription.test whenever you want to see the path work.

Receive webhooks

A receiver has to do four things, in this order: verify the signature against the raw body, deduplicate on the event id, answer 2xx before doing the work, and branch on the event type.

FlightByte::Webhook::RackApp does the first and answers for you: 401 for a bad signature, 400 for a body that is not an event, 500 when your block raises (so FlightByte retries) and 200 otherwise, plus 405 to anything but a POST and 413 to a body over 1 MiB. What your block raises goes to warn, or to the on_error: option. An empty secret raises an ArgumentError right away, because anyone can sign with an empty key: an unset environment variable fails at boot instead of accepting forged events. It is a plain Rack app that needs no Rack gem, so it mounts in every Ruby web framework:

receiver = FlightByte::Webhook::RackApp.new(ENV.fetch("FLIGHTBYTE_WEBHOOK_SECRET")) do |event|
  # A retry carries the same id: answer it, but don't handle it twice.
  next unless mark_handled(event.id)

  # Answer first: FlightByte treats a delivery as failed after 10 seconds.
  FlightEventJob.perform_later(event.to_h)
end
Rails, Sinatra, Roda and a bare config.ru
# Build the receiver once, at boot: in Rails, an initializer that sets
# FLIGHTBYTE_RECEIVER = FlightByte::Webhook::RackApp.new(...) { |event| ... }

# Rails: config/routes.rb
mount FLIGHTBYTE_RECEIVER, at: "/hooks/flightbyte"

# Sinatra, Hanami or any app built with Rack::Builder: config.ru
map("/hooks/flightbyte") { run receiver }
run MyApp

# Roda
route do |r|
  r.on("hooks", "flightbyte") { r.run receiver }
end

In a Rails controller, read the body with request.raw_post, not params: the signature covers the bytes as sent, and JSON parsed and serialised again no longer matches.

class FlightbyteWebhooksController < ActionController::API
  def create
    event = FlightByte::Webhook.construct_event(
      request.raw_post,
      request.headers[FlightByte::Webhook::SIGNATURE_HEADER],
      ENV.fetch("FLIGHTBYTE_WEBHOOK_SECRET")
    )
  rescue FlightByte::WebhookSignatureError
    head :unauthorized
  rescue FlightByte::Error
    head :bad_request
  else
    FlightEventJob.perform_later(event.to_h)
    head :ok
  end
end

class FlightEventJob < ApplicationJob
  def perform(payload)
    event = FlightByte::WebhookEvent.new(payload)
    case event.type
    when "flight.updated"
      event.changes.each { |change| logger.info("#{event.flight_key} #{change.type}: #{change.message}") }
    when "subscription.completed"
      logger.info("#{event.flight_key} finished")
    end
  end
end

In a Sinatra route, the raw body is request.body.read and the header is request.env[FlightByte::Webhook::SIGNATURE_ENV_KEY]. A receiver with no framework, for any Rack server, is in examples/webhook.ru.

How the signature works
x-flightbyte-signature: t=1789305971,v1=5f1c9a...e3b2
v1 = HMAC-SHA256(secret, "<t>." + <raw body>)

FlightByte::Webhook.verify computes the HMAC over the body you received, not over JSON you decoded and encoded again, compares it in constant time with OpenSSL.fixed_length_secure_compare, accepts any of several v1 values, and rejects a t more than five minutes from now. Webhook.sign produces the same header, for testing your receiver. The test suite checks both against signatures made by the API's own signer, and fuzzes the header parser.

The reasons behind each step are in Verifying webhook signatures, and reference receivers in Node.js, Python and Go are in flightbyte-webhook-examples.

Errors

Every failed request raises a subclass of FlightByte::Error, so you rescue the ones you can handle and let the rest through.

Error Status When, and what to do
BadRequestError 400 Invalid input; messages has one line per field. For a number that flies twice, legs lists them: pass one's origin.
AuthenticationError 401 Missing, invalid, revoked or expired API key.
PaymentRequiredError 402 No watched flights left. code says why: watched_flight_limit, overage_cap_reached (see resets_at) or credits_exhausted (see balance and expires_at).
PermissionDeniedError 403 The account is suspended, or a token lacks the scope (code).
NotFoundError 404 The flight did not operate that day, or no such subscription.
RateLimitError 429 A minute, day or month quota is used up. Wait retry_after seconds.
UpstreamError 502 The flight data provider failed. Retry shortly. It is also a ServerError.
ServerError, UnexpectedStatusError other Anything else. request_id is what support asks for.
ConnectionError none No response at all: refused connection, DNS, TLS or a dropped socket, or timed_out? when the timeout ran out. The original exception is its cause.
begin
  client.subscriptions.create(**params)
rescue FlightByte::BadRequestError => e
  raise if e.legs.empty?

  puts "Pick a leg: #{e.legs.map(&:origin).join(", ")}"
rescue FlightByte::PaymentRequiredError => e
  puts "No watched flights left (#{e.code}) until #{e.resets_at}"
rescue FlightByte::RateLimitError => e
  sleep(e.retry_after || 5)
  retry
end

Arguments that cannot make a valid request, such as an empty id or a blank API key, raise an ArgumentError before anything is sent. Every status is explained in the errors docs.

Built for Ruby apps

  • One client, many threads. A FlightByte::Client is safe to share between Puma threads and Sidekiq workers; create it once, in an initializer for example. Responses are frozen, so they can be cached and handed between threads. CI runs every Ruby from 3.1 to 4.0.
  • No dependencies. Only the standard library: net/http, openssl and json. Nothing to audit but this gem.
  • Your key stays on your server. An API key or a signing secret shipped inside a browser or mobile app can be pulled out of it by anyone who has the app. Flag images are the exception: countries.flag_url needs no key. On the server, inspect never shows the key and shows a signing secret masked, so neither lands in your logs.
  • Your key stays with the API. The client follows a redirect only for a read, and only on the API's own origin (scheme, host and port), so a misdirected answer cannot carry the key elsewhere and a write is never sent twice.
  • New API values don't break old code. A phase, status or change type added after this release is still a plain string, and a field added after it reads as a method like the others. The tests check every method, parameter and model against the API's OpenAPI document, so a field the API adds shows up as a failing test here first, not as a missing method in your code.
  • Zero stays apart from unknown. A field the API left out or sent as null reads as nil, so a delay of 0 and no delay reading are different things, and key? tells the two apart. A misspelt field raises NoMethodError instead of passing for a missing value.
  • Errors say what to do next. A number that flies twice comes back with its legs, a 429 with how long to wait, a 402 with the reason and when the allowance resets.
  • Quotas are visible. client.last_rate_limit holds the minute, day and month windows from the latest response's X-RateLimit-* headers.

Configuration

client = FlightByte::Client.new(
  api_key: ENV.fetch("FLIGHTBYTE_API_KEY"),
  base_url: "http://localhost:3000/v1",
  timeout: 10,
  user_agent: "my-app/1.2"
)
Option Default Meaning
api_key required Your API key, sent as x-api-key.
base_url https://api.flightbyte.dev/v1 API base URL, e.g. http://localhost:3000/v1 for a local API.
timeout 30 Seconds each request may take, connecting, redirects and response body included. 0 disables it; a call's own timeout: overrides it.
user_agent none Put in front of flightbyte-ruby/<version> in the user-agent header.

Requests go through Net::HTTP, so the usual HTTPS_PROXY, HTTP_PROXY and NO_PROXY environment variables apply.

Development

bundle install
bundle exec rake                  # RuboCop, the signature check and the tests
bundle exec rake sync_openapi     # refresh spec/openapi.json, then run the tests against it
node tool/webhook_vectors.mjs

The tests never touch the real API and need no key. They cover every method's request mapping, the error class for each status, redirects and timeouts against real local servers, the models against fixtures shaped like the API's JSON and against the API's OpenAPI document, the Rack receiver with Rack::Lint, and webhook verification against signatures made with Node's createHmac exactly as the API signs them. CI runs them on Ruby 3.1, 3.2, 3.3, 3.4 and 4.0, and builds and installs the gem.

How to add a field, an enum value or an endpoint is in CONTRIBUTING.md. Report security issues by email, as SECURITY.md explains, never in a public issue.

Project layout
lib/
  flightbyte.rb                  entry point, format_date and the helpers
  flightbyte/client.rb           FlightByte::Client and its options
  flightbyte/transport.rb        requests, headers, timeouts, redirects, error mapping
  flightbyte/resources/          flights, subscriptions, countries
  flightbyte/object.rb           FlightByte::Object, the read-only base of every response
  flightbyte/models.rb           a class for each of the API's shapes
  flightbyte/values.rb           the API's value lists
  flightbyte/errors.rb           FlightByte::Error and its subclasses
  flightbyte/webhook.rb          Webhook.verify, construct_event and sign
  flightbyte/webhook/rack_app.rb Webhook::RackApp, the Rack receiver
  flightbyte/rate_limit.rb       X-RateLimit-* headers
sig/flightbyte.rbs               RBS type signatures
spec/openapi.json                the API document the tests check against
test/fixtures/                   API-shaped JSON and signed webhook vectors
examples/                        a lookup from the terminal and a Rack receiver
tool/sync_openapi.rb             refreshes spec/openapi.json
tool/webhook_vectors.mjs         regenerates the signed vectors with Node, as the API signs
tool/release_notes.sh            a version's CHANGELOG.md section, for the GitHub release
Releasing
  1. Set VERSION in lib/flightbyte/version.rb; the gemspec reads it.
  2. Give the version its own ## <version> section in CHANGELOG.md; a test fails without it.
  3. Push a tag such as v1.0.1.

The release workflow checks that the tag, FlightByte::VERSION and the gemspec agree and that the changelog has the section, runs every check, publishes to RubyGems with trusted publishing unless that version is already there, and creates the GitHub release from the changelog section. Run it by hand from the Actions tab to rehearse: it builds the gem and publishes nothing.

License

MIT


FlightByte
FlightByte · Flight intelligence, byte by byte · flightbyte.dev

About

Official Ruby SDK for the FlightByte flight status API: live flight status, flight tracking and signed webhooks with a ready Rack receiver for Rails and Sinatra. Zero dependencies.

flightbyte.dev/docs

Topics

api-clientapi-wrapperaviationflight-apiflight-dataflight-statusflight-trackingflightsrackrailsrest-apirubyruby-gemruby-on-railsrubygemsdksinatrawebhookwebhookszero-dependency

Resources

Readme
MIT license

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.