-
Notifications
You must be signed in to change notification settings - Fork 5
/
phone-numbers.go
71 lines (51 loc) · 1.36 KB
/
phone-numbers.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
package whatsapp
import (
"encoding/json"
"fmt"
)
func (api *API) ListPhoneNumbers(businessAccountId string) (*ListPhoneResponse, error) {
endpoint := fmt.Sprintf("/%s/phone_numbers", businessAccountId)
params := map[string]interface{}{}
params["access_token"] = api.Token
res, status, err := api.request(endpoint, "GET", params, nil)
if err != nil {
return nil, err
}
if status != 200 {
e := ErrorResponse{}
json.Unmarshal(res, &e)
return nil, &e
}
var response ListPhoneResponse
json.Unmarshal(res, &response)
return &response, nil
}
func (api *API) SinglePhoneNumber(phoneId string) (*PhoneNumber, error) {
endpoint := fmt.Sprintf("/%s", phoneId)
params := map[string]interface{}{}
params["access_token"] = api.Token
res, status, err := api.request(endpoint, "GET", params, nil)
if err != nil {
return nil, err
}
if status != 200 {
e := ErrorResponse{}
json.Unmarshal(res, &e)
return nil, &e
}
var response PhoneNumber
json.Unmarshal(res, &response)
return &response, nil
}
type ListPhoneResponse struct {
Data []PhoneNumber `json:"data"`
}
type GetPhoneResponse struct {
Data PhoneNumber `json:"data"`
}
type PhoneNumber struct {
VerifiedName string `json:"verified_name"`
DisplayPhoneNumber string `json:"display_phone_number"`
Id string `json:"id"`
QualityRating string `json:"quality_rating"`
}