forked from messagebird/go-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hlr.go
95 lines (78 loc) · 2.13 KB
/
hlr.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
84
85
86
87
88
89
90
91
92
93
94
95
package hlr
import (
"errors"
"net/http"
"time"
messagebird "github.com/Bijles-aan-Huis-B-V/messagebird-go-rest-api"
)
// path represents the path to the HLR resource.
const path = "hlr"
// HLR stands for Home Location Register. Contains information about the
// subscribers identity, telephone number, the associated services and general
// information about the location of the subscriber.
type HLR struct {
ID string
HRef string
MSISDN int
Network int
Reference string
Status string
Details map[string]interface{}
CreatedDatetime *time.Time
StatusDatetime *time.Time
}
// HLRList represents a list of HLR requests.
type HLRList struct {
Offset int
Limit int
Count int
TotalCount int
Links map[string]*string
Items []HLR
}
type hlrRequest struct {
MSISDN string `json:"msisdn"`
Reference string `json:"reference"`
}
// Read looks up an existing HLR object for the specified id that was previously
// created by the NewHLR function.
func Read(c messagebird.Client, id string) (*HLR, error) {
hlr := &HLR{}
if err := c.Request(hlr, http.MethodGet, path+"/"+id, nil); err != nil {
return nil, err
}
return hlr, nil
}
// List all HLR objects that were previously created by the Create function.
func List(c messagebird.Client) (*HLRList, error) {
hlrList := &HLRList{}
if err := c.Request(hlrList, http.MethodGet, path, nil); err != nil {
return nil, err
}
return hlrList, nil
}
// Create creates a new HLR object.
func Create(c messagebird.Client, msisdn string, reference string) (*HLR, error) {
requestData, err := requestDataForHLR(msisdn, reference)
if err != nil {
return nil, err
}
hlr := &HLR{}
if err := c.Request(hlr, http.MethodPost, path, requestData); err != nil {
return nil, err
}
return hlr, nil
}
func requestDataForHLR(msisdn string, reference string) (*hlrRequest, error) {
if msisdn == "" {
return nil, errors.New("msisdn is required")
}
if reference == "" {
return nil, errors.New("reference is required")
}
request := &hlrRequest{
MSISDN: msisdn,
Reference: reference,
}
return request, nil
}