forked from airheartdev/duffel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpartialofferrequests.go
More file actions
93 lines (78 loc) · 3.86 KB
/
Copy pathpartialofferrequests.go
File metadata and controls
93 lines (78 loc) · 3.86 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package duffel
import (
"context"
"net/url"
)
const partialOsfferRequestIDPrefix = "prq_"
type (
PartialOfferRequestClient interface {
CreatePartialOfferRequest(ctx context.Context, requestInput PartialOfferRequestInput, requestOptions ...RequestOption) (*OfferRequest, error)
GetPartialOfferRequest(ctx context.Context, partialOfferRequestID string, options []GetPartialOfferRequestParams, requestOptions ...RequestOption) (*OfferRequest, error)
ListPartialOfferRequestFares(ctx context.Context, partialOfferRequestID string, options []ListPartialOfferRequestFaresParams, requestOptions ...RequestOption) (*OfferRequest, error)
}
PartialOfferRequestInput struct {
// The passengers who want to travel. If you specify an age for a passenger,
// the type may differ for the same passenger in different offers due to airline's different rules.
// e.g. one airline may treat a 14 year old as an adult, and another as a young adult.
// You may only specify an age or a type – not both.
Passengers []OfferRequestPassenger `json:"passengers" url:"-"`
// The slices that make up this offer request. One-way journeys can be expressed using one slice,
// whereas return trips will need two.
Slices []OfferRequestSlice `json:"slices" url:"-"`
// The cabin that the passengers want to travel in
CabinClass CabinClass `json:"cabin_class" url:"-"`
// The maximum number of connections within any slice of the offer.
// For example 0 means a direct flight which will have a single segment within each slice
// and 1 means a maximum of two segments within each slice of the offer.
MaxConnections *int `json:"max_connections,omitempty" url:"-"`
// The maximum amount of time in milliseconds to wait for each airline to respond
SupplierTimeout int `json:"-" url:"supplier_timeout,omitempty"`
}
GetPartialOfferRequestParams struct {
SelectedPartialOffer string `url:"selected_partial_offer"`
}
ListPartialOfferRequestFaresParams struct {
SelectedPartialOffer string `url:"selected_partial_offer"`
}
)
func (a *API) CreatePartialOfferRequest(ctx context.Context, requestInput PartialOfferRequestInput, requestOptions ...RequestOption) (*OfferRequest, error) {
return newRequestWithAPI[PartialOfferRequestInput, OfferRequest](a).
Post("/air/partial_offer_requests", &requestInput).
WithOptions(requestOptions...).
Single(ctx)
}
func (a *API) GetPartialOfferRequest(ctx context.Context, partialOfferRequestID string, params []GetPartialOfferRequestParams, requestOptions ...RequestOption) (*OfferRequest, error) {
if err := validateID(partialOfferRequestID, partialOsfferRequestIDPrefix); err != nil {
return nil, err
}
return newRequestWithAPI[GetPartialOfferRequestParams, OfferRequest](a).
Getf("/air/partial_offer_requests/%s", partialOfferRequestID).
WithParams(normalizeParams(params)...).
WithOptions(requestOptions...).
Single(ctx)
}
func (a *API) ListPartialOfferRequestFares(ctx context.Context, partialOfferRequestID string, params []ListPartialOfferRequestFaresParams, requestOptions ...RequestOption) (*OfferRequest, error) {
if err := validateID(partialOfferRequestID, partialOsfferRequestIDPrefix); err != nil {
return nil, err
}
return newRequestWithAPI[ListPartialOfferRequestFaresParams, OfferRequest](a).
Getf("/air/partial_offer_requests/%s/fares", partialOfferRequestID).
WithParams(normalizeParams(params)...).
WithOptions(requestOptions...).
Single(ctx)
}
var _ PartialOfferRequestClient = (*API)(nil)
func (o GetPartialOfferRequestParams) Encode(q url.Values) error {
if o.SelectedPartialOffer != "" {
q.Set("selected_partial_offer[]", o.SelectedPartialOffer)
}
return nil
}
func (o ListPartialOfferRequestFaresParams) Encode(q url.Values) error {
q.Add("selected_partial_offer[]", o.SelectedPartialOffer)
return nil
}
// Encode implements the ParamEncoder interface.
func (o PartialOfferRequestInput) Encode(q url.Values) error {
return nil
}