APIDiscoveryService.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // Copyright 2016, Sander van Harmelen
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package cloudstack
  17. import (
  18. "encoding/json"
  19. "net/url"
  20. )
  21. type ListApisParams struct {
  22. p map[string]interface{}
  23. }
  24. func (p *ListApisParams) toURLValues() url.Values {
  25. u := url.Values{}
  26. if p.p == nil {
  27. return u
  28. }
  29. if v, found := p.p["name"]; found {
  30. u.Set("name", v.(string))
  31. }
  32. return u
  33. }
  34. func (p *ListApisParams) SetName(v string) {
  35. if p.p == nil {
  36. p.p = make(map[string]interface{})
  37. }
  38. p.p["name"] = v
  39. return
  40. }
  41. // You should always use this function to get a new ListApisParams instance,
  42. // as then you are sure you have configured all required params
  43. func (s *APIDiscoveryService) NewListApisParams() *ListApisParams {
  44. p := &ListApisParams{}
  45. p.p = make(map[string]interface{})
  46. return p
  47. }
  48. // lists all available apis on the server, provided by the Api Discovery plugin
  49. func (s *APIDiscoveryService) ListApis(p *ListApisParams) (*ListApisResponse, error) {
  50. resp, err := s.cs.newRequest("listApis", p.toURLValues())
  51. if err != nil {
  52. return nil, err
  53. }
  54. var r ListApisResponse
  55. if err := json.Unmarshal(resp, &r); err != nil {
  56. return nil, err
  57. }
  58. return &r, nil
  59. }
  60. type ListApisResponse struct {
  61. Count int `json:"count"`
  62. Apis []*Api `json:"api"`
  63. }
  64. type Api struct {
  65. Description string `json:"description,omitempty"`
  66. Isasync bool `json:"isasync,omitempty"`
  67. Name string `json:"name,omitempty"`
  68. Params []struct {
  69. Description string `json:"description,omitempty"`
  70. Length int `json:"length,omitempty"`
  71. Name string `json:"name,omitempty"`
  72. Related string `json:"related,omitempty"`
  73. Required bool `json:"required,omitempty"`
  74. Since string `json:"since,omitempty"`
  75. Type string `json:"type,omitempty"`
  76. } `json:"params,omitempty"`
  77. Related string `json:"related,omitempty"`
  78. Response []struct {
  79. Description string `json:"description,omitempty"`
  80. Name string `json:"name,omitempty"`
  81. Response []string `json:"response,omitempty"`
  82. Type string `json:"type,omitempty"`
  83. } `json:"response,omitempty"`
  84. Since string `json:"since,omitempty"`
  85. Type string `json:"type,omitempty"`
  86. }