Skip to content

Commit 910f27a

Browse files
Merge pull request #12 from airheartdev/feature/better-seatmap-support
Fixing Seat map support
2 parents f6c74df + 2a44f4c commit 910f27a

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

examples/offer-requests/main.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import (
1717
func main() {
1818
apiToken := os.Getenv("DUFFEL_TOKEN")
1919
client := duffel.New(apiToken, duffel.WithDebug())
20+
ctx := context.Background()
2021

2122
// childAge := 1
2223

23-
data, err := client.CreateOfferRequest(context.Background(), duffel.OfferRequestInput{
24+
data, err := client.CreateOfferRequest(ctx, duffel.OfferRequestInput{
2425
ReturnOffers: true,
2526

2627
Passengers: []duffel.OfferRequestPassenger{
@@ -70,6 +71,10 @@ func main() {
7071
fmt.Println()
7172

7273
for _, offer := range data.Offers {
74+
// if offer.Owner.IATACode != "AA" {
75+
// continue
76+
// }
77+
7378
fmt.Printf("===> Offer %s from %s\n Passengers: ", offer.ID, offer.Owner.Name)
7479
for i, p := range offer.Passengers {
7580
fmt.Printf("(%s) %s %s", p.Type, p.GivenName, p.FamilyName)
@@ -92,7 +97,28 @@ func main() {
9297
}
9398

9499
fmt.Printf(" 🛬 %s • %s\n", s.FareBrandName, time.Duration(s.Duration).String())
100+
95101
}
102+
103+
// seats, err := client.SeatmapForOffer(ctx, offer)
104+
// if err != nil {
105+
// log.Fatalln(err)
106+
// }
107+
108+
// for _, seat := range seats {
109+
// for _, cab := range seat.Cabins {
110+
// for _, row := range cab.Rows {
111+
// fmt.Println()
112+
// for _, sec := range row.Sections {
113+
// fmt.Println()
114+
// for _, el := range sec.Elements {
115+
// fmt.Printf("%s ", el.Designator)
116+
// }
117+
// }
118+
// }
119+
// }
120+
// }
121+
96122
fmt.Println()
97123
}
98124
}

offers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ type (
3737
Owner Airline `json:"owner"`
3838
Slices []Slice `json:"slices"`
3939
Passengers []OfferRequestPassenger `json:"passengers"`
40+
Partial bool `json:"partial"`
4041
PassengerIdentityDocumentsRequired bool `json:"passenger_identity_documents_required"`
4142
PaymentRequirements OfferPaymentRequirement `json:"payment_requirements"`
43+
AvailableServices []Service `json:"available_services"`
4244
}
4345

4446
OfferPaymentRequirement struct {

seatmaps.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ type (
8080
}
8181

8282
SeatmapClient interface {
83-
// GetSeatmaps returns an iterator for the seatmaps of a given Offer.
84-
GetSeatmaps(ctx context.Context, offerID string) *Iter[Seatmap]
83+
// GetSeatmap returns an iterator for the seatmaps of a given Offer.
84+
GetSeatmap(ctx context.Context, offerID string) ([]*Seatmap, error)
85+
SeatmapForOffer(ctx context.Context, offer Offer) ([]*Seatmap, error)
8586
}
8687
)
8788

@@ -100,11 +101,15 @@ func (e ElementType) String() string {
100101
return string(e)
101102
}
102103

103-
func (a *API) GetSeatmaps(ctx context.Context, offerID string) *Iter[Seatmap] {
104+
func (a *API) SeatmapForOffer(ctx context.Context, offer Offer) ([]*Seatmap, error) {
105+
return a.GetSeatmap(ctx, offer.ID)
106+
}
107+
108+
func (a *API) GetSeatmap(ctx context.Context, offerID string) ([]*Seatmap, error) {
104109
return newRequestWithAPI[EmptyPayload, Seatmap](a).
105110
Get("/air/seat_maps").
106111
WithParam("offer_id", offerID).
107-
Iter(ctx)
112+
Slice(ctx)
108113
}
109114

110115
func (s *SectionService) TotalAmount() currency.Amount {

seatmaps_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,18 @@ func TestGetSeatmaps(t *testing.T) {
3030
ctx := context.TODO()
3131

3232
client := New("duffel_test_123")
33-
iter := client.GetSeatmaps(ctx, "off_00009htYpSCXrwaB9DnUm0")
34-
35-
iter.Next()
36-
data := iter.Current()
37-
err := iter.Err()
38-
reqID, _ := iter.LastRequestID()
39-
33+
seats, err := client.GetSeatmap(ctx, "off_00009htYpSCXrwaB9DnUm0")
4034
a.NoError(err)
41-
a.NotNil(data)
35+
reqID, _ := client.LastRequestID()
36+
37+
a.NotNil(seats)
4238
a.Equal("FvxRwfnMtKgc0EwCCoXE", reqID)
4339

44-
a.Equal("sea_00003hthlsHZ8W4LxXjkzo", data.ID)
45-
a.Equal("seg_00009htYpSCXrwaB9Dn456", data.SegmentID)
46-
a.Equal("sli_00009htYpSCXrwaB9Dn123", data.SliceID)
40+
seat := seats[0]
41+
a.Equal("sea_00003hthlsHZ8W4LxXjkzo", seat.ID)
42+
a.Equal("seg_00009htYpSCXrwaB9Dn456", seat.SegmentID)
43+
a.Equal("sli_00009htYpSCXrwaB9Dn123", seat.SliceID)
4744

48-
serviceAmount := data.Cabins[0].Rows[0].Sections[0].Elements[0].AvailableServices[0].TotalAmount().String()
45+
serviceAmount := seat.Cabins[0].Rows[0].Sections[0].Elements[0].AvailableServices[0].TotalAmount().String()
4946
a.Equal("30.00 GBP", serviceAmount)
5047
}

0 commit comments

Comments
 (0)