-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.go
More file actions
48 lines (37 loc) · 1.17 KB
/
lists.go
File metadata and controls
48 lines (37 loc) · 1.17 KB
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
package carmaclient
import (
"encoding/json"
"errors"
"fmt"
"github.com/moonwalker/carmaclient/dto"
"net/http"
"net/url"
)
type ListsService service
func (s *ListsService) GetContact(listID int64, originalID string) (*dto.ContactDTO, error) {
response := s.client.carmaRequest(fmt.Sprintf("lists/%d/contacts/%s", listID, url.QueryEscape(originalID)), http.MethodGet, nil)
if response.err != nil {
return nil, response.err
}
if response.statusCode == http.StatusNotFound {
return nil, errors.New(http.StatusText(response.statusCode))
}
responseDTO := &dto.ContactDTO{}
err := json.Unmarshal(response.data, responseDTO)
if err != nil {
return nil, err
}
return responseDTO, nil
}
func (s *ListsService) PutContactUpdate(listID int64, originalID string, contact dto.ContactDTO) (*dto.ContactDTO, error) {
response := s.client.carmaRequest(fmt.Sprintf("lists/%d/contacts/%s/update?force=true", listID, url.QueryEscape(originalID)), http.MethodPut, contact)
if response.err != nil {
return nil, response.err
}
responseDTO := &dto.ContactDTO{}
err := json.Unmarshal(response.data, responseDTO)
if err != nil {
return nil, err
}
return responseDTO, nil
}