forked from Scalingo/go-scalingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addons_providers.go
77 lines (65 loc) · 1.8 KB
/
addons_providers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package scalingo
import (
"github.com/Scalingo/go-scalingo/http"
"gopkg.in/errgo.v1"
)
type AddonProvidersService interface {
AddonProvidersList() ([]*AddonProvider, error)
AddonProviderPlansList(addon string) ([]*Plan, error)
}
var _ AddonProvidersService = (*Client)(nil)
type Plan struct {
ID string `json:"id"`
LogoURL string `json:"logo_url"`
DisplayName string `json:"display_name"`
Name string `json:"name"`
Description string `json:"description"`
Price float64 `json:"price"`
}
type PlansParams struct {
Plans []*Plan `json:"plans"`
}
type AddonProvider struct {
ID string `json:"id"`
LogoURL string `json:"logo_url"`
Name string `json:"name"`
}
type ListParams struct {
AddonProviders []*AddonProvider `json:"addon_providers"`
}
func (c *Client) AddonProvidersList() ([]*AddonProvider, error) {
req := &http.APIRequest{
NoAuth: true,
Endpoint: "/addon_providers",
}
var params ListParams
err := c.ScalingoAPI().DoRequest(req, ¶ms)
if err != nil {
return nil, errgo.Mask(err)
}
return params.AddonProviders, nil
}
var addonProviderTypo = map[string]string{
"scalingo-mongo": "scalingo-mongodb",
"scalingo-influx": "scalingo-influxdb",
"scalingo-postgres": "scalingo-postgresql",
"scalingo-postgre": "scalingo-postgresql",
"scalingo-pgsql": "scalingo-postgresql",
"scalingo-psql": "scalingo-postgresql",
}
func (c *Client) AddonProviderPlansList(addon string) ([]*Plan, error) {
correctAddon, ok := addonProviderTypo[addon]
if ok {
addon = correctAddon
}
var params PlansParams
req := &http.APIRequest{
NoAuth: true,
Endpoint: "/addon_providers/" + addon + "/plans",
}
err := c.ScalingoAPI().DoRequest(req, ¶ms)
if err != nil {
return nil, errgo.Notef(err, "fail to get plans")
}
return params.Plans, nil
}