-
Notifications
You must be signed in to change notification settings - Fork 6
/
airports.go
43 lines (35 loc) · 1.1 KB
/
airports.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2021-present Airheart, Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package duffel
import (
"context"
"net/url"
)
type (
AirportsClient interface {
ListAirports(ctx context.Context, params ...ListAirportsParams) *Iter[Airport]
GetAirport(ctx context.Context, id string) (*Airport, error)
}
ListAirportsParams struct {
IATACountryCode string `url:"iata_country_code,omitempty"`
}
)
func (a *API) ListAirports(ctx context.Context, params ...ListAirportsParams) *Iter[Airport] {
return newRequestWithAPI[ListAirportsParams, Airport](a).
Get("/air/airports").
WithParams(normalizeParams(params)...).
Iter(ctx)
}
func (a *API) GetAirport(ctx context.Context, id string) (*Airport, error) {
return newRequestWithAPI[EmptyPayload, Airport](a).
Getf("/air/airports/%s", id).
Single(ctx)
}
func (p ListAirportsParams) Encode(q url.Values) error {
if p.IATACountryCode != "" {
q.Set("iata_country_code", p.IATACountryCode)
}
return nil
}
var _ AirportsClient = (*API)(nil)