forked from intercom/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_api.go
27 lines (22 loc) · 677 Bytes
/
message_api.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
package intercom
import (
"encoding/json"
"gopkg.in/intercom/intercom-go.v2/interfaces"
)
// MessageRepository defines the interface for creating and updating Messages through the API.
type MessageRepository interface {
save(message *MessageRequest) (MessageResponse, error)
}
// MessageAPI implements MessageRepository
type MessageAPI struct {
httpClient interfaces.HTTPClient
}
func (api MessageAPI) save(message *MessageRequest) (MessageResponse, error) {
data, err := api.httpClient.Post("/messages", message)
savedMessage := MessageResponse{}
if err != nil {
return savedMessage, err
}
err = json.Unmarshal(data, &savedMessage)
return savedMessage, err
}