Created
November 25, 2015 10:17
-
-
Save dmunch/06b89867af6bade6058e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "../packages/FSharp.Data/lib/net40/FSharp.Data.dll" | |
open FSharp.Data | |
type Flights = JsonProvider<"QXPRequest.json", RootName="QXP"> | |
type FlightsResponse = JsonProvider<"QXPResponse.json"> | |
let slice1 = Flights.Slouse(origin = "BER", destination = "NYC", date = "2015-11-26") | |
let slice2 = Flights.Slouse(origin = "NYC", destination = "CDG", date = "2015-11-28") | |
let slice3 = Flights.Slouse(origin = "CDG", destination = "BER", date = "2015-11-30") | |
let passengers = Flights.Passengers(adultCount = 1, | |
infantInLapCount = 0, | |
infantInSeatCount = 0, | |
childCount = 0, | |
seniorCount = 0) | |
let request = Flights.Request(solutions = 10, | |
saleCountry = "DE", | |
refundable = false, | |
passengers = passengers, | |
slice = [| slice1; slice2; slice3 |]) | |
let qxp = Flights.Qxp(request = request) | |
let printConnections json = | |
let trips = (FlightsResponse.Parse json).Trips | |
for option in trips.TripOption do | |
printfn "Total: %s" option.SaleTotal | |
for slice in option.Slice do | |
for segment in slice.Segment do | |
for leg in segment.Leg do | |
printfn "From %s to %s" leg.Origin leg.Destination | |
printfn "Departure %O" leg.DepartureTime | |
printfn "Arrival %O" leg.ArrivalTime | |
printfn "--" | |
let res = qxp.JsonValue.Request "https://www.googleapis.com/qpxExpress/v1/trips/search?key=<your-api-key>" | |
match res.Body with | |
| Text json -> printConnections json | |
| _ -> printf "Unexpected response" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment