Skip to content

Commit 698c51d

Browse files
committed
change client interface and implementation names
1 parent 4c8ce66 commit 698c51d

File tree

28 files changed

+116
-116
lines changed

28 files changed

+116
-116
lines changed

balance/balance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const path = "balance"
1717

1818
// Read returns the balance information for the account that is associated with
1919
// the access key.
20-
func Read(c messagebird.MessageBirdClient) (*Balance, error) {
20+
func Read(c messagebird.Client) (*Balance, error) {
2121
balance := &Balance{}
2222
if err := c.Request(balance, http.MethodGet, path, nil); err != nil {
2323
return nil, err

client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ var (
4242
// A Feature can be enabled
4343
type Feature int
4444

45-
type MessageBirdClient interface {
45+
type Client interface {
4646
Request(v interface{}, method, path string, data interface{}) error
4747
}
4848

49-
// Client is used to access API with a given key.
49+
// BasicClient is used to access API with a given key.
5050
// Uses standard lib HTTP client internally, so should be reused instead of created as needed and it is safe for concurrent use.
51-
type Client struct {
51+
type BasicClient struct {
5252
AccessKey string // The API access key.
5353
HTTPClient *http.Client // The HTTP client to send requests on.
5454
DebugLog *log.Logger // Optional logger for debugging purposes.
@@ -73,8 +73,8 @@ func SetErrorReader(r errorReader) {
7373
}
7474

7575
// New creates a new MessageBird client object.
76-
func New(accessKey string) *Client {
77-
return &Client{
76+
func New(accessKey string) *BasicClient {
77+
return &BasicClient{
7878
AccessKey: accessKey,
7979
HTTPClient: &http.Client{
8080
Timeout: httpClientTimeout,
@@ -83,7 +83,7 @@ func New(accessKey string) *Client {
8383
}
8484

8585
// Request is for internal use only and unstable.
86-
func (c *Client) Request(v interface{}, method, path string, data interface{}) error {
86+
func (c *BasicClient) Request(v interface{}, method, path string, data interface{}) error {
8787
if !strings.HasPrefix(path, "https://") && !strings.HasPrefix(path, "http://") {
8888
path = fmt.Sprintf("%s/%s", Endpoint, path)
8989
}

contact/contact.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type ViewRequest struct {
5858
Name string `json:"firstName,omitempty"`
5959
}
6060

61-
func Create(c messagebird.MessageBirdClient, contactRequest *CreateRequest) (*Contact, error) {
61+
func Create(c messagebird.Client, contactRequest *CreateRequest) (*Contact, error) {
6262
contact := &Contact{}
6363
if err := c.Request(contact, http.MethodPost, path, contactRequest); err != nil {
6464
return nil, err
@@ -69,13 +69,13 @@ func Create(c messagebird.MessageBirdClient, contactRequest *CreateRequest) (*Co
6969

7070
// Delete attempts deleting the contact with the provided ID. If nil is returned,
7171
// the resource was deleted successfully.
72-
func Delete(c messagebird.MessageBirdClient, id string) error {
72+
func Delete(c messagebird.Client, id string) error {
7373
return c.Request(nil, http.MethodDelete, path+"/"+id, nil)
7474
}
7575

7676
// List retrieves a paginated list of contacts, based on the options provided.
7777
// It's worth noting DefaultListOptions.
78-
func List(c messagebird.MessageBirdClient, options *messagebird.PaginationRequest) (*Contacts, error) {
78+
func List(c messagebird.Client, options *messagebird.PaginationRequest) (*Contacts, error) {
7979
contactList := &Contacts{}
8080
if err := c.Request(contactList, http.MethodGet, path+"?"+options.QueryParams(), nil); err != nil {
8181
return nil, err
@@ -85,7 +85,7 @@ func List(c messagebird.MessageBirdClient, options *messagebird.PaginationReques
8585
}
8686

8787
// Read retrieves the information of an existing contact.
88-
func Read(c messagebird.MessageBirdClient, id string, req *ViewRequest) (*Contact, error) {
88+
func Read(c messagebird.Client, id string, req *ViewRequest) (*Contact, error) {
8989
contact := &Contact{}
9090
if err := c.Request(contact, http.MethodGet, path+"/"+id, req); err != nil {
9191
return nil, err
@@ -96,7 +96,7 @@ func Read(c messagebird.MessageBirdClient, id string, req *ViewRequest) (*Contac
9696

9797
// Update updates the record referenced by id with any values set in contactRequest.
9898
// Do not set any values that should not be updated.
99-
func Update(c messagebird.MessageBirdClient, id string, contactRequest *CreateRequest) (*Contact, error) {
99+
func Update(c messagebird.Client, id string, contactRequest *CreateRequest) (*Contact, error) {
100100
contact := &Contact{}
101101
if err := c.Request(contact, http.MethodPatch, path+"/"+id, contactRequest); err != nil {
102102
return nil, err

conversation/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const (
3131
webhooksPath = "webhooks"
3232
)
3333

34-
// request does the exact same thing as Client.Request. It does, however,
34+
// request does the exact same thing as BasicClient.Request. It does, however,
3535
// prefix the path with the Conversation API's root. This ensures the client
3636
// doesn't "handle" this for us: by default, it uses the REST API.
37-
func request(c messagebird.MessageBirdClient, v interface{}, method, path string, data interface{}) error {
37+
func request(c messagebird.Client, v interface{}, method, path string, data interface{}) error {
3838
return c.Request(v, method, fmt.Sprintf("%s/%s", apiRoot, path), data)
3939
}

conversation/conversation.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (lr *ListByContactRequest) QueryParams() string {
159159
}
160160

161161
// List gets a collection of Conversations. Pagination can be set in options.
162-
func List(c messagebird.MessageBirdClient, options *ListRequest) (*Conversations, error) {
162+
func List(c messagebird.Client, options *ListRequest) (*Conversations, error) {
163163
convList := &Conversations{}
164164
if err := request(c, convList, http.MethodGet, fmt.Sprintf("%s?%s", path, options.QueryParams()), nil); err != nil {
165165
return nil, err
@@ -169,7 +169,7 @@ func List(c messagebird.MessageBirdClient, options *ListRequest) (*Conversations
169169
}
170170

171171
// ListByContact fetches a collection of Conversations of a specific MessageBird contact ID.
172-
func ListByContact(c messagebird.MessageBirdClient, contactId string, options *messagebird.PaginationRequest) (*ConversationsByContact, error) {
172+
func ListByContact(c messagebird.Client, contactId string, options *messagebird.PaginationRequest) (*ConversationsByContact, error) {
173173
reqPath := fmt.Sprintf("%s/%s/%s?%s", path, contactPath, contactId, options.QueryParams())
174174

175175
conv := &ConversationsByContact{}
@@ -181,7 +181,7 @@ func ListByContact(c messagebird.MessageBirdClient, contactId string, options *m
181181
}
182182

183183
// Read fetches a single Conversation based on its ID.
184-
func Read(c messagebird.MessageBirdClient, id string) (*Conversation, error) {
184+
func Read(c messagebird.Client, id string) (*Conversation, error) {
185185
conv := &Conversation{}
186186
if err := request(c, conv, http.MethodGet, path+"/"+id, nil); err != nil {
187187
return nil, err
@@ -192,7 +192,7 @@ func Read(c messagebird.MessageBirdClient, id string) (*Conversation, error) {
192192

193193
// Start creates a conversation by sending an initial message. If an active
194194
// conversation exists for the recipient, it is resumed.
195-
func Start(c messagebird.MessageBirdClient, req *StartRequest) (*Conversation, error) {
195+
func Start(c messagebird.Client, req *StartRequest) (*Conversation, error) {
196196
conv := &Conversation{}
197197
if err := request(c, conv, http.MethodPost, path+"/"+startConversationPath, req); err != nil {
198198
return nil, err
@@ -202,7 +202,7 @@ func Start(c messagebird.MessageBirdClient, req *StartRequest) (*Conversation, e
202202
}
203203

204204
// Reply Send a new message to an existing conversation. In case the conversation is archived, a new conversation is created.
205-
func Reply(c messagebird.MessageBirdClient, conversationID string, req *ReplyRequest) (*Message, error) {
205+
func Reply(c messagebird.Client, conversationID string, req *ReplyRequest) (*Message, error) {
206206
uri := fmt.Sprintf("%s/%s/%s", path, conversationID, messagesPath)
207207

208208
message := &Message{}
@@ -215,7 +215,7 @@ func Reply(c messagebird.MessageBirdClient, conversationID string, req *ReplyReq
215215

216216
// Update changes the conversation's status, so this can be used to (un)archive
217217
// conversations.
218-
func Update(c messagebird.MessageBirdClient, id string, req *UpdateRequest) (*Conversation, error) {
218+
func Update(c messagebird.Client, id string, req *UpdateRequest) (*Conversation, error) {
219219
conv := &Conversation{}
220220
if err := request(c, conv, http.MethodPatch, path+"/"+id, req); err != nil {
221221
return nil, err

conversation/message.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (lr *ListMessagesRequest) QueryParams() string {
212212
// SendMessage send a message to a specific recipient in a specific platform.
213213
// If an active conversation already exists for the recipient, the conversation will be resumed.
214214
// In case there's no active conversation a new one is created.
215-
func SendMessage(c messagebird.MessageBirdClient, options *SendMessageRequest) (*Message, error) {
215+
func SendMessage(c messagebird.Client, options *SendMessageRequest) (*Message, error) {
216216
message := &Message{}
217217
if err := request(c, message, http.MethodPost, sendMessagePath, options); err != nil {
218218
return nil, err
@@ -223,7 +223,7 @@ func SendMessage(c messagebird.MessageBirdClient, options *SendMessageRequest) (
223223

224224
// ListConversationMessages gets a collection of messages from a conversation.
225225
// Pagination can be set in the options.
226-
func ListConversationMessages(c messagebird.MessageBirdClient, conversationID string, options *ListConversationMessagesRequest) (*MessageList, error) {
226+
func ListConversationMessages(c messagebird.Client, conversationID string, options *ListConversationMessagesRequest) (*MessageList, error) {
227227
uri := fmt.Sprintf("%s/%s/%s?%s", path, conversationID, messagesPath, options.QueryParams())
228228

229229
messageList := &MessageList{}
@@ -236,7 +236,7 @@ func ListConversationMessages(c messagebird.MessageBirdClient, conversationID st
236236

237237
// ListMessages gets a collection of messages from a conversation.
238238
// Pagination can be set in the options.
239-
func ListMessages(c messagebird.MessageBirdClient, options *ListMessagesRequest) (*MessageList, error) {
239+
func ListMessages(c messagebird.Client, options *ListMessagesRequest) (*MessageList, error) {
240240
uri := fmt.Sprintf("%s?%s", messagesPath, options.QueryParams())
241241

242242
messageList := &MessageList{}
@@ -248,7 +248,7 @@ func ListMessages(c messagebird.MessageBirdClient, options *ListMessagesRequest)
248248
}
249249

250250
// ReadMessage gets a single message based on its ID.
251-
func ReadMessage(c messagebird.MessageBirdClient, messageID string) (*Message, error) {
251+
func ReadMessage(c messagebird.Client, messageID string) (*Message, error) {
252252
message := &Message{}
253253
if err := request(c, message, http.MethodGet, messagesPath+"/"+messageID, nil); err != nil {
254254
return nil, err

conversation/webhook.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const (
6969

7070
// CreateWebhook registers a webhook that is invoked when something interesting
7171
// happens.
72-
func CreateWebhook(c messagebird.MessageBirdClient, req *WebhookCreateRequest) (*Webhook, error) {
72+
func CreateWebhook(c messagebird.Client, req *WebhookCreateRequest) (*Webhook, error) {
7373
webhook := &Webhook{}
7474
if err := request(c, webhook, http.MethodPost, webhooksPath, req); err != nil {
7575
return nil, err
@@ -80,12 +80,12 @@ func CreateWebhook(c messagebird.MessageBirdClient, req *WebhookCreateRequest) (
8080

8181
// DeleteWebhook ensures an existing webhook is deleted and no longer
8282
// triggered. If the error is nil, the deletion was successful.
83-
func DeleteWebhook(c messagebird.MessageBirdClient, id string) error {
83+
func DeleteWebhook(c messagebird.Client, id string) error {
8484
return request(c, nil, http.MethodDelete, webhooksPath+"/"+id, nil)
8585
}
8686

8787
// ListWebhooks gets a collection of webhooks. Pagination can be set in options.
88-
func ListWebhooks(c messagebird.MessageBirdClient, options *messagebird.PaginationRequest) (*WebhookList, error) {
88+
func ListWebhooks(c messagebird.Client, options *messagebird.PaginationRequest) (*WebhookList, error) {
8989
webhookList := &WebhookList{}
9090
if err := request(c, webhookList, http.MethodGet, webhooksPath+"?"+options.QueryParams(), nil); err != nil {
9191
return nil, err
@@ -95,7 +95,7 @@ func ListWebhooks(c messagebird.MessageBirdClient, options *messagebird.Paginati
9595
}
9696

9797
// ReadWebhook gets a single webhook based on its ID.
98-
func ReadWebhook(c messagebird.MessageBirdClient, id string) (*Webhook, error) {
98+
func ReadWebhook(c messagebird.Client, id string) (*Webhook, error) {
9999
webhook := &Webhook{}
100100
if err := request(c, webhook, http.MethodGet, webhooksPath+"/"+id, nil); err != nil {
101101
return nil, err
@@ -106,7 +106,7 @@ func ReadWebhook(c messagebird.MessageBirdClient, id string) (*Webhook, error) {
106106

107107
// UpdateWebhook updates a single webhook based on its ID with any values set in WebhookUpdateRequest.
108108
// Do not set any values that should not be updated.
109-
func UpdateWebhook(c messagebird.MessageBirdClient, id string, req *WebhookUpdateRequest) (*Webhook, error) {
109+
func UpdateWebhook(c messagebird.Client, id string, req *WebhookUpdateRequest) (*Webhook, error) {
110110
webhook := &Webhook{}
111111
if err := request(c, webhook, http.MethodPatch, webhooksPath+"/"+id, req); err != nil {
112112
return nil, err

group/group.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type Request struct {
5858
Name string `json:"name"`
5959
}
6060

61-
func Create(c messagebird.MessageBirdClient, request *Request) (*Group, error) {
61+
func Create(c messagebird.Client, request *Request) (*Group, error) {
6262
if err := validateCreate(request); err != nil {
6363
return nil, err
6464
}
@@ -81,13 +81,13 @@ func validateCreate(request *Request) error {
8181

8282
// Delete attempts deleting the group with the provided ID. If nil is returned,
8383
// the resource was deleted successfully.
84-
func Delete(c messagebird.MessageBirdClient, id string) error {
84+
func Delete(c messagebird.Client, id string) error {
8585
return c.Request(nil, http.MethodDelete, path+"/"+id, nil)
8686
}
8787

8888
// List retrieves a paginated list of groups, based on the options provided.
8989
// It's worth noting DefaultListOptions.
90-
func List(c messagebird.MessageBirdClient, options *messagebird.PaginationRequest) (*Groups, error) {
90+
func List(c messagebird.Client, options *messagebird.PaginationRequest) (*Groups, error) {
9191
groupList := &Groups{}
9292
if err := c.Request(groupList, http.MethodGet, path+"?"+options.QueryParams(), nil); err != nil {
9393
return nil, err
@@ -113,7 +113,7 @@ func listQuery(options *messagebird.PaginationRequest) (string, error) {
113113
}
114114

115115
// Read retrieves the information of an existing group.
116-
func Read(c messagebird.MessageBirdClient, id string) (*Group, error) {
116+
func Read(c messagebird.Client, id string) (*Group, error) {
117117
group := &Group{}
118118
if err := c.Request(group, http.MethodGet, path+"/"+id, nil); err != nil {
119119
return nil, err
@@ -123,7 +123,7 @@ func Read(c messagebird.MessageBirdClient, id string) (*Group, error) {
123123
}
124124

125125
// Update overrides the group with any values provided in request.
126-
func Update(c messagebird.MessageBirdClient, id string, request *Request) error {
126+
func Update(c messagebird.Client, id string, request *Request) error {
127127
if err := validateUpdate(request); err != nil {
128128
return err
129129
}
@@ -140,7 +140,7 @@ func validateUpdate(request *Request) error {
140140
}
141141

142142
// AddContacts adds a maximum of 50 contacts to the group.
143-
func AddContacts(c messagebird.MessageBirdClient, groupID string, contactIDs []string) error {
143+
func AddContacts(c messagebird.Client, groupID string, contactIDs []string) error {
144144
if err := validateAddContacts(contactIDs); err != nil {
145145
return err
146146
}
@@ -179,7 +179,7 @@ func addContactsData(contactIDs []string) string {
179179
}
180180

181181
// ListContacts lists the contacts that are a member of a group.
182-
func ListContacts(c messagebird.MessageBirdClient, groupID string, options *messagebird.PaginationRequest) (*contact.Contacts, error) {
182+
func ListContacts(c messagebird.Client, groupID string, options *messagebird.PaginationRequest) (*contact.Contacts, error) {
183183
formattedPath := fmt.Sprintf("%s/%s/%s?%s", path, groupID, contactPath, options.QueryParams())
184184

185185
contacts := &contact.Contacts{}
@@ -192,7 +192,7 @@ func ListContacts(c messagebird.MessageBirdClient, groupID string, options *mess
192192

193193
// RemoveContact removes the contact from a group. If nil is returned, the
194194
// operation was successful.
195-
func RemoveContact(c messagebird.MessageBirdClient, groupID, contactID string) error {
195+
func RemoveContact(c messagebird.Client, groupID, contactID string) error {
196196
formattedPath := fmt.Sprintf("%s/%s/contacts/%s", path, groupID, contactID)
197197

198198
return c.Request(nil, http.MethodDelete, formattedPath, nil)

hlr/hlr.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type hlrRequest struct {
4343

4444
// Read looks up an existing HLR object for the specified id that was previously
4545
// created by the NewHLR function.
46-
func Read(c messagebird.MessageBirdClient, id string) (*HLR, error) {
46+
func Read(c messagebird.Client, id string) (*HLR, error) {
4747
hlr := &HLR{}
4848
if err := c.Request(hlr, http.MethodGet, path+"/"+id, nil); err != nil {
4949
return nil, err
@@ -53,7 +53,7 @@ func Read(c messagebird.MessageBirdClient, id string) (*HLR, error) {
5353
}
5454

5555
// List all HLR objects that were previously created by the Create function.
56-
func List(c messagebird.MessageBirdClient) (*HLRList, error) {
56+
func List(c messagebird.Client) (*HLRList, error) {
5757
hlrList := &HLRList{}
5858
if err := c.Request(hlrList, http.MethodGet, path, nil); err != nil {
5959
return nil, err
@@ -63,7 +63,7 @@ func List(c messagebird.MessageBirdClient) (*HLRList, error) {
6363
}
6464

6565
// Create creates a new HLR object.
66-
func Create(c messagebird.MessageBirdClient, msisdn string, reference string) (*HLR, error) {
66+
func Create(c messagebird.Client, msisdn string, reference string) (*HLR, error) {
6767
requestData, err := requestDataForHLR(msisdn, reference)
6868
if err != nil {
6969
return nil, err

internal/mbtest/test_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ func (c *ClientMock) Request(v interface{}, method, path string, data interface{
2727
}
2828

2929
// MockClient initializes a new mock of MessageBird client
30-
func MockClient() messagebird.MessageBirdClient {
30+
func MockClient() messagebird.Client {
3131
return &ClientMock{}
3232
}
3333

3434
// Client initializes a new MessageBird client that uses the
35-
func Client(t *testing.T) *messagebird.Client {
35+
func Client(t *testing.T) *messagebird.BasicClient {
3636
return newClient(t, "")
3737
}
3838

39-
func newClient(t *testing.T, accessKey string) *messagebird.Client {
39+
func newClient(t *testing.T, accessKey string) *messagebird.BasicClient {
4040
transport := &http.Transport{
4141
DialTLS: func(network, _ string) (net.Conn, error) {
4242
addr := server.Listener.Addr().String()

0 commit comments

Comments
 (0)