-
Notifications
You must be signed in to change notification settings - Fork 6
/
places.go
51 lines (42 loc) · 1.67 KB
/
places.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
44
45
46
47
48
49
50
51
// 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"
type (
PlacesClient interface {
PlaceSuggestions(ctx context.Context, query string) ([]*Place, error)
Cities(ctx context.Context) *Iter[City]
City(ctx context.Context, id string) (*City, error)
}
Place struct {
ID string `json:"id"`
Airports []*Airport `json:"airports"`
City *City `json:"city"`
CityName string `json:"city_name"`
CountryName string `json:"country_name"`
IATACityCode string `json:"iata_city_code"`
IATACode string `json:"iata_code"`
IATACountryCode string `json:"iata_country_code"`
ICAOCode string `json:"icao_code"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Name string `json:"name"`
TimeZone string `json:"time_zone"`
Type PlaceType `json:"type"`
}
PlaceType string
)
const PlaceTypeAirport = "airport"
const PlaceTypeCity = "city"
func (a *API) PlaceSuggestions(ctx context.Context, query string) ([]*Place, error) {
return newRequestWithAPI[EmptyPayload, Place](a).
Get("/places/suggestions").WithParam("query", query).
Slice(ctx)
}
func (a *API) Cities(ctx context.Context) *Iter[City] {
return newRequestWithAPI[EmptyPayload, City](a).Get("/air/cities").Iter(ctx)
}
func (a *API) City(ctx context.Context, id string) (*City, error) {
return newRequestWithAPI[EmptyPayload, City](a).Getf("/air/cities/%s", id).Single(ctx)
}