2016-06-28 22:35:41 -04:00
|
|
|
package profitbricks
|
|
|
|
|
2016-08-01 07:15:21 -04:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Location struct {
|
2017-08-10 09:15:53 -04:00
|
|
|
Id string `json:"id,omitempty"`
|
|
|
|
Type_ string `json:"type,omitempty"`
|
|
|
|
Href string `json:"href,omitempty"`
|
|
|
|
Metadata Metadata `json:"metadata,omitempty"`
|
|
|
|
Properties LocationProperties `json:"properties,omitempty"`
|
|
|
|
Response string `json:"Response,omitempty"`
|
|
|
|
Headers *http.Header `json:"headers,omitempty"`
|
|
|
|
StatusCode int `json:"headers,omitempty"`
|
2016-08-01 07:15:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Locations struct {
|
|
|
|
Id string `json:"id,omitempty"`
|
|
|
|
Type_ string `json:"type,omitempty"`
|
|
|
|
Href string `json:"href,omitempty"`
|
|
|
|
Items []Location `json:"items,omitempty"`
|
|
|
|
Response string `json:"Response,omitempty"`
|
|
|
|
Headers *http.Header `json:"headers,omitempty"`
|
|
|
|
StatusCode int `json:"headers,omitempty"`
|
|
|
|
}
|
|
|
|
|
2017-08-10 09:15:53 -04:00
|
|
|
type LocationProperties struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Features []string `json:"features,omitempty"`
|
|
|
|
ImageAliases []string `json:"imageAliases,omitempty"`
|
2016-08-01 07:15:21 -04:00
|
|
|
}
|
|
|
|
|
2016-06-28 22:35:41 -04:00
|
|
|
// ListLocations returns location collection data
|
2016-08-01 07:15:21 -04:00
|
|
|
func ListLocations() Locations {
|
|
|
|
url := mk_url(location_col_path()) + `?depth=` + Depth
|
|
|
|
req, _ := http.NewRequest("GET", url, nil)
|
|
|
|
req.Header.Add("Content-Type", FullHeader)
|
|
|
|
return toLocations(do(req))
|
2016-06-28 22:35:41 -04:00
|
|
|
}
|
|
|
|
|
2017-08-10 09:15:53 -04:00
|
|
|
// GetRegionalLocations returns a list of available locations in a specific region
|
|
|
|
func GetRegionalLocations(regid string) Locations {
|
|
|
|
url := mk_url(location_reg_path(regid)) + `?depth=` + Depth
|
|
|
|
req, _ := http.NewRequest("GET", url, nil)
|
|
|
|
req.Header.Add("Content-Type", FullHeader)
|
|
|
|
return toLocations(do(req))
|
|
|
|
}
|
|
|
|
|
2016-06-28 22:35:41 -04:00
|
|
|
// GetLocation returns location data
|
2016-08-01 07:15:21 -04:00
|
|
|
func GetLocation(locid string) Location {
|
|
|
|
url := mk_url(location_path(locid)) + `?depth=` + Depth
|
|
|
|
req, _ := http.NewRequest("GET", url, nil)
|
|
|
|
req.Header.Add("Content-Type", FullHeader)
|
|
|
|
return toLocation(do(req))
|
|
|
|
}
|
|
|
|
|
|
|
|
func toLocation(resp Resp) Location {
|
|
|
|
var obj Location
|
|
|
|
json.Unmarshal(resp.Body, &obj)
|
|
|
|
obj.Response = string(resp.Body)
|
|
|
|
obj.Headers = &resp.Headers
|
|
|
|
obj.StatusCode = resp.StatusCode
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
|
|
|
func toLocations(resp Resp) Locations {
|
|
|
|
var col Locations
|
|
|
|
json.Unmarshal(resp.Body, &col)
|
|
|
|
col.Response = string(resp.Body)
|
|
|
|
col.Headers = &resp.Headers
|
|
|
|
col.StatusCode = resp.StatusCode
|
|
|
|
return col
|
2016-06-28 22:35:41 -04:00
|
|
|
}
|