Skip to content

Commit 5163792

Browse files
committed
Clean up code
1 parent c64590e commit 5163792

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

group/group.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ func Create(c *messagebird.Client, request *Request) (*Group, error) {
7272
}
7373

7474
group := &Group{}
75-
76-
err := c.Request(group, http.MethodPost, path, request)
77-
if err != nil {
75+
if err := c.Request(group, http.MethodPost, path, request); err != nil {
7876
return nil, err
7977
}
8078

@@ -104,7 +102,6 @@ func List(c *messagebird.Client, options *ListOptions) (*GroupList, error) {
104102
}
105103

106104
groupList := &GroupList{}
107-
108105
if err := c.Request(groupList, http.MethodGet, path+"?"+query, nil); err != nil {
109106
return nil, err
110107
}
@@ -132,9 +129,7 @@ func listQuery(options *ListOptions) (string, error) {
132129
// Read retrieves the information of an existing group.
133130
func Read(c *messagebird.Client, id string) (*Group, error) {
134131
group := &Group{}
135-
136-
err := c.Request(group, http.MethodGet, path+"/"+id, nil)
137-
if err != nil {
132+
if err := c.Request(group, http.MethodGet, path+"/"+id, nil); err != nil {
138133
return nil, err
139134
}
140135

@@ -165,7 +160,6 @@ func AddContacts(c *messagebird.Client, groupID string, contactIDS []string) err
165160
}
166161

167162
query := addContactsQuery(contactIDS)
168-
169163
formattedPath := fmt.Sprintf("%s/%s/%s?%s", path, groupID, contactPath, query)
170164

171165
return c.Request(nil, http.MethodGet, formattedPath, nil)
@@ -194,7 +188,6 @@ func validateAddContacts(contactIDS []string) error {
194188
func addContactsQuery(contactIDS []string) string {
195189
// Slice's length is one bigger than len(IDs) for the _method param.
196190
params := make([]string, 0, len(contactIDS)+1)
197-
198191
params = append(params, "_method="+http.MethodPut)
199192

200193
for _, contactID := range contactIDS {
@@ -214,10 +207,7 @@ func ListContacts(c *messagebird.Client, groupID string, options *ListOptions) (
214207
formattedPath := fmt.Sprintf("%s/%s/%s?%s", path, groupID, contactPath, query)
215208

216209
contacts := &contact.ContactList{}
217-
218-
err = c.Request(contacts, http.MethodGet, formattedPath, nil)
219-
220-
if err != nil {
210+
if err = c.Request(contacts, http.MethodGet, formattedPath, nil); err != nil {
221211
return nil, err
222212
}
223213

group/group_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func TestAddContactsWithEmptyContacts(t *testing.T) {
196196
func TestAddContactsWithTooManyContacts(t *testing.T) {
197197
client := mbtest.Client(t)
198198

199+
// Only 50 contacts are allowed at a time.
199200
contactIDS := make([]string, 51)
200201

201202
if err := AddContacts(client, "group-id", contactIDS); err == nil {

0 commit comments

Comments
 (0)