@@ -22,12 +22,27 @@ import (
22
22
23
23
const (
24
24
// ClientVersion is used in User-Agent request header to provide server with API level.
25
- ClientVersion = "4.1 .0"
25
+ ClientVersion = "4.2 .0"
26
26
27
27
// Endpoint points you to MessageBird REST API.
28
28
Endpoint = "https://rest.messagebird.com"
29
29
)
30
30
31
+ const (
32
+ // HLRPath represents the path to the HLR resource.
33
+ HLRPath = "hlr"
34
+ // MessagePath represents the path to the Message resource.
35
+ MessagePath = "messages"
36
+ // MMSPath represents the path to the MMS resource.
37
+ MMSPath = "mms"
38
+ // VoiceMessagePath represents the path to the VoiceMessage resource.
39
+ VoiceMessagePath = "voicemessages"
40
+ // VerifyPath represents the path to the Verify resource.
41
+ VerifyPath = "verify"
42
+ // LookupPath represents the path to the Lookup resource.
43
+ LookupPath = "lookup"
44
+ )
45
+
31
46
var (
32
47
// ErrResponse is returned when we were able to contact API but request was not successful and contains error details.
33
48
ErrResponse = errors .New ("The MessageBird API returned an error" )
@@ -140,7 +155,7 @@ func (c *Client) Balance() (*Balance, error) {
140
155
// created by the NewHLR function.
141
156
func (c * Client ) HLR (id string ) (* HLR , error ) {
142
157
hlr := & HLR {}
143
- if err := c .request (hlr , "hlr /"+ id , nil ); err != nil {
158
+ if err := c .request (hlr , HLRPath + " /"+ id , nil ); err != nil {
144
159
if err == ErrResponse {
145
160
return hlr , err
146
161
}
@@ -151,6 +166,21 @@ func (c *Client) HLR(id string) (*HLR, error) {
151
166
return hlr , nil
152
167
}
153
168
169
+ // HLRs lists all HLR objects that were previously created by the NewHLR
170
+ // function.
171
+ func (c * Client ) HLRs () (* HLRList , error ) {
172
+ hlrList := & HLRList {}
173
+ if err := c .request (hlrList , HLRPath , nil ); err != nil {
174
+ if err == ErrResponse {
175
+ return hlrList , err
176
+ }
177
+
178
+ return nil , err
179
+ }
180
+
181
+ return hlrList , nil
182
+ }
183
+
154
184
// NewHLR retrieves the information of an existing HLR.
155
185
func (c * Client ) NewHLR (msisdn , reference string ) (* HLR , error ) {
156
186
params := & url.Values {
@@ -159,7 +189,7 @@ func (c *Client) NewHLR(msisdn, reference string) (*HLR, error) {
159
189
}
160
190
161
191
hlr := & HLR {}
162
- if err := c .request (hlr , "hlr" , params ); err != nil {
192
+ if err := c .request (hlr , HLRPath , params ); err != nil {
163
193
if err == ErrResponse {
164
194
return hlr , err
165
195
}
@@ -173,7 +203,7 @@ func (c *Client) NewHLR(msisdn, reference string) (*HLR, error) {
173
203
// Message retrieves the information of an existing Message.
174
204
func (c * Client ) Message (id string ) (* Message , error ) {
175
205
message := & Message {}
176
- if err := c .request (message , "messages /"+ id , nil ); err != nil {
206
+ if err := c .request (message , MessagePath + " /"+ id , nil ); err != nil {
177
207
if err == ErrResponse {
178
208
return message , err
179
209
}
@@ -184,6 +214,25 @@ func (c *Client) Message(id string) (*Message, error) {
184
214
return message , nil
185
215
}
186
216
217
+ // Messages retrieves all messages of the user represented as a MessageList object.
218
+ func (c * Client ) Messages (msgListParams * MessageListParams ) (* MessageList , error ) {
219
+ messageList := & MessageList {}
220
+ params , err := paramsForMessageList (msgListParams )
221
+ if err != nil {
222
+ return messageList , err
223
+ }
224
+
225
+ if err := c .request (messageList , MessagePath + "?" + params .Encode (), nil ); err != nil {
226
+ if err == ErrResponse {
227
+ return messageList , err
228
+ }
229
+
230
+ return nil , err
231
+ }
232
+
233
+ return messageList , nil
234
+ }
235
+
187
236
// NewMessage creates a new message for one or more recipients.
188
237
func (c * Client ) NewMessage (originator string , recipients []string , body string , msgParams * MessageParams ) (* Message , error ) {
189
238
params , err := paramsForMessage (msgParams )
@@ -196,7 +245,7 @@ func (c *Client) NewMessage(originator string, recipients []string, body string,
196
245
params .Set ("recipients" , strings .Join (recipients , "," ))
197
246
198
247
message := & Message {}
199
- if err := c .request (message , "messages" , params ); err != nil {
248
+ if err := c .request (message , MessagePath , params ); err != nil {
200
249
if err == ErrResponse {
201
250
return message , err
202
251
}
@@ -210,7 +259,7 @@ func (c *Client) NewMessage(originator string, recipients []string, body string,
210
259
// MMSMessage retrieves the information of an existing MmsMessage.
211
260
func (c * Client ) MMSMessage (id string ) (* MMSMessage , error ) {
212
261
mmsMessage := & MMSMessage {}
213
- if err := c .request (mmsMessage , "mms /"+ id , nil ); err != nil {
262
+ if err := c .request (mmsMessage , MMSPath + " /"+ id , nil ); err != nil {
214
263
if err == ErrResponse {
215
264
return mmsMessage , err
216
265
}
@@ -232,7 +281,7 @@ func (c *Client) NewMMSMessage(originator string, recipients []string, msgParams
232
281
params .Set ("recipients" , strings .Join (recipients , "," ))
233
282
234
283
mmsMessage := & MMSMessage {}
235
- if err := c .request (mmsMessage , "mms" , params ); err != nil {
284
+ if err := c .request (mmsMessage , MMSPath , params ); err != nil {
236
285
if err == ErrResponse {
237
286
return mmsMessage , err
238
287
}
@@ -246,7 +295,7 @@ func (c *Client) NewMMSMessage(originator string, recipients []string, msgParams
246
295
// VoiceMessage retrieves the information of an existing VoiceMessage.
247
296
func (c * Client ) VoiceMessage (id string ) (* VoiceMessage , error ) {
248
297
message := & VoiceMessage {}
249
- if err := c .request (message , "voicemessages /"+ id , nil ); err != nil {
298
+ if err := c .request (message , VoiceMessagePath + " /"+ id , nil ); err != nil {
250
299
if err == ErrResponse {
251
300
return message , err
252
301
}
@@ -257,14 +306,28 @@ func (c *Client) VoiceMessage(id string) (*VoiceMessage, error) {
257
306
return message , nil
258
307
}
259
308
309
+ // VoiceMessages retrieves all VoiceMessages of the user.
310
+ func (c * Client ) VoiceMessages () (* VoiceMessageList , error ) {
311
+ messageList := & VoiceMessageList {}
312
+ if err := c .request (messageList , VoiceMessagePath , nil ); err != nil {
313
+ if err == ErrResponse {
314
+ return messageList , err
315
+ }
316
+
317
+ return nil , err
318
+ }
319
+
320
+ return messageList , nil
321
+ }
322
+
260
323
// NewVoiceMessage creates a new voice message for one or more recipients.
261
324
func (c * Client ) NewVoiceMessage (recipients []string , body string , params * VoiceMessageParams ) (* VoiceMessage , error ) {
262
325
urlParams := paramsForVoiceMessage (params )
263
326
urlParams .Set ("body" , body )
264
327
urlParams .Set ("recipients" , strings .Join (recipients , "," ))
265
328
266
329
message := & VoiceMessage {}
267
- if err := c .request (message , "voicemessages" , urlParams ); err != nil {
330
+ if err := c .request (message , VoiceMessagePath , urlParams ); err != nil {
268
331
if err == ErrResponse {
269
332
return message , err
270
333
}
@@ -281,7 +344,7 @@ func (c *Client) NewVerify(recipient string, params *VerifyParams) (*Verify, err
281
344
urlParams .Set ("recipient" , recipient )
282
345
283
346
verify := & Verify {}
284
- if err := c .request (verify , "verify" , urlParams ); err != nil {
347
+ if err := c .request (verify , VerifyPath , urlParams ); err != nil {
285
348
if err == ErrResponse {
286
349
return verify , err
287
350
}
@@ -297,7 +360,7 @@ func (c *Client) VerifyToken(id, token string) (*Verify, error) {
297
360
params := & url.Values {}
298
361
params .Set ("token" , token )
299
362
300
- path := "verify /" + id + "?" + params .Encode ()
363
+ path := VerifyPath + " /" + id + "?" + params .Encode ()
301
364
302
365
verify := & Verify {}
303
366
if err := c .request (verify , path , nil ); err != nil {
@@ -314,7 +377,7 @@ func (c *Client) VerifyToken(id, token string) (*Verify, error) {
314
377
// Lookup performs a new lookup for the specified number.
315
378
func (c * Client ) Lookup (phoneNumber string , params * LookupParams ) (* Lookup , error ) {
316
379
urlParams := paramsForLookup (params )
317
- path := "lookup /" + phoneNumber + "?" + urlParams .Encode ()
380
+ path := LookupPath + " /" + phoneNumber + "?" + urlParams .Encode ()
318
381
319
382
lookup := & Lookup {}
320
383
if err := c .request (lookup , path , nil ); err != nil {
@@ -331,7 +394,7 @@ func (c *Client) Lookup(phoneNumber string, params *LookupParams) (*Lookup, erro
331
394
// NewLookupHLR creates a new HLR lookup for the specified number.
332
395
func (c * Client ) NewLookupHLR (phoneNumber string , params * LookupParams ) (* HLR , error ) {
333
396
urlParams := paramsForLookup (params )
334
- path := "lookup /" + phoneNumber + "/hlr"
397
+ path := LookupPath + " /" + phoneNumber + "/" + HLRPath
335
398
336
399
hlr := & HLR {}
337
400
if err := c .request (hlr , path , urlParams ); err != nil {
@@ -348,7 +411,7 @@ func (c *Client) NewLookupHLR(phoneNumber string, params *LookupParams) (*HLR, e
348
411
// LookupHLR performs a HLR lookup for the specified number.
349
412
func (c * Client ) LookupHLR (phoneNumber string , params * LookupParams ) (* HLR , error ) {
350
413
urlParams := paramsForLookup (params )
351
- path := "lookup /" + phoneNumber + "/hlr ?" + urlParams .Encode ()
414
+ path := LookupPath + " /" + phoneNumber + "/" + HLRPath + " ?" + urlParams .Encode ()
352
415
353
416
hlr := & HLR {}
354
417
if err := c .request (hlr , path , nil ); err != nil {
0 commit comments