1 // Copyright 2024 Google LLC. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Code generated file. DO NOT EDIT. 6 7 // Package travelimpactmodel provides access to the Travel Impact Model API. 8 // 9 // For product documentation, see: https://developers.google.com/travel/impact-model 10 // 11 // # Library status 12 // 13 // These client libraries are officially supported by Google. However, this 14 // library is considered complete and is in maintenance mode. This means 15 // that we will address critical bugs and security issues but will not add 16 // any new features. 17 // 18 // When possible, we recommend using our newer 19 // [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go) 20 // that are still actively being worked and iterated on. 21 // 22 // # Creating a client 23 // 24 // Usage example: 25 // 26 // import "google.golang.org/api/travelimpactmodel/v1" 27 // ... 28 // ctx := context.Background() 29 // travelimpactmodelService, err := travelimpactmodel.NewService(ctx) 30 // 31 // In this example, Google Application Default Credentials are used for 32 // authentication. For information on how to create and obtain Application 33 // Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials. 34 // 35 // # Other authentication options 36 // 37 // To use an API key for authentication (note: some APIs do not support API 38 // keys), use [google.golang.org/api/option.WithAPIKey]: 39 // 40 // travelimpactmodelService, err := travelimpactmodel.NewService(ctx, option.WithAPIKey("AIza...")) 41 // 42 // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth 43 // flow, use [google.golang.org/api/option.WithTokenSource]: 44 // 45 // config := &oauth2.Config{...} 46 // // ... 47 // token, err := config.Exchange(ctx, ...) 48 // travelimpactmodelService, err := travelimpactmodel.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token))) 49 // 50 // See [google.golang.org/api/option.ClientOption] for details on options. 51 package travelimpactmodel // import "google.golang.org/api/travelimpactmodel/v1" 52 53 import ( 54 "bytes" 55 "context" 56 "encoding/json" 57 "errors" 58 "fmt" 59 "io" 60 "net/http" 61 "net/url" 62 "strconv" 63 "strings" 64 65 googleapi "google.golang.org/api/googleapi" 66 internal "google.golang.org/api/internal" 67 gensupport "google.golang.org/api/internal/gensupport" 68 option "google.golang.org/api/option" 69 internaloption "google.golang.org/api/option/internaloption" 70 htransport "google.golang.org/api/transport/http" 71 ) 72 73 // Always reference these packages, just in case the auto-generated code 74 // below doesn't. 75 var _ = bytes.NewBuffer 76 var _ = strconv.Itoa 77 var _ = fmt.Sprintf 78 var _ = json.NewDecoder 79 var _ = io.Copy 80 var _ = url.Parse 81 var _ = gensupport.MarshalJSON 82 var _ = googleapi.Version 83 var _ = errors.New 84 var _ = strings.Replace 85 var _ = context.Canceled 86 var _ = internaloption.WithDefaultEndpoint 87 var _ = internal.Version 88 89 const apiId = "travelimpactmodel:v1" 90 const apiName = "travelimpactmodel" 91 const apiVersion = "v1" 92 const basePath = "https://travelimpactmodel.googleapis.com/" 93 const basePathTemplate = "https://travelimpactmodel.UNIVERSE_DOMAIN/" 94 const mtlsBasePath = "https://travelimpactmodel.mtls.googleapis.com/" 95 96 // NewService creates a new Service. 97 func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) { 98 opts = append(opts, internaloption.WithDefaultEndpoint(basePath)) 99 opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate)) 100 opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath)) 101 opts = append(opts, internaloption.EnableNewAuthLibrary()) 102 client, endpoint, err := htransport.NewClient(ctx, opts...) 103 if err != nil { 104 return nil, err 105 } 106 s, err := New(client) 107 if err != nil { 108 return nil, err 109 } 110 if endpoint != "" { 111 s.BasePath = endpoint 112 } 113 return s, nil 114 } 115 116 // New creates a new Service. It uses the provided http.Client for requests. 117 // 118 // Deprecated: please use NewService instead. 119 // To provide a custom HTTP client, use option.WithHTTPClient. 120 // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead. 121 func New(client *http.Client) (*Service, error) { 122 if client == nil { 123 return nil, errors.New("client is nil") 124 } 125 s := &Service{client: client, BasePath: basePath} 126 s.Flights = NewFlightsService(s) 127 return s, nil 128 } 129 130 type Service struct { 131 client *http.Client 132 BasePath string // API endpoint base URL 133 UserAgent string // optional additional User-Agent fragment 134 135 Flights *FlightsService 136 } 137 138 func (s *Service) userAgent() string { 139 if s.UserAgent == "" { 140 return googleapi.UserAgent 141 } 142 return googleapi.UserAgent + " " + s.UserAgent 143 } 144 145 func NewFlightsService(s *Service) *FlightsService { 146 rs := &FlightsService{s: s} 147 return rs 148 } 149 150 type FlightsService struct { 151 s *Service 152 } 153 154 // ComputeFlightEmissionsRequest: Input definition for the 155 // ComputeFlightEmissions request. 156 type ComputeFlightEmissionsRequest struct { 157 // Flights: Required. Direct flights to return emission estimates for. 158 Flights []*Flight `json:"flights,omitempty"` 159 // ForceSendFields is a list of field names (e.g. "Flights") to unconditionally 160 // include in API requests. By default, fields with empty or default values are 161 // omitted from API requests. See 162 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more 163 // details. 164 ForceSendFields []string `json:"-"` 165 // NullFields is a list of field names (e.g. "Flights") to include in API 166 // requests with the JSON null value. By default, fields with empty values are 167 // omitted from API requests. See 168 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. 169 NullFields []string `json:"-"` 170 } 171 172 func (s *ComputeFlightEmissionsRequest) MarshalJSON() ([]byte, error) { 173 type NoMethod ComputeFlightEmissionsRequest 174 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields) 175 } 176 177 // ComputeFlightEmissionsResponse: Output definition for the 178 // ComputeFlightEmissions response. 179 type ComputeFlightEmissionsResponse struct { 180 // FlightEmissions: List of flight legs with emission estimates. 181 FlightEmissions []*FlightWithEmissions `json:"flightEmissions,omitempty"` 182 // ModelVersion: The model version under which emission estimates for all 183 // flights in this response were computed. 184 ModelVersion *ModelVersion `json:"modelVersion,omitempty"` 185 186 // ServerResponse contains the HTTP response code and headers from the server. 187 googleapi.ServerResponse `json:"-"` 188 // ForceSendFields is a list of field names (e.g. "FlightEmissions") to 189 // unconditionally include in API requests. By default, fields with empty or 190 // default values are omitted from API requests. See 191 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more 192 // details. 193 ForceSendFields []string `json:"-"` 194 // NullFields is a list of field names (e.g. "FlightEmissions") to include in 195 // API requests with the JSON null value. By default, fields with empty values 196 // are omitted from API requests. See 197 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. 198 NullFields []string `json:"-"` 199 } 200 201 func (s *ComputeFlightEmissionsResponse) MarshalJSON() ([]byte, error) { 202 type NoMethod ComputeFlightEmissionsResponse 203 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields) 204 } 205 206 // Date: Represents a whole or partial calendar date, such as a birthday. The 207 // time of day and time zone are either specified elsewhere or are 208 // insignificant. The date is relative to the Gregorian Calendar. This can 209 // represent one of the following: * A full date, with non-zero year, month, 210 // and day values. * A month and day, with a zero year (for example, an 211 // anniversary). * A year on its own, with a zero month and a zero day. * A 212 // year and month, with a zero day (for example, a credit card expiration 213 // date). Related types: * google.type.TimeOfDay * google.type.DateTime * 214 // google.protobuf.Timestamp 215 type Date struct { 216 // Day: Day of a month. Must be from 1 to 31 and valid for the year and month, 217 // or 0 to specify a year by itself or a year and month where the day isn't 218 // significant. 219 Day int64 `json:"day,omitempty"` 220 // Month: Month of a year. Must be from 1 to 12, or 0 to specify a year without 221 // a month and day. 222 Month int64 `json:"month,omitempty"` 223 // Year: Year of the date. Must be from 1 to 9999, or 0 to specify a date 224 // without a year. 225 Year int64 `json:"year,omitempty"` 226 // ForceSendFields is a list of field names (e.g. "Day") to unconditionally 227 // include in API requests. By default, fields with empty or default values are 228 // omitted from API requests. See 229 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more 230 // details. 231 ForceSendFields []string `json:"-"` 232 // NullFields is a list of field names (e.g. "Day") to include in API requests 233 // with the JSON null value. By default, fields with empty values are omitted 234 // from API requests. See 235 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. 236 NullFields []string `json:"-"` 237 } 238 239 func (s *Date) MarshalJSON() ([]byte, error) { 240 type NoMethod Date 241 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields) 242 } 243 244 // EmissionsGramsPerPax: Grouped emissions per seating class results. 245 type EmissionsGramsPerPax struct { 246 // Business: Emissions for one passenger in business class in grams. This field 247 // is always computed and populated, regardless of whether the aircraft has 248 // business class seats or not. 249 Business int64 `json:"business,omitempty"` 250 // Economy: Emissions for one passenger in economy class in grams. This field 251 // is always computed and populated, regardless of whether the aircraft has 252 // economy class seats or not. 253 Economy int64 `json:"economy,omitempty"` 254 // First: Emissions for one passenger in first class in grams. This field is 255 // always computed and populated, regardless of whether the aircraft has first 256 // class seats or not. 257 First int64 `json:"first,omitempty"` 258 // PremiumEconomy: Emissions for one passenger in premium economy class in 259 // grams. This field is always computed and populated, regardless of whether 260 // the aircraft has premium economy class seats or not. 261 PremiumEconomy int64 `json:"premiumEconomy,omitempty"` 262 // ForceSendFields is a list of field names (e.g. "Business") to 263 // unconditionally include in API requests. By default, fields with empty or 264 // default values are omitted from API requests. See 265 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more 266 // details. 267 ForceSendFields []string `json:"-"` 268 // NullFields is a list of field names (e.g. "Business") to include in API 269 // requests with the JSON null value. By default, fields with empty values are 270 // omitted from API requests. See 271 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. 272 NullFields []string `json:"-"` 273 } 274 275 func (s *EmissionsGramsPerPax) MarshalJSON() ([]byte, error) { 276 type NoMethod EmissionsGramsPerPax 277 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields) 278 } 279 280 // Flight: All details related to a single request item for a direct flight 281 // emission estimates. 282 type Flight struct { 283 // DepartureDate: Required. Date of the flight in the time zone of the origin 284 // airport. Must be a date in the present or future. 285 DepartureDate *Date `json:"departureDate,omitempty"` 286 // Destination: Required. IATA airport code for flight destination, e.g. "JFK". 287 Destination string `json:"destination,omitempty"` 288 // FlightNumber: Required. Flight number, e.g. 324. 289 FlightNumber int64 `json:"flightNumber,omitempty"` 290 // OperatingCarrierCode: Required. IATA carrier code, e.g. "AA". 291 OperatingCarrierCode string `json:"operatingCarrierCode,omitempty"` 292 // Origin: Required. IATA airport code for flight origin, e.g. "LHR". 293 Origin string `json:"origin,omitempty"` 294 // ForceSendFields is a list of field names (e.g. "DepartureDate") to 295 // unconditionally include in API requests. By default, fields with empty or 296 // default values are omitted from API requests. See 297 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more 298 // details. 299 ForceSendFields []string `json:"-"` 300 // NullFields is a list of field names (e.g. "DepartureDate") to include in API 301 // requests with the JSON null value. By default, fields with empty values are 302 // omitted from API requests. See 303 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. 304 NullFields []string `json:"-"` 305 } 306 307 func (s *Flight) MarshalJSON() ([]byte, error) { 308 type NoMethod Flight 309 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields) 310 } 311 312 // FlightWithEmissions: Direct flight with emission estimates. 313 type FlightWithEmissions struct { 314 // EmissionsGramsPerPax: Optional. Per-passenger emission estimate numbers. 315 // Will not be present if emissions could not be computed. For the list of 316 // reasons why emissions could not be computed, see ComputeFlightEmissions. 317 // Note this field is currently equivalent to ttw_emissions_grams_per_pax until 318 // TIM version 1.X.0 which will update this to be total wtw emissions aka 319 // wtt_emissions_grams_per_pax + ttw_emissions_grams_per_pax. 320 EmissionsGramsPerPax *EmissionsGramsPerPax `json:"emissionsGramsPerPax,omitempty"` 321 // Flight: Required. Matches the flight identifiers in the request. Note: all 322 // IATA codes are capitalized. 323 Flight *Flight `json:"flight,omitempty"` 324 // ForceSendFields is a list of field names (e.g. "EmissionsGramsPerPax") to 325 // unconditionally include in API requests. By default, fields with empty or 326 // default values are omitted from API requests. See 327 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more 328 // details. 329 ForceSendFields []string `json:"-"` 330 // NullFields is a list of field names (e.g. "EmissionsGramsPerPax") to include 331 // in API requests with the JSON null value. By default, fields with empty 332 // values are omitted from API requests. See 333 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. 334 NullFields []string `json:"-"` 335 } 336 337 func (s *FlightWithEmissions) MarshalJSON() ([]byte, error) { 338 type NoMethod FlightWithEmissions 339 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields) 340 } 341 342 // ModelVersion: Travel Impact Model version. For more information about the 343 // model versioning see 344 // https://github.com/google/travel-impact-model/#versioning. 345 type ModelVersion struct { 346 // Dated: Dated versions: Model datasets are recreated with refreshed input 347 // data but no change to the algorithms regularly. 348 Dated string `json:"dated,omitempty"` 349 // Major: Major versions: Major changes to methodology (e.g. adding new data 350 // sources to the model that lead to major output changes). Such changes will 351 // be infrequent and announced well in advance. Might involve API version 352 // changes, which will respect guidelines in 353 // https://cloud.google.com/endpoints/docs/openapi/versioning-an-api#backwards-incompatible 354 Major int64 `json:"major,omitempty"` 355 // Minor: Minor versions: Changes to the model that, while being consistent 356 // across schema versions, change the model parameters or implementation. 357 Minor int64 `json:"minor,omitempty"` 358 // Patch: Patch versions: Implementation changes meant to address bugs or 359 // inaccuracies in the model implementation. 360 Patch int64 `json:"patch,omitempty"` 361 // ForceSendFields is a list of field names (e.g. "Dated") to unconditionally 362 // include in API requests. By default, fields with empty or default values are 363 // omitted from API requests. See 364 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more 365 // details. 366 ForceSendFields []string `json:"-"` 367 // NullFields is a list of field names (e.g. "Dated") to include in API 368 // requests with the JSON null value. By default, fields with empty values are 369 // omitted from API requests. See 370 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details. 371 NullFields []string `json:"-"` 372 } 373 374 func (s *ModelVersion) MarshalJSON() ([]byte, error) { 375 type NoMethod ModelVersion 376 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields) 377 } 378 379 type FlightsComputeFlightEmissionsCall struct { 380 s *Service 381 computeflightemissionsrequest *ComputeFlightEmissionsRequest 382 urlParams_ gensupport.URLParams 383 ctx_ context.Context 384 header_ http.Header 385 } 386 387 // ComputeFlightEmissions: Stateless method to retrieve emission estimates. 388 // Details on how emission estimates are computed: 389 // https://github.com/google/travel-impact-model The response will contain all 390 // entries that match the input flight legs, in the same order. If there are no 391 // estimates available for a certain flight leg, the response will return the 392 // flight leg object with empty emission fields. The request will still be 393 // considered successful. Reasons for missing emission estimates include: - The 394 // flight is unknown to the server. - The input flight leg is missing one or 395 // more identifiers. - The flight date is in the past. - The aircraft type is 396 // not supported by the model. - Missing seat configuration. The request can 397 // contain up to 1000 flight legs. If the request has more than 1000 direct 398 // flights, if will fail with an INVALID_ARGUMENT error. 399 func (r *FlightsService) ComputeFlightEmissions(computeflightemissionsrequest *ComputeFlightEmissionsRequest) *FlightsComputeFlightEmissionsCall { 400 c := &FlightsComputeFlightEmissionsCall{s: r.s, urlParams_: make(gensupport.URLParams)} 401 c.computeflightemissionsrequest = computeflightemissionsrequest 402 return c 403 } 404 405 // Fields allows partial responses to be retrieved. See 406 // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more 407 // details. 408 func (c *FlightsComputeFlightEmissionsCall) Fields(s ...googleapi.Field) *FlightsComputeFlightEmissionsCall { 409 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 410 return c 411 } 412 413 // Context sets the context to be used in this call's Do method. 414 func (c *FlightsComputeFlightEmissionsCall) Context(ctx context.Context) *FlightsComputeFlightEmissionsCall { 415 c.ctx_ = ctx 416 return c 417 } 418 419 // Header returns a http.Header that can be modified by the caller to add 420 // headers to the request. 421 func (c *FlightsComputeFlightEmissionsCall) Header() http.Header { 422 if c.header_ == nil { 423 c.header_ = make(http.Header) 424 } 425 return c.header_ 426 } 427 428 func (c *FlightsComputeFlightEmissionsCall) doRequest(alt string) (*http.Response, error) { 429 reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) 430 var body io.Reader = nil 431 body, err := googleapi.WithoutDataWrapper.JSONReader(c.computeflightemissionsrequest) 432 if err != nil { 433 return nil, err 434 } 435 c.urlParams_.Set("alt", alt) 436 c.urlParams_.Set("prettyPrint", "false") 437 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/flights:computeFlightEmissions") 438 urls += "?" + c.urlParams_.Encode() 439 req, err := http.NewRequest("POST", urls, body) 440 if err != nil { 441 return nil, err 442 } 443 req.Header = reqHeaders 444 return gensupport.SendRequest(c.ctx_, c.s.client, req) 445 } 446 447 // Do executes the "travelimpactmodel.flights.computeFlightEmissions" call. 448 // Any non-2xx status code is an error. Response headers are in either 449 // *ComputeFlightEmissionsResponse.ServerResponse.Header or (if a response was 450 // returned at all) in error.(*googleapi.Error).Header. Use 451 // googleapi.IsNotModified to check whether the returned error was because 452 // http.StatusNotModified was returned. 453 func (c *FlightsComputeFlightEmissionsCall) Do(opts ...googleapi.CallOption) (*ComputeFlightEmissionsResponse, error) { 454 gensupport.SetOptions(c.urlParams_, opts...) 455 res, err := c.doRequest("json") 456 if res != nil && res.StatusCode == http.StatusNotModified { 457 if res.Body != nil { 458 res.Body.Close() 459 } 460 return nil, gensupport.WrapError(&googleapi.Error{ 461 Code: res.StatusCode, 462 Header: res.Header, 463 }) 464 } 465 if err != nil { 466 return nil, err 467 } 468 defer googleapi.CloseBody(res) 469 if err := googleapi.CheckResponse(res); err != nil { 470 return nil, gensupport.WrapError(err) 471 } 472 ret := &ComputeFlightEmissionsResponse{ 473 ServerResponse: googleapi.ServerResponse{ 474 Header: res.Header, 475 HTTPStatusCode: res.StatusCode, 476 }, 477 } 478 target := &ret 479 if err := gensupport.DecodeResponse(target, res); err != nil { 480 return nil, err 481 } 482 return ret, nil 483 } 484