Skip to content

Commit 9d345ae

Browse files
committed
Merge branch 'refactor-package' into use-testdata
2 parents c97dfdc + 836f745 commit 9d345ae

File tree

11 files changed

+189
-189
lines changed

11 files changed

+189
-189
lines changed

lookup/lookup.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ type Lookup struct {
2727
HLR *hlr.HLR
2828
}
2929

30-
// LookupParams provide additional lookup information.
31-
type LookupParams struct {
30+
// Params provide additional lookup information.
31+
type Params struct {
3232
CountryCode string
3333
Reference string
3434
}
@@ -45,7 +45,7 @@ const hlrPath = "hlr"
4545
const lookupPath = "lookup"
4646

4747
// Create performs a new lookup for the specified number.
48-
func Create(c *messagebird.Client, phoneNumber string, params *LookupParams) (*Lookup, error) {
48+
func Create(c *messagebird.Client, phoneNumber string, params *Params) (*Lookup, error) {
4949
urlParams := paramsForLookup(params)
5050
path := lookupPath + "/" + phoneNumber + "?" + urlParams.Encode()
5151

@@ -58,7 +58,7 @@ func Create(c *messagebird.Client, phoneNumber string, params *LookupParams) (*L
5858
}
5959

6060
// CreateHLR creates a new HLR lookup for the specified number.
61-
func CreateHLR(c *messagebird.Client, phoneNumber string, params *LookupParams) (*hlr.HLR, error) {
61+
func CreateHLR(c *messagebird.Client, phoneNumber string, params *Params) (*hlr.HLR, error) {
6262
requestData := requestDataForLookup(params)
6363
path := lookupPath + "/" + phoneNumber + "/" + hlrPath
6464

@@ -71,7 +71,7 @@ func CreateHLR(c *messagebird.Client, phoneNumber string, params *LookupParams)
7171
}
7272

7373
// ReadHLR performs a HLR lookup for the specified number.
74-
func ReadHLR(c *messagebird.Client, phoneNumber string, params *LookupParams) (*hlr.HLR, error) {
74+
func ReadHLR(c *messagebird.Client, phoneNumber string, params *Params) (*hlr.HLR, error) {
7575
urlParams := paramsForLookup(params)
7676
path := lookupPath + "/" + phoneNumber + "/" + hlrPath + "?" + urlParams.Encode()
7777

@@ -83,7 +83,7 @@ func ReadHLR(c *messagebird.Client, phoneNumber string, params *LookupParams) (*
8383
return hlr, nil
8484
}
8585

86-
func requestDataForLookup(params *LookupParams) *lookupRequest {
86+
func requestDataForLookup(params *Params) *lookupRequest {
8787
request := &lookupRequest{}
8888

8989
if params == nil {
@@ -96,7 +96,7 @@ func requestDataForLookup(params *LookupParams) *lookupRequest {
9696
return request
9797
}
9898

99-
func paramsForLookup(params *LookupParams) *url.Values {
99+
func paramsForLookup(params *Params) *url.Values {
100100
urlParams := &url.Values{}
101101

102102
if params == nil {

lookup/lookup_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestCreate(t *testing.T) {
1818
client := messagebirdtest.Client(t)
1919

2020
phoneNumber := "31624971134"
21-
lookup, err := Create(client, phoneNumber, &LookupParams{CountryCode: "NL"})
21+
lookup, err := Create(client, phoneNumber, &Params{CountryCode: "NL"})
2222
if err != nil {
2323
t.Fatalf("Didn't expect error while doing the lookup: %s", err)
2424
}
@@ -63,15 +63,15 @@ func TestReadHLR(t *testing.T) {
6363
messagebirdtest.WillReturnTestdata(t, "lookupHLRObject.json", http.StatusOK)
6464
client := messagebirdtest.Client(t)
6565

66-
hlr, err := ReadHLR(client, "31624971134", &LookupParams{CountryCode: "NL"})
66+
hlr, err := ReadHLR(client, "31624971134", &Params{CountryCode: "NL"})
6767
if err != nil {
6868
t.Fatalf("Didn't expect error while doing the lookup: %s", err)
6969
}
7070
checkHLR(t, hlr)
7171
}
7272

7373
func TestRequestDataForLookupHLR(t *testing.T) {
74-
lookupParams := &LookupParams{
74+
lookupParams := &Params{
7575
CountryCode: "NL",
7676
Reference: "MyReference",
7777
}
@@ -89,7 +89,7 @@ func TestCreateHLR(t *testing.T) {
8989
messagebirdtest.WillReturnTestdata(t, "lookupHLRObject.json", http.StatusCreated)
9090
client := messagebirdtest.Client(t)
9191

92-
hlr, err := CreateHLR(client, "31624971134", &LookupParams{CountryCode: "NL", Reference: "reference2000"})
92+
hlr, err := CreateHLR(client, "31624971134", &Params{CountryCode: "NL", Reference: "reference2000"})
9393
if err != nil {
9494
t.Fatalf("Didn't expect error while doing the lookup: %s", err)
9595
}

message/message.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ type MessageList struct {
4444
Items []Message
4545
}
4646

47-
// MessageParams provide additional message send options and used in URL as params.
48-
type MessageParams struct {
47+
// Params provide additional message send options and used in URL as params.
48+
type Params struct {
4949
Type string
5050
Reference string
5151
Validity int
@@ -56,8 +56,8 @@ type MessageParams struct {
5656
ScheduledDatetime time.Time
5757
}
5858

59-
// MessageListParams provides additional message list options.
60-
type MessageListParams struct {
59+
// ListParams provides additional message list options.
60+
type ListParams struct {
6161
Originator string
6262
Direction string
6363
Type string
@@ -94,7 +94,7 @@ func Read(c *messagebird.Client, id string) (*Message, error) {
9494
}
9595

9696
// List retrieves all messages of the user represented as a MessageList object.
97-
func List(c *messagebird.Client, msgListParams *MessageListParams) (*MessageList, error) {
97+
func List(c *messagebird.Client, msgListParams *ListParams) (*MessageList, error) {
9898
messageList := &MessageList{}
9999
params, err := paramsForMessageList(msgListParams)
100100
if err != nil {
@@ -109,7 +109,7 @@ func List(c *messagebird.Client, msgListParams *MessageListParams) (*MessageList
109109
}
110110

111111
// Create creates a new message for one or more recipients.
112-
func Create(c *messagebird.Client, originator string, recipients []string, body string, msgParams *MessageParams) (*Message, error) {
112+
func Create(c *messagebird.Client, originator string, recipients []string, body string, msgParams *Params) (*Message, error) {
113113
requestData, err := requestDataForMessage(originator, recipients, body, msgParams)
114114
if err != nil {
115115
return nil, err
@@ -123,7 +123,7 @@ func Create(c *messagebird.Client, originator string, recipients []string, body
123123
return message, nil
124124
}
125125

126-
func requestDataForMessage(originator string, recipients []string, body string, params *MessageParams) (*messageRequest, error) {
126+
func requestDataForMessage(originator string, recipients []string, body string, params *Params) (*messageRequest, error) {
127127
if originator == "" {
128128
return nil, errors.New("originator is required")
129129
}
@@ -167,7 +167,7 @@ func requestDataForMessage(originator string, recipients []string, body string,
167167

168168
// paramsForMessageList converts the specified MessageListParams struct to a
169169
// url.Values pointer and returns it.
170-
func paramsForMessageList(params *MessageListParams) (*url.Values, error) {
170+
func paramsForMessageList(params *ListParams) (*url.Values, error) {
171171
urlParams := &url.Values{}
172172

173173
if params == nil {

message/message_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestCreateWithParams(t *testing.T) {
131131
messagebirdtest.WillReturnTestdata(t, "messageWithParamsObject.json", http.StatusOK)
132132
client := messagebirdtest.Client(t)
133133

134-
params := &MessageParams{
134+
params := &Params{
135135
Type: "sms",
136136
Reference: "TestReference",
137137
Validity: 13,
@@ -169,7 +169,7 @@ func TestCreateWithBinaryType(t *testing.T) {
169169
messagebirdtest.WillReturnTestdata(t, "binaryMessageObject.json", http.StatusOK)
170170
client := messagebirdtest.Client(t)
171171

172-
params := &MessageParams{
172+
params := &Params{
173173
Type: "binary",
174174
TypeDetails: TypeDetails{"udh": "050003340201"},
175175
}
@@ -196,7 +196,7 @@ func TestCreateWithPremiumType(t *testing.T) {
196196
messagebirdtest.WillReturnTestdata(t, "premiumMessageObject.json", http.StatusOK)
197197
client := messagebirdtest.Client(t)
198198

199-
params := &MessageParams{
199+
params := &Params{
200200
Type: "premium",
201201
TypeDetails: TypeDetails{"keyword": "RESTAPI", "shortcode": 1008, "tariff": 150},
202202
}
@@ -231,7 +231,7 @@ func TestCreateWithFlashType(t *testing.T) {
231231
messagebirdtest.WillReturnTestdata(t, "flashMessageObject.json", http.StatusOK)
232232
client := messagebirdtest.Client(t)
233233

234-
params := &MessageParams{Type: "flash"}
234+
params := &Params{Type: "flash"}
235235

236236
message, err := Create(client, "TestName", []string{"31612345678"}, "Hello World", params)
237237
if err != nil {
@@ -249,7 +249,7 @@ func TestCreateWithScheduledDatetime(t *testing.T) {
249249

250250
scheduledDatetime, _ := time.Parse(time.RFC3339, "2015-01-05T10:03:59+00:00")
251251

252-
params := &MessageParams{ScheduledDatetime: scheduledDatetime}
252+
params := &Params{ScheduledDatetime: scheduledDatetime}
253253

254254
message, err := Create(client, "TestName", []string{"31612345678"}, "Hello World", params)
255255
if err != nil {
@@ -310,7 +310,7 @@ func TestList(t *testing.T) {
310310

311311
func TestRequestDataForMessage(t *testing.T) {
312312
currentTime := time.Now()
313-
messageParams := &MessageParams{
313+
messageParams := &Params{
314314
Type: "binary",
315315
Reference: "MyReference",
316316
Validity: 1,

mmsmessage/mms_message.go renamed to mms/message.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mmsmessage
1+
package mms
22

33
import (
44
"errors"
@@ -10,8 +10,8 @@ import (
1010
messagebird "github.com/messagebird/go-rest-api"
1111
)
1212

13-
// MMSMessage represents a MMS Message.
14-
type MMSMessage struct {
13+
// Message represents a MMS Message.
14+
type Message struct {
1515
ID string
1616
HRef string
1717
Direction string
@@ -25,9 +25,9 @@ type MMSMessage struct {
2525
Recipients messagebird.Recipients
2626
}
2727

28-
// MMSMessageParams represents the parameters that can be supplied when creating
28+
// Params represents the parameters that can be supplied when creating
2929
// a request.
30-
type MMSMessageParams struct {
30+
type Params struct {
3131
Body string
3232
MediaUrls []string
3333
Subject string
@@ -39,8 +39,8 @@ type MMSMessageParams struct {
3939
const path = "mms"
4040

4141
// Read retrieves the information of an existing MmsMessage.
42-
func Read(c *messagebird.Client, id string) (*MMSMessage, error) {
43-
mmsMessage := &MMSMessage{}
42+
func Read(c *messagebird.Client, id string) (*Message, error) {
43+
mmsMessage := &Message{}
4444
if err := c.Request(mmsMessage, http.MethodGet, path+"/"+id, nil); err != nil {
4545
return nil, err
4646
}
@@ -49,26 +49,26 @@ func Read(c *messagebird.Client, id string) (*MMSMessage, error) {
4949
}
5050

5151
// Create creates a new MMS message for one or more recipients.
52-
func Create(c *messagebird.Client, originator string, recipients []string, msgParams *MMSMessageParams) (*MMSMessage, error) {
53-
params, err := paramsForMMSMessage(msgParams)
52+
func Create(c *messagebird.Client, originator string, recipients []string, msgParams *Params) (*Message, error) {
53+
params, err := paramsForMessage(msgParams)
5454
if err != nil {
5555
return nil, err
5656
}
5757

5858
params.Set("originator", originator)
5959
params.Set("recipients", strings.Join(recipients, ","))
6060

61-
mmsMessage := &MMSMessage{}
61+
mmsMessage := &Message{}
6262
if err := c.Request(mmsMessage, http.MethodPost, path, params); err != nil {
6363
return nil, err
6464
}
6565

6666
return mmsMessage, nil
6767
}
6868

69-
// paramsForMMSMessage converts the specified MMSMessageParams struct to a
70-
// url.Values pointer and returns it.
71-
func paramsForMMSMessage(params *MMSMessageParams) (*url.Values, error) {
69+
// paramsForMessage converts the specified Parmas struct to a url.Values
70+
// pointer and returns it.
71+
func paramsForMessage(params *Params) (*url.Values, error) {
7272
urlParams := &url.Values{}
7373

7474
if params.Body == "" && params.MediaUrls == nil {

0 commit comments

Comments
 (0)