Skip to content

Commit 61decfc

Browse files
committed
Use consts for HTTP verbs
1 parent f5faf4f commit 61decfc

File tree

7 files changed

+34
-30
lines changed

7 files changed

+34
-30
lines changed

client.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (c *Client) Request(v interface{}, method, path string, data interface{}) e
138138
// with the access key.
139139
func (c *Client) Balance() (*Balance, error) {
140140
balance := &Balance{}
141-
if err := c.Request(balance, "GET", "balance", nil); err != nil {
141+
if err := c.Request(balance, http.MethodGet, "balance", nil); err != nil {
142142
if err == ErrResponse {
143143
return balance, err
144144
}
@@ -153,7 +153,7 @@ func (c *Client) Balance() (*Balance, error) {
153153
// created by the NewHLR function.
154154
func (c *Client) HLR(id string) (*HLR, error) {
155155
hlr := &HLR{}
156-
if err := c.Request(hlr, "GET", HLRPath+"/"+id, nil); err != nil {
156+
if err := c.Request(hlr, http.MethodGet, HLRPath+"/"+id, nil); err != nil {
157157
if err == ErrResponse {
158158
return hlr, err
159159
}
@@ -168,7 +168,7 @@ func (c *Client) HLR(id string) (*HLR, error) {
168168
// function.
169169
func (c *Client) HLRs() (*HLRList, error) {
170170
hlrList := &HLRList{}
171-
if err := c.Request(hlrList, "GET", HLRPath, nil); err != nil {
171+
if err := c.Request(hlrList, http.MethodGet, HLRPath, nil); err != nil {
172172
if err == ErrResponse {
173173
return hlrList, err
174174
}
@@ -188,7 +188,7 @@ func (c *Client) NewHLR(msisdn string, reference string) (*HLR, error) {
188188

189189
hlr := &HLR{}
190190

191-
if err := c.Request(hlr, "POST", HLRPath, requestData); err != nil {
191+
if err := c.Request(hlr, http.MethodPost, HLRPath, requestData); err != nil {
192192
if err == ErrResponse {
193193
return hlr, err
194194
}
@@ -202,7 +202,7 @@ func (c *Client) NewHLR(msisdn string, reference string) (*HLR, error) {
202202
// Message retrieves the information of an existing Message.
203203
func (c *Client) Message(id string) (*Message, error) {
204204
message := &Message{}
205-
if err := c.Request(message, "GET", MessagePath+"/"+id, nil); err != nil {
205+
if err := c.Request(message, http.MethodGet, MessagePath+"/"+id, nil); err != nil {
206206
if err == ErrResponse {
207207
return message, err
208208
}
@@ -221,7 +221,7 @@ func (c *Client) Messages(msgListParams *MessageListParams) (*MessageList, error
221221
return messageList, err
222222
}
223223

224-
if err := c.Request(messageList, "GET", MessagePath+"?"+params.Encode(), nil); err != nil {
224+
if err := c.Request(messageList, http.MethodGet, MessagePath+"?"+params.Encode(), nil); err != nil {
225225
if err == ErrResponse {
226226
return messageList, err
227227
}
@@ -240,7 +240,7 @@ func (c *Client) NewMessage(originator string, recipients []string, body string,
240240
}
241241

242242
message := &Message{}
243-
if err := c.Request(message, "POST", MessagePath, requestData); err != nil {
243+
if err := c.Request(message, http.MethodPost, MessagePath, requestData); err != nil {
244244
if err == ErrResponse {
245245
return message, err
246246
}
@@ -254,7 +254,7 @@ func (c *Client) NewMessage(originator string, recipients []string, body string,
254254
// MMSMessage retrieves the information of an existing MmsMessage.
255255
func (c *Client) MMSMessage(id string) (*MMSMessage, error) {
256256
mmsMessage := &MMSMessage{}
257-
if err := c.Request(mmsMessage, "GET", MMSPath+"/"+id, nil); err != nil {
257+
if err := c.Request(mmsMessage, http.MethodGet, MMSPath+"/"+id, nil); err != nil {
258258
if err == ErrResponse {
259259
return mmsMessage, err
260260
}
@@ -276,7 +276,7 @@ func (c *Client) NewMMSMessage(originator string, recipients []string, msgParams
276276
params.Set("recipients", strings.Join(recipients, ","))
277277

278278
mmsMessage := &MMSMessage{}
279-
if err := c.Request(mmsMessage, "POST", MMSPath, params); err != nil {
279+
if err := c.Request(mmsMessage, http.MethodPost, MMSPath, params); err != nil {
280280
if err == ErrResponse {
281281
return mmsMessage, err
282282
}
@@ -290,7 +290,7 @@ func (c *Client) NewMMSMessage(originator string, recipients []string, msgParams
290290
// VoiceMessage retrieves the information of an existing VoiceMessage.
291291
func (c *Client) VoiceMessage(id string) (*VoiceMessage, error) {
292292
message := &VoiceMessage{}
293-
if err := c.Request(message, "GET", VoiceMessagePath+"/"+id, nil); err != nil {
293+
if err := c.Request(message, http.MethodGet, VoiceMessagePath+"/"+id, nil); err != nil {
294294
if err == ErrResponse {
295295
return message, err
296296
}
@@ -304,7 +304,7 @@ func (c *Client) VoiceMessage(id string) (*VoiceMessage, error) {
304304
// VoiceMessages retrieves all VoiceMessages of the user.
305305
func (c *Client) VoiceMessages() (*VoiceMessageList, error) {
306306
messageList := &VoiceMessageList{}
307-
if err := c.Request(messageList, "GET", VoiceMessagePath, nil); err != nil {
307+
if err := c.Request(messageList, http.MethodGet, VoiceMessagePath, nil); err != nil {
308308
if err == ErrResponse {
309309
return messageList, err
310310
}
@@ -323,7 +323,7 @@ func (c *Client) NewVoiceMessage(recipients []string, body string, params *Voice
323323
}
324324

325325
message := &VoiceMessage{}
326-
if err := c.Request(message, "POST", VoiceMessagePath, requestData); err != nil {
326+
if err := c.Request(message, http.MethodPost, VoiceMessagePath, requestData); err != nil {
327327
if err == ErrResponse {
328328
return message, err
329329
}
@@ -342,7 +342,7 @@ func (c *Client) NewVerify(recipient string, params *VerifyParams) (*Verify, err
342342
}
343343

344344
verify := &Verify{}
345-
if err := c.Request(verify, "POST", VerifyPath, requestData); err != nil {
345+
if err := c.Request(verify, http.MethodPost, VerifyPath, requestData); err != nil {
346346
if err == ErrResponse {
347347
return verify, err
348348
}
@@ -361,7 +361,7 @@ func (c *Client) VerifyToken(id, token string) (*Verify, error) {
361361
path := VerifyPath + "/" + id + "?" + params.Encode()
362362

363363
verify := &Verify{}
364-
if err := c.Request(verify, "GET", path, nil); err != nil {
364+
if err := c.Request(verify, http.MethodGet, path, nil); err != nil {
365365
if err == ErrResponse {
366366
return verify, err
367367
}
@@ -378,7 +378,7 @@ func (c *Client) Lookup(phoneNumber string, params *LookupParams) (*Lookup, erro
378378
path := LookupPath + "/" + phoneNumber + "?" + urlParams.Encode()
379379

380380
lookup := &Lookup{}
381-
if err := c.Request(lookup, "POST", path, nil); err != nil {
381+
if err := c.Request(lookup, http.MethodPost, path, nil); err != nil {
382382
if err == ErrResponse {
383383
return lookup, err
384384
}
@@ -395,7 +395,7 @@ func (c *Client) NewLookupHLR(phoneNumber string, params *LookupParams) (*HLR, e
395395
path := LookupPath + "/" + phoneNumber + "/" + HLRPath
396396

397397
hlr := &HLR{}
398-
if err := c.Request(hlr, "POST", path, requestData); err != nil {
398+
if err := c.Request(hlr, http.MethodPost, path, requestData); err != nil {
399399
if err == ErrResponse {
400400
return hlr, err
401401
}
@@ -412,7 +412,7 @@ func (c *Client) LookupHLR(phoneNumber string, params *LookupParams) (*HLR, erro
412412
path := LookupPath + "/" + phoneNumber + "/" + HLRPath + "?" + urlParams.Encode()
413413

414414
hlr := &HLR{}
415-
if err := c.Request(hlr, "GET", path, nil); err != nil {
415+
if err := c.Request(hlr, http.MethodGet, path, nil); err != nil {
416416
if err == ErrResponse {
417417
return hlr, err
418418
}

voice/call.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package voice
33
import (
44
"encoding/json"
55
"fmt"
6+
"net/http"
67
"reflect"
78
"time"
89

@@ -107,7 +108,7 @@ func (call *Call) UnmarshalJSON(data []byte) error {
107108
// An error is returned if no such call flow exists or is accessible.
108109
func CallByID(client *messagebird.Client, id string) (*Call, error) {
109110
call := &Call{}
110-
err := client.Request(call, "GET", "calls/"+id, nil)
111+
err := client.Request(call, http.MethodGet, "calls/"+id, nil)
111112
return call, err
112113
}
113114

@@ -140,15 +141,15 @@ func InitiateCall(client *messagebird.Client, source, destination string, callfl
140141
body.Webhook.Token = webhook.Token
141142
}
142143
call := &Call{}
143-
err := client.Request(call, "POST", "calls/", body)
144+
err := client.Request(call, http.MethodPost, "calls/", body)
144145
return call, err
145146
}
146147

147148
// Delete deletes the Call.
148149
//
149150
// If the call is in progress, it hangs up all legs.
150151
func (call *Call) Delete(client *messagebird.Client) error {
151-
return client.Request(nil, "DELETE", "calls/"+call.ID, nil)
152+
return client.Request(nil, http.MethodDelete, "calls/"+call.ID, nil)
152153
}
153154

154155
// Legs returns a paginator over all Legs associated with a call.

voice/callflow.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package voice
33
import (
44
"encoding/json"
55
"fmt"
6+
"net/http"
67
"reflect"
78
"time"
89

@@ -105,7 +106,7 @@ func (callflow *CallFlow) UnmarshalJSON(data []byte) error {
105106
// An error is returned if no such call flow exists or is accessible.
106107
func CallFlowByID(client *messagebird.Client, id string) (*CallFlow, error) {
107108
callflow := &CallFlow{}
108-
err := client.Request(callflow, "GET", "call-flows/"+id, nil)
109+
err := client.Request(callflow, http.MethodGet, "call-flows/"+id, nil)
109110
return callflow, err
110111
}
111112

@@ -121,7 +122,7 @@ func (callflow *CallFlow) Create(client *messagebird.Client) error {
121122
var data struct {
122123
Data []CallFlow `json:"data"`
123124
}
124-
if err := client.Request(&data, "POST", "call-flows/", callflow); err != nil {
125+
if err := client.Request(&data, http.MethodPost, "call-flows/", callflow); err != nil {
125126
return err
126127
}
127128
*callflow = data.Data[0]
@@ -135,7 +136,7 @@ func (callflow *CallFlow) Update(client *messagebird.Client) error {
135136
var data struct {
136137
Data []CallFlow `json:"data"`
137138
}
138-
if err := client.Request(&data, "PUT", "call-flows/"+callflow.ID, callflow); err != nil {
139+
if err := client.Request(&data, http.MethodPut, "call-flows/"+callflow.ID, callflow); err != nil {
139140
return err
140141
}
141142
*callflow = data.Data[0]
@@ -144,7 +145,7 @@ func (callflow *CallFlow) Update(client *messagebird.Client) error {
144145

145146
// Delete deletes the CallFlow.
146147
func (callflow *CallFlow) Delete(client *messagebird.Client) error {
147-
return client.Request(nil, "DELETE", "call-flows/"+callflow.ID, nil)
148+
return client.Request(nil, http.MethodDelete, "call-flows/"+callflow.ID, nil)
148149
}
149150

150151
// A CallFlowStep is a single step that can be taken in a callflow.

voice/paginator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package voice
33
import (
44
"fmt"
55
"io"
6+
"net/http"
67
"reflect"
78

89
messagebird "github.com/messagebird/go-rest-api"
@@ -61,7 +62,7 @@ func (pag *Paginator) NextPage() (interface{}, error) {
6162
})
6263
rawVal := reflect.New(rawType)
6364

64-
if err := pag.client.Request(rawVal.Interface(), "GET", fmt.Sprintf("%s?page=%d", pag.endpoint, pag.nextPage), nil); err != nil {
65+
if err := pag.client.Request(rawVal.Interface(), http.MethodGet, fmt.Sprintf("%s?page=%d", pag.endpoint, pag.nextPage), nil); err != nil {
6566
return nil, err
6667
}
6768

voice/recording.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (rec *Recording) Transcriptions(client *messagebird.Client) *Paginator {
101101

102102
// DownloadFile streams the recorded WAV file.
103103
func (rec *Recording) DownloadFile(client *messagebird.Client) (io.ReadCloser, error) {
104-
req, err := http.NewRequest("GET", messagebird.Endpoint+rec.links["file"], nil)
104+
req, err := http.NewRequest(http.MethodGet, messagebird.Endpoint+rec.links["file"], nil)
105105
if err != nil {
106106
return nil, err
107107
}

voice/transcription.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (trans *Transcription) UnmarshalJSON(data []byte) error {
7272
//
7373
// This is a plain text file.
7474
func (trans *Transcription) Contents(client *messagebird.Client) (string, error) {
75-
req, err := http.NewRequest("GET", messagebird.Endpoint+trans.links["file"], nil)
75+
req, err := http.NewRequest(http.MethodGet, messagebird.Endpoint+trans.links["file"], nil)
7676
if err != nil {
7777
return "", err
7878
}

voice/webhook.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package voice
33
import (
44
"encoding/json"
55
"fmt"
6+
"net/http"
67
"reflect"
78
"time"
89

@@ -79,7 +80,7 @@ func CreateWebHook(client *messagebird.Client, url, token string) (*Webhook, err
7980
Token: token,
8081
}
8182
wh := &Webhook{}
82-
if err := client.Request(wh, "POST", "webhooks/", data); err != nil {
83+
if err := client.Request(wh, http.MethodPost, "webhooks/", data); err != nil {
8384
return nil, err
8485
}
8586
return wh, nil
@@ -90,7 +91,7 @@ func (wh *Webhook) Update(client *messagebird.Client) error {
9091
var data struct {
9192
Data []Webhook `json:"data"`
9293
}
93-
if err := client.Request(&data, "PUT", "webhooks/"+wh.ID, wh); err != nil {
94+
if err := client.Request(&data, http.MethodPut, "webhooks/"+wh.ID, wh); err != nil {
9495
return err
9596
}
9697
*wh = data.Data[0]
@@ -99,5 +100,5 @@ func (wh *Webhook) Update(client *messagebird.Client) error {
99100

100101
// Delete deletes a webhook.
101102
func (wh *Webhook) Delete(client *messagebird.Client) error {
102-
return client.Request(nil, "DELETE", "webhooks/"+wh.ID, nil)
103+
return client.Request(nil, http.MethodDelete, "webhooks/"+wh.ID, nil)
103104
}

0 commit comments

Comments
 (0)