forked from Bonial-International-GmbH/site24x7-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
location_profiles.go
83 lines (70 loc) · 1.9 KB
/
location_profiles.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
78
79
80
81
82
83
package endpoints
import (
"github.com/Bonial-International-GmbH/site24x7-go/api"
"github.com/Bonial-International-GmbH/site24x7-go/rest"
)
type LocationProfiles interface {
Get(profileID string) (*api.LocationProfile, error)
Create(profile *api.LocationProfile) (*api.LocationProfile, error)
Update(profile *api.LocationProfile) (*api.LocationProfile, error)
Delete(profileID string) error
List() ([]*api.LocationProfile, error)
}
type locationProfiles struct {
client rest.Client
}
func NewLocationProfiles(client rest.Client) LocationProfiles {
return &locationProfiles{
client: client,
}
}
func (c *locationProfiles) Get(profileID string) (*api.LocationProfile, error) {
profile := &api.LocationProfile{}
err := c.client.
Get().
Resource("location_profiles").
ResourceID(profileID).
Do().
Into(profile)
return profile, err
}
func (c *locationProfiles) Create(profile *api.LocationProfile) (*api.LocationProfile, error) {
newProfile := &api.LocationProfile{}
err := c.client.
Post().
Resource("location_profiles").
AddHeader("Content-Type", "application/json;charset=UTF-8").
Body(profile).
Do().
Into(newProfile)
return newProfile, err
}
func (c *locationProfiles) Update(profile *api.LocationProfile) (*api.LocationProfile, error) {
updatedProfile := &api.LocationProfile{}
err := c.client.
Put().
Resource("location_profiles").
ResourceID(profile.ProfileID).
AddHeader("Content-Type", "application/json;charset=UTF-8").
Body(profile).
Do().
Into(updatedProfile)
return updatedProfile, err
}
func (c *locationProfiles) Delete(profileID string) error {
return c.client.
Delete().
Resource("location_profiles").
ResourceID(profileID).
Do().
Err()
}
func (c *locationProfiles) List() ([]*api.LocationProfile, error) {
profiles := []*api.LocationProfile{}
err := c.client.
Get().
Resource("location_profiles").
Do().
Into(&profiles)
return profiles, err
}