/
data_subscribers_service.go
73 lines (65 loc) · 2.03 KB
/
data_subscribers_service.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
package mdm
import (
"encoding/json"
"fmt"
"net/http"
"github.com/philips-software/go-hsdp-api/internal"
)
type DataSubscribersService struct {
*Client
}
type DataSubscriber struct {
ResourceType string `json:"resourceType"`
ID string `json:"id"`
Name string `json:"name"`
SubscriberGuid Identifier `json:"subscriberGuid"`
SubscriberTypeId Reference `json:"subscriberTypeId"`
Configuration json.RawMessage `json:"configuration"`
Meta *Meta `json:"meta"`
}
type GetDataSubscriberOptions struct {
LastUpdate *string `url:"_lastUpdated,omitempty"`
ReverseInclude *string `url:"_revinclude,omitempty"`
Include *string `url:"_include,omitempty"`
ID *string `url:"_id,omitempty"`
Name *string `url:"name,omitempty"`
SubscriberTypeID *string `url:"subscriberTypeId,omitempty"`
SubscriberTypeFGUID *string `url:"subscriberGuid,omitempty"`
}
func (r *DataSubscribersService) Get(opt *GetDataSubscriberOptions) (*[]DataSubscriber, *Response, error) {
req, err := r.NewRequest(http.MethodGet, "/DataSubscriber", opt)
if err != nil {
return nil, nil, err
}
var bundleResponse internal.Bundle
resp, err := r.Do(req, &bundleResponse)
if err != nil {
return nil, resp, err
}
if err := internal.CheckResponse(resp.Response); err != nil {
return nil, resp, err
}
var resources []DataSubscriber
for _, s := range bundleResponse.Entry {
var resource DataSubscriber
if err := json.Unmarshal(s.Resource, &resource); err == nil {
resources = append(resources, resource)
}
}
return &resources, resp, nil
}
func (r *DataSubscribersService) GetByID(id string) (*DataSubscriber, *Response, error) {
if len(id) == 0 {
return nil, nil, fmt.Errorf("GetByID: missing id")
}
resources, resp, err := r.Get(&GetDataSubscriberOptions{
ID: &id,
})
if err != nil {
return nil, resp, err
}
if len(*resources) == 0 {
return nil, resp, ErrEmptyResult
}
return &(*resources)[0], resp, nil
}