-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflight.go
143 lines (135 loc) · 7.41 KB
/
flight.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package kiwi
import (
"github.com/google/go-querystring/query"
)
// Parameters represents all URI parameters that can be passed to the Kiwi API
type Parameters struct {
FlyFrom string `url:"flyFrom,omitempty"`
To string `url:"to,omitempty"`
DateFrom string `url:"dateFrom,omitempty"`
DateTo string `url:"dateTo,omitempty"`
LongitudeFrom float32 `url:"longitudeFrom,omitempty"`
LatitudeFrom float32 `url:"latitudeFrom,omitempty"`
RadiusFrom int `url:"radiusFrom,omitempty"`
LongitudeTo float32 `url:"longitudeTo,omitempty"`
LatitudeTo float32 `url:"latitudeTo,omitempty"`
RadiusTo int `url:"radiusTo,omitempty"`
DaysInDestinationFrom int `url:"daysInDestinationFrom,omitempty"`
DaysInDestinationTo int `url:"daysInDestinationTo,omitempty"`
ReturnFrom string `url:"returnFrom,omitempty"`
ReturnTo string `url:"returnTo,omitempty"`
MaxFlyDuration int `url:"maxFlyDuration,omitempty"`
TypeFlight string `url:"typeFlight,omitempty"`
OneForCity bool `url:"oneforcity,omitempty"`
OnePerDate bool `url:"one_per_date,omitempty"`
Passengers int `url:"passengers,omitempty"`
Adults int `url:"adults,omitempty"`
Children int `url:"children,omitempty"`
Infants int `url:"infants,omitempty"`
FlyDays []int `url:"flyDays,omitempty"`
FlyDaysType string `url:"flyDaysType,omitempty"`
ReturnFlyDays []int `url:"returnFlyDays,omitempty"`
ReturnFlyDaysType string `url:"returnFlyDaysType,omitempty"`
OnlyWorkingDays bool `url:"onlyWorkingDays,omitempty"`
OnlyWeekends bool `url:"onlyWeekends,omitempty"`
DirectFlights bool `url:"directFlights,omitempty"`
Partner string `url:"partner,omitempty"`
PartnerMarket string `url:"partner_market,omitempty"`
Currency string `url:"curr,omitempty"`
Locale string `url:"locale,omitempty"`
PriceFrom int `url:"price_from,omitempty"`
PriceTo int `url:"price_to,omitempty"`
DepartureTimeFrom string `url:"dtimefrom,omitempty"`
DepartureTimeTo string `url:"dtimeto,omitempty"`
ArrivalTimeFrom string `url:"atimefrom,omitempty"`
ArrivalTimeTo string `url:"atimeto,omitempty"`
ReturnDepartureTimeFrom string `url:"returndtimefrom,omitempty"`
ReturnDepartureTimeTo string `url:"returndtimeto,omitempty"`
ReturnArrivalTimeFrom string `url:"returnatimefrom,omitempty"`
ReturnArrivalTimeTo string `url:"returnatimeto,omitempty"`
StopoverFrom string `url:"stopoverfrom,omitempty"`
StopoverTo string `url:"stopoverto,omitempty"`
MaxStopovers int `url:"maxstopovers,omitempty"`
ConnectionsOnDifferentAirport int `url:"connectionsOnDifferentAirport,omitempty"`
ReturnFromDifferentAirport int `url:"returnFromDifferentAirport,omitempty"`
ReturnToDifferentAirport int `url:"returnToDifferentAirport,omitempty"`
InnerLimit int `url:"innerLimit,omitempty"`
SelectedAirlines string `url:"selectedAirlines,omitempty"`
SelectedStopoverAirports bool `url:"selectedStopoverAirports,omitempty"`
SelectedAirlinesExclude bool `url:"selectedAirlinesExclude,omitempty"`
SelectedStopoverAirportsExclude string `url:"selectedStopoverAirportsExclude,omitempty"`
Offset int `url:"offset,omitempty"`
Limit int `url:"limit,omitempty"`
Sort string `url:"sort,omitempty"`
Asc int `url:"asc,omitempty"`
Version int `url:"v,omitempty"`
XML int `url:"xml,omitempty"`
}
// Response has the information of different flights
type Response struct {
SearchParameters map[string]string `json:"search_params"`
Time int `json:"time"`
Currency string `json:"currency"`
CurrencyRate float32 `json:"currency_rate"`
Flights []Flight `json:"data"`
}
// Flight has the detailed information of a flight
type Flight struct {
ID string `json:"id"`
MapIDFrom string `json:"mapIdfrom"`
CityFrom string `json:"cityFrom"`
CountryFrom map[string]string `json:"countryFrom"`
FlyFrom string `json:"flyFrom"`
ReturnDuration string `json:"return_duration"`
MapIDTo string `json:"mapIdto"`
CityTo string `json:"cityTo"`
CountryTo map[string]string `json:"countryTo"`
FlyTo string `json:"flyTo"`
FlyDuration string `json:"fly_duration"`
Conversion map[string]int `json:"conversion"`
DeepLink string `json:"deep_link"`
BookingToken string `json:"booking_token"`
NightsInDestination int `json:"nightsInDest"`
BagLimit map[string]int `json:"baglimit"`
BagsPrice map[string]int `json:"bags_price"`
DepartureTimeUTC int `json:"dTimeUTC"`
DepartureTime int `json:"dTime"`
ArrivalTimeUTC int `json:"aTimeUTC"`
ArrivalTime int `json:"aTime"`
Distance float32 `json:"distance"`
Price int `json:"price"`
TypeFlights []string `json:"type_flights"`
Route []Route `json:"route"`
}
// Route has the information each of the flight during the whole trip
type Route struct {
ID string `json:"id"`
Airline string `json:"airline"`
FlightNumber int `json:"flight_no"`
Price int `json:"price"`
BagsRecheckRequired bool `json:"bags_recheck_required"`
DepartureTimeUTC int `json:"dTimeUTC"`
DepartureTime int `json:"dTime"`
ArrivalTimeUTC int `json:"aTimeUTC"`
ArrivalTime int `json:"aTime"`
MapIDFrom string `json:"mapIdfrom"`
CityFrom string `json:"cityFrom"`
FlyFrom string `json:"flyFrom"`
LatitudeFrom float32 `json:"latFrom"`
LongitudeFrom float32 `json:"lngFrom"`
MapIDTo string `json:"mapIdto"`
FlyTo string `json:"flyTo"`
CityTo string `json:"cityTo"`
LatitudeTo float32 `json:"latTo"`
LongitudeTo float32 `json:"lngTo"`
}
// GetFlights calls the Kiwi API to retrieve all the flights that match the given parameters
func (k *Kiwi) GetFlights(p *Parameters) (*Response, error) {
qs, err := query.Values(p)
if err != nil {
return nil, err
}
var r Response
err = k.call("/flights?"+qs.Encode(), &r)
return &r, err
}