flightbyte 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,546 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FlightByte
4
+ # The shapes the API answers with. Class names follow the API's OpenAPI
5
+ # document. Each reader returns the value exactly as the API sent it:
6
+ # timestamps are ISO 8601 strings, enums are strings, and a field the API
7
+ # left out or sent as `null` is `nil`.
8
+
9
+ # A country as it appears inside an airport.
10
+ class CountryRef < Object
11
+ # @!attribute [r] code
12
+ # @return [String] ISO 3166-1 alpha-2 code, for example `TR`.
13
+ field "code"
14
+ # @!attribute [r] name
15
+ # @return [String] Country name.
16
+ field "name"
17
+ # @!attribute [r] emoji
18
+ # @return [String] Flag emoji.
19
+ field "emoji"
20
+ # @!attribute [r] flag_svg
21
+ # @return [String] Absolute URL of the 4:3 SVG flag.
22
+ field "flagSvg"
23
+ # @!attribute [r] flag_svg_square
24
+ # @return [String] Absolute URL of the 1:1 SVG flag.
25
+ field "flagSvgSquare"
26
+ end
27
+
28
+ # A country from {Countries#list} and {Countries#get}.
29
+ class Country < CountryRef
30
+ # @!attribute [r] alpha2
31
+ # @return [String] ISO 3166-1 alpha-2 code.
32
+ field "alpha2"
33
+ # @!attribute [r] has_flag
34
+ # @return [Boolean] Whether a flag image exists for the country. Also `has_flag?`.
35
+ field "hasFlag", predicate: true
36
+ end
37
+
38
+ # An airport.
39
+ class AirportRef < Object
40
+ # @!attribute [r] iata
41
+ # @return [String] IATA code, for example `IST`.
42
+ field "iata"
43
+ # @!attribute [r] icao
44
+ # @return [String, nil] ICAO code, for example `LTFM`.
45
+ field "icao"
46
+ # @!attribute [r] code
47
+ # @return [String, nil] The upstream's own airport code; it may differ from `iata`.
48
+ field "code"
49
+ # @!attribute [r] name
50
+ # @return [String] Airport name.
51
+ field "name"
52
+ # @!attribute [r] city
53
+ # @return [String, nil] City.
54
+ field "city"
55
+ # @!attribute [r] state
56
+ # @return [String, nil] State or region.
57
+ field "state"
58
+ # @!attribute [r] country
59
+ # @return [CountryRef] Country.
60
+ field "country", CountryRef
61
+ # @!attribute [r] timezone
62
+ # @return [String, nil] IANA time zone, for example `Europe/Istanbul`.
63
+ field "timezone"
64
+ end
65
+
66
+ # A point in time, in UTC and in the airport's local time.
67
+ class FlightTime < Object
68
+ # @!attribute [r] utc
69
+ # @return [String] The instant, ISO 8601 in UTC.
70
+ field "utc"
71
+ # @!attribute [r] local
72
+ # @return [String, nil] Airport-local wall time without an offset, for
73
+ # example `2026-09-08T12:10:00.000`. Pair it with the airport's time zone.
74
+ field "local"
75
+ # @!attribute [r] timezone
76
+ # @return [String, nil] Time zone abbreviation, for example `EEST`.
77
+ field "timezone"
78
+ end
79
+
80
+ # The gate and runway times of a departure or an arrival.
81
+ class EndpointTimes < Object
82
+ # @!attribute [r] scheduled_gate
83
+ # @return [FlightTime, nil] Scheduled gate time.
84
+ field "scheduledGate", FlightTime
85
+ # @!attribute [r] estimated_gate
86
+ # @return [FlightTime, nil] Estimated gate time.
87
+ field "estimatedGate", FlightTime
88
+ # @!attribute [r] actual_gate
89
+ # @return [FlightTime, nil] Actual gate time.
90
+ field "actualGate", FlightTime
91
+ # @!attribute [r] scheduled_runway
92
+ # @return [FlightTime, nil] Scheduled runway time.
93
+ field "scheduledRunway", FlightTime
94
+ # @!attribute [r] estimated_runway
95
+ # @return [FlightTime, nil] Estimated runway time.
96
+ field "estimatedRunway", FlightTime
97
+ # @!attribute [r] actual_runway
98
+ # @return [FlightTime, nil] Actual runway time.
99
+ field "actualRunway", FlightTime
100
+
101
+ # The best known gate time: actual, else estimated, else scheduled.
102
+ #
103
+ # @return [FlightTime, nil]
104
+ def best_gate
105
+ FlightByte.best_gate_time(self)
106
+ end
107
+ end
108
+
109
+ # The departure or arrival side of a flight.
110
+ class FlightEndpoint < Object
111
+ # @!attribute [r] airport
112
+ # @return [AirportRef] The airport.
113
+ field "airport", AirportRef
114
+ # @!attribute [r] terminal
115
+ # @return [String, nil] Terminal.
116
+ field "terminal"
117
+ # @!attribute [r] gate
118
+ # @return [String, nil] Gate.
119
+ field "gate"
120
+ # @!attribute [r] baggage
121
+ # @return [String, nil] Baggage carousel, on arrival.
122
+ field "baggage"
123
+ # @!attribute [r] times
124
+ # @return [EndpointTimes] Gate and runway times.
125
+ field "times", EndpointTimes
126
+ # @!attribute [r] best_time_utc
127
+ # @return [String, nil] Best known time in UTC: actual, else estimated, else scheduled.
128
+ field "bestTimeUtc"
129
+ # @!attribute [r] delay_minutes
130
+ # @return [Integer, nil] Gate delay in minutes; negative when early.
131
+ field "delayMinutes"
132
+ end
133
+
134
+ # The marketing carrier.
135
+ class CarrierRef < Object
136
+ # @!attribute [r] iata
137
+ # @return [String] IATA code, for example `TK`.
138
+ field "iata"
139
+ # @!attribute [r] icao
140
+ # @return [String, nil] ICAO code, for example `THY`.
141
+ field "icao"
142
+ # @!attribute [r] name
143
+ # @return [String] Airline name.
144
+ field "name"
145
+ end
146
+
147
+ # A codeshare flight number sold on the same flight.
148
+ class CodeshareRef < Object
149
+ # @!attribute [r] carrier
150
+ # @return [String] Carrier code.
151
+ field "carrier"
152
+ # @!attribute [r] name
153
+ # @return [String] Carrier name.
154
+ field "name"
155
+ # @!attribute [r] flight_number
156
+ # @return [String] Flight number.
157
+ field "flightNumber"
158
+ end
159
+
160
+ # The status of a flight.
161
+ class FlightStatusInfo < Object
162
+ # @!attribute [r] code
163
+ # @return [String] Upstream status code: `S`, `A`, `L`, `C`, `D`, `R`, `U` or `NO`.
164
+ field "code"
165
+ # @!attribute [r] label
166
+ # @return [String] Human-readable status, for example `Arrived`.
167
+ field "label"
168
+ # @!attribute [r] description
169
+ # @return [String, nil] Longer description, for example `On time`.
170
+ field "description"
171
+ # @!attribute [r] color
172
+ # @return [String, nil] Suggested color, for example `green`.
173
+ field "color"
174
+ # @!attribute [r] phase
175
+ # @return [String] The lifecycle phase; one of {FLIGHT_PHASES}, or a newer one.
176
+ field "phase"
177
+ # @!attribute [r] delayed
178
+ # @return [Boolean] Whether the flight is delayed. Also `delayed?`.
179
+ field "delayed", predicate: true
180
+ # @!attribute [r] cancelled
181
+ # @return [Boolean] Whether the flight is cancelled. Also `cancelled?`.
182
+ field "cancelled", predicate: true
183
+ # @!attribute [r] diverted
184
+ # @return [Boolean] Whether the flight is diverted. Also `diverted?`.
185
+ field "diverted", predicate: true
186
+ # @!attribute [r] departure_gate_delay_minutes
187
+ # @return [Integer, nil] Departure gate delay in minutes.
188
+ field "departureGateDelayMinutes"
189
+ # @!attribute [r] arrival_gate_delay_minutes
190
+ # @return [Integer, nil] Arrival gate delay in minutes.
191
+ field "arrivalGateDelayMinutes"
192
+
193
+ # Whether the flight is finished: arrived, cancelled, diverted or redirected.
194
+ def terminal?
195
+ FlightByte.terminal_phase?(phase)
196
+ end
197
+ end
198
+
199
+ # The aircraft.
200
+ class EquipmentInfo < Object
201
+ # @!attribute [r] tail_number
202
+ # @return [String, nil] Registration, for example `TC-LTP`.
203
+ field "tailNumber"
204
+ # @!attribute [r] iata
205
+ # @return [String, nil] IATA aircraft type, for example `32Q`.
206
+ field "iata"
207
+ # @!attribute [r] name
208
+ # @return [String, nil] Aircraft name, for example `Airbus A321neo`.
209
+ field "name"
210
+ # @!attribute [r] source
211
+ # @return [String, nil] Where the data came from, for example `Actual`.
212
+ field "source"
213
+ end
214
+
215
+ # Block times in minutes.
216
+ class DurationInfo < Object
217
+ # @!attribute [r] scheduled_minutes
218
+ # @return [Integer, nil] Scheduled duration.
219
+ field "scheduledMinutes"
220
+ # @!attribute [r] estimated_minutes
221
+ # @return [Integer, nil] Estimated duration.
222
+ field "estimatedMinutes"
223
+ # @!attribute [r] actual_minutes
224
+ # @return [Integer, nil] Actual duration.
225
+ field "actualMinutes"
226
+ end
227
+
228
+ # One entry of a flight's upstream history.
229
+ class TimelineEntry < Object
230
+ # @!attribute [r] occurred_at
231
+ # @return [String] When it happened, ISO 8601.
232
+ field "occurredAt"
233
+ # @!attribute [r] title
234
+ # @return [String] Title, for example `Time Adjustment`.
235
+ field "title"
236
+ # @!attribute [r] source
237
+ # @return [String, nil] Source, for example `Airline`.
238
+ field "source"
239
+ # @!attribute [r] events
240
+ # @return [Array<String>] What changed, as sentences.
241
+ field "events"
242
+ end
243
+
244
+ # A leg flown under the same flight number on the same date. Flight numbers
245
+ # are not unique per day, so the API lists every leg and marks the one the
246
+ # snapshot describes with `selected`.
247
+ class FlightLegRef < Object
248
+ # @!attribute [r] provider_flight_id
249
+ # @return [String, nil] Upstream flight id; pass it as `flight_id:` to select this leg.
250
+ field "providerFlightId"
251
+ # @!attribute [r] carrier
252
+ # @return [String, nil] Operating carrier code.
253
+ field "carrier"
254
+ # @!attribute [r] departure_iata
255
+ # @return [String] Origin IATA code.
256
+ field "departureIata"
257
+ # @!attribute [r] arrival_iata
258
+ # @return [String] Destination IATA code.
259
+ field "arrivalIata"
260
+ # @!attribute [r] scheduled_departure_local
261
+ # @return [String, nil] Scheduled local departure, `HH:mm`.
262
+ field "scheduledDepartureLocal"
263
+ # @!attribute [r] scheduled_arrival_local
264
+ # @return [String, nil] Scheduled local arrival, `HH:mm`.
265
+ field "scheduledArrivalLocal"
266
+ # @!attribute [r] selected
267
+ # @return [Boolean] Whether this is the leg the snapshot describes. Also `selected?`.
268
+ field "selected", predicate: true
269
+ end
270
+
271
+ # Everything known about one flight leg at one moment, from {Flights#get}.
272
+ class FlightSnapshot < Object
273
+ # @!attribute [r] flight_key
274
+ # @return [String] Stable key, for example `TK1848:2026-09-08` or `TK1:2026-09-08@IST-JFK`.
275
+ field "flightKey"
276
+ # @!attribute [r] carrier_code
277
+ # @return [String] Carrier code from the request, for example `TK`.
278
+ field "carrierCode"
279
+ # @!attribute [r] flight_number
280
+ # @return [String] Flight number without leading zeros, for example `1848`.
281
+ field "flightNumber"
282
+ # @!attribute [r] date
283
+ # @return [String] Local departure date at the origin, `YYYY-MM-DD`.
284
+ field "date"
285
+ # @!attribute [r] provider_flight_id
286
+ # @return [String, nil] Upstream flight id.
287
+ field "providerFlightId"
288
+ # @!attribute [r] fetched_at
289
+ # @return [String] When the API fetched this data from upstream, ISO 8601.
290
+ field "fetchedAt"
291
+ # @!attribute [r] carrier
292
+ # @return [CarrierRef] Marketing carrier.
293
+ field "carrier", CarrierRef
294
+ # @!attribute [r] operated_by
295
+ # @return [String, nil] Operating carrier name, when different.
296
+ field "operatedBy"
297
+ # @!attribute [r] codeshares
298
+ # @return [Array<CodeshareRef>] Codeshare flight numbers.
299
+ field "codeshares", [CodeshareRef]
300
+ # @!attribute [r] departure
301
+ # @return [FlightEndpoint] Departure side.
302
+ field "departure", FlightEndpoint
303
+ # @!attribute [r] arrival
304
+ # @return [FlightEndpoint] Arrival side.
305
+ field "arrival", FlightEndpoint
306
+ # @!attribute [r] diverted
307
+ # @return [FlightEndpoint, nil] Where the flight actually went, when diverted.
308
+ field "diverted", FlightEndpoint
309
+ # @!attribute [r] status
310
+ # @return [FlightStatusInfo] Status.
311
+ field "status", FlightStatusInfo
312
+ # @!attribute [r] equipment
313
+ # @return [EquipmentInfo] Aircraft.
314
+ field "equipment", EquipmentInfo
315
+ # @!attribute [r] duration
316
+ # @return [DurationInfo] Block times.
317
+ field "duration", DurationInfo
318
+ # @!attribute [r] timeline
319
+ # @return [Array<TimelineEntry>] Upstream history, newest first.
320
+ field "timeline", [TimelineEntry]
321
+ # @!attribute [r] alternates
322
+ # @return [Array<FlightLegRef>] Every leg flown under this flight number on this date.
323
+ field "alternates", [FlightLegRef]
324
+ # @!attribute [r] fingerprint
325
+ # @return [String] Hash over the change-relevant fields.
326
+ field "fingerprint"
327
+ # @!attribute [r] cached
328
+ # @return [Boolean, nil] Whether a lookup was answered from the API's cache.
329
+ # Sent with lookups, not inside webhook events. Also `cached?`.
330
+ field "cached", predicate: true
331
+ end
332
+
333
+ # The response of {Flights#timeline}.
334
+ class FlightTimeline < Object
335
+ # @!attribute [r] flight_key
336
+ # @return [String] The flight's key.
337
+ field "flightKey"
338
+ # @!attribute [r] count
339
+ # @return [Integer] The number of entries.
340
+ field "count"
341
+ # @!attribute [r] data
342
+ # @return [Array<TimelineEntry>] History entries, newest first.
343
+ field "data", [TimelineEntry]
344
+ end
345
+
346
+ # A watched flight: the API polls it and posts a signed webhook to
347
+ # `webhook_url` whenever something about it changes.
348
+ class Subscription < Object
349
+ # @!attribute [r] id
350
+ # @return [String] Id, for example `sub_7Kd91mQx0Zb2c3d4e5f6`.
351
+ field "id"
352
+ # @!attribute [r] status
353
+ # @return [String] Lifecycle status; one of {SUBSCRIPTION_STATUSES}, or a newer one.
354
+ field "status"
355
+ # @!attribute [r] flight_key
356
+ # @return [String] The watched flight's key, for example `TK1848:2026-09-08`.
357
+ field "flightKey"
358
+ # @!attribute [r] carrier
359
+ # @return [String] Carrier code.
360
+ field "carrier"
361
+ # @!attribute [r] flight_number
362
+ # @return [String] Flight number.
363
+ field "flightNumber"
364
+ # @!attribute [r] date
365
+ # @return [String] Local departure date at the origin, `YYYY-MM-DD`.
366
+ field "date"
367
+ # @!attribute [r] webhook_url
368
+ # @return [String] Where webhooks are posted.
369
+ field "webhookUrl"
370
+ # @!attribute [r] secret_hint
371
+ # @return [String, nil] The masked signing secret, for example `whsec_AbCdE...wxyz`.
372
+ field "secretHint"
373
+ # @!attribute [r] secret
374
+ # @return [String, nil] The full signing secret. Only the creation response
375
+ # carries it; read it again with {Subscriptions#secret}.
376
+ field "secret"
377
+ # @!attribute [r] headers
378
+ # @return [Hash{String => String}, nil] Extra headers sent with every delivery.
379
+ field "headers", :map
380
+ # @!attribute [r] events
381
+ # @return [Array<String>] The change types that trigger a webhook; see {FLIGHT_CHANGE_TYPES}.
382
+ field "events"
383
+ # @!attribute [r] delay_threshold_minutes
384
+ # @return [Integer] Delay swings smaller than this many minutes are ignored.
385
+ field "delayThresholdMinutes"
386
+ # @!attribute [r] metadata
387
+ # @return [Hash{String => String}, nil] Your own data, echoed back in every webhook.
388
+ field "metadata", :map
389
+ # @!attribute [r] created_at
390
+ # @return [String] When it was created, ISO 8601.
391
+ field "createdAt"
392
+ # @!attribute [r] updated_at
393
+ # @return [String] When it last changed, ISO 8601.
394
+ field "updatedAt"
395
+ # @!attribute [r] last_polled_at
396
+ # @return [String, nil] When the flight was last polled, ISO 8601.
397
+ field "lastPolledAt"
398
+ # @!attribute [r] last_change_at
399
+ # @return [String, nil] When a change was last detected, ISO 8601.
400
+ field "lastChangeAt"
401
+ # @!attribute [r] last_delivery_at
402
+ # @return [String, nil] When a webhook was last delivered, ISO 8601.
403
+ field "lastDeliveryAt"
404
+ # @!attribute [r] delivered_count
405
+ # @return [Integer] Webhooks delivered.
406
+ field "deliveredCount"
407
+ # @!attribute [r] failed_count
408
+ # @return [Integer] Webhook attempts that failed.
409
+ field "failedCount"
410
+ # @!attribute [r] flight_resolved
411
+ # @return [Boolean] `false` while the flight is not found upstream yet. Also `flight_resolved?`.
412
+ field "flightResolved", predicate: true
413
+ # @!attribute [r] status_reason
414
+ # @return [String, nil] Why the subscription was suspended or completed.
415
+ field "statusReason"
416
+ end
417
+
418
+ # The response of {Subscriptions#create}.
419
+ class CreatedSubscription < Subscription
420
+ # @!attribute [r] reused
421
+ # @return [Boolean] `true` when an earlier request with the same idempotency
422
+ # key, within 24 hours, was replayed: the original subscription is
423
+ # returned and nothing new is created or billed. Also `reused?`.
424
+ field "reused", predicate: true
425
+ # @!attribute [r] flight
426
+ # @return [FlightSnapshot, nil] The flight as first seen, when it was found. Absent when reused.
427
+ field "flight", FlightSnapshot
428
+ end
429
+
430
+ # One page of {Subscriptions#list}.
431
+ class SubscriptionPage < Object
432
+ # @!attribute [r] total
433
+ # @return [Integer] The number of subscriptions matching the filters.
434
+ field "total"
435
+ # @!attribute [r] limit
436
+ # @return [Integer] The page size used.
437
+ field "limit"
438
+ # @!attribute [r] offset
439
+ # @return [Integer] The number of subscriptions skipped.
440
+ field "offset"
441
+ # @!attribute [r] data
442
+ # @return [Array<Subscription>] The subscriptions on this page, newest first.
443
+ field "data", [Subscription]
444
+ end
445
+
446
+ # One webhook delivery attempt, from {Subscriptions#deliveries}.
447
+ class DeliveryRecord < Object
448
+ # @!attribute [r] event_id
449
+ # @return [String] The delivered event's id.
450
+ field "eventId"
451
+ # @!attribute [r] attempt
452
+ # @return [Integer] Attempt number, starting at 1.
453
+ field "attempt"
454
+ # @!attribute [r] status
455
+ # @return [String] The outcome; one of {DELIVERY_STATUSES}, or a newer one.
456
+ field "status"
457
+ # @!attribute [r] http_status
458
+ # @return [Integer, nil] The receiver's HTTP status, when it answered.
459
+ field "httpStatus"
460
+ # @!attribute [r] error
461
+ # @return [String, nil] What went wrong, when the attempt failed.
462
+ field "error"
463
+ # @!attribute [r] duration_ms
464
+ # @return [Integer] How long the attempt took, in milliseconds.
465
+ field "durationMs"
466
+ # @!attribute [r] at
467
+ # @return [String] When the attempt was made, ISO 8601.
468
+ field "at"
469
+ # @!attribute [r] change_types
470
+ # @return [Array<String>] The change types the event carried.
471
+ field "changeTypes"
472
+ end
473
+
474
+ # One change inside a `flight.updated` event.
475
+ class FlightChange < Object
476
+ # @!attribute [r] type
477
+ # @return [String] What changed; one of {FLIGHT_CHANGE_TYPES}, or a newer one.
478
+ field "type"
479
+ # @!attribute [r] path
480
+ # @return [String] Dotted path into the snapshot, for example `departure.gate`.
481
+ field "path"
482
+ # @!attribute [r] from
483
+ # @return [String, Numeric, Boolean, nil] The old value. Times are ISO 8601 UTC strings.
484
+ field "from"
485
+ # @!attribute [r] to
486
+ # @return [String, Numeric, Boolean, nil] The new value. Times are ISO 8601 UTC strings.
487
+ field "to"
488
+ # @!attribute [r] message
489
+ # @return [String] A sentence describing the change.
490
+ field "message"
491
+ # @!attribute [r] delta_minutes
492
+ # @return [Integer, nil] Signed minute delta, for time changes.
493
+ field "deltaMinutes"
494
+ end
495
+
496
+ # A webhook event, as posted to your receiver and as listed by
497
+ # {Subscriptions#events}.
498
+ class WebhookEvent < Object
499
+ # @!attribute [r] id
500
+ # @return [String] Event id, `evt_<uuid>`. The same across delivery retries: deduplicate on it.
501
+ field "id"
502
+ # @!attribute [r] type
503
+ # @return [String] The event type; one of {WEBHOOK_EVENT_TYPES}, or a newer one.
504
+ field "type"
505
+ # @!attribute [r] created_at
506
+ # @return [String] When the event was created, ISO 8601.
507
+ field "createdAt"
508
+ # @!attribute [r] subscription_id
509
+ # @return [String] The subscription it belongs to.
510
+ field "subscriptionId"
511
+ # @!attribute [r] flight_key
512
+ # @return [String] The flight's key.
513
+ field "flightKey"
514
+ # @!attribute [r] flight
515
+ # @return [FlightSnapshot, nil] The flight after the change. Missing on some lifecycle events.
516
+ field "flight", FlightSnapshot
517
+ # @!attribute [r] changes
518
+ # @return [Array<FlightChange>] What changed. Empty except on `flight.updated`.
519
+ field "changes", [FlightChange]
520
+ # @!attribute [r] previous_fetched_at
521
+ # @return [String, nil] When the previous snapshot was fetched, on `flight.updated`.
522
+ field "previousFetchedAt"
523
+ # @!attribute [r] metadata
524
+ # @return [Hash{String => String}, nil] The subscription's metadata.
525
+ field "metadata", :map
526
+ end
527
+
528
+ # One of the legs listed by an ambiguous-flight {BadRequestError}.
529
+ class AmbiguousLeg < Object
530
+ # @!attribute [r] origin
531
+ # @return [String] Origin IATA code.
532
+ field "origin"
533
+ # @!attribute [r] destination
534
+ # @return [String] Destination IATA code.
535
+ field "destination"
536
+ # @!attribute [r] carrier
537
+ # @return [String, nil] Operating carrier.
538
+ field "carrier"
539
+ # @!attribute [r] scheduled_departure_local
540
+ # @return [String, nil] Scheduled local departure, `HH:mm`.
541
+ field "scheduledDepartureLocal"
542
+ # @!attribute [r] flight_id
543
+ # @return [String, nil] Upstream flight id.
544
+ field "flightId"
545
+ end
546
+ end