resourcetickets.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2016 VMware, Inc. All Rights Reserved.
  2. //
  3. // This product is licensed to you under the Apache License, Version 2.0 (the "License").
  4. // You may not use this product except in compliance with the License.
  5. //
  6. // This product may include a number of subcomponents with separate copyright notices and
  7. // license terms. Your use of these subcomponents is subject to the terms and conditions
  8. // of the subcomponent's license, as noted in the LICENSE file.
  9. package photon
  10. import (
  11. "encoding/json"
  12. )
  13. // Contains functionality for hosts API.
  14. type ResourceTicketsAPI struct {
  15. client *Client
  16. }
  17. var resourceTicketUrl string = rootUrl + "/resource-tickets/"
  18. // Gets all tasks with the specified resource ticket ID, using options to filter the results.
  19. // If options is nil, no filtering will occur.
  20. func (api *ResourceTicketsAPI) GetTasks(id string, options *TaskGetOptions) (result *TaskList, err error) {
  21. uri := api.client.Endpoint + resourceTicketUrl + id + "/tasks"
  22. if options != nil {
  23. uri += getQueryString(options)
  24. }
  25. res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
  26. if err != nil {
  27. return
  28. }
  29. result = &TaskList{}
  30. err = json.Unmarshal(res, result)
  31. return
  32. }
  33. // Gets the resource ticket with a specified ID.
  34. func (api *ResourceTicketsAPI) Get(id string) (resourceTicket *ResourceTicket, err error) {
  35. res, err := api.client.restClient.Get(api.client.Endpoint+resourceTicketUrl+"/"+id,
  36. api.client.options.TokenOptions)
  37. if err != nil {
  38. return
  39. }
  40. defer res.Body.Close()
  41. res, err = getError(res)
  42. if err != nil {
  43. return
  44. }
  45. resourceTicket = &ResourceTicket{}
  46. err = json.NewDecoder(res.Body).Decode(resourceTicket)
  47. return
  48. }