Skip to content

Commit

Permalink
Merge pull request #42 from plivo/mms-change
Browse files Browse the repository at this point in the history
mms related change
  • Loading branch information
nixonsam authored Dec 4, 2019
2 parents 6589231 + 4ac2ab8 commit 06679e2
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [4.1.3](https://github.com/plivo/plivo-go/tree/v4.1.3) (2019-12-04)
- Add MMS support

## [4.1.2](https://github.com/plivo/plivo-go/tree/v4.1.2) (2019-11-13)
- Add GetInput XML support

Expand Down
2 changes: 1 addition & 1 deletion baseclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/google/go-querystring/query"
)

const sdkVersion = "4.1.2"
const sdkVersion = "4.1.3"

type ClientOptions struct {
HttpClient *http.Client
Expand Down
8 changes: 8 additions & 0 deletions fixtures/mmsMediaGetResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"api_id": "292437c0-e5a3-11e9-b521-0242ac110003",
"content_type": "image/gif",
"media_id": "91f8f9ce-e236-474f-a2b8-f75d9c35988a",
"media_url": "http://127.0.0.1:80/media/MAODZKMDFJMJU3MTEYNG/f734eeec-e59f-11e9-89dc-0242ac110003/91f8f9ce-e236-474f-a2b8-f75d9c35988a",
"message_uuid": "f734eeec-e59f-11e9-89dc-0242ac110003",
"size": 766424
}
18 changes: 18 additions & 0 deletions fixtures/mmsMediaListResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"api_id": "95e98e4a-e5a4-11e9-b521-0242ac110003",
"objects": [{
"content_type": "image/gif",
"media_id": "91f8f9ce-e236-474f-a2b8-f75d9c35988a",
"media_url": "http://127.0.0.1:80/media/MAODZKMDFJMJU3MTEYNG/f734eeec-e59f-11e9-89dc-0242ac110003/91f8f9ce-e236-474f-a2b8-f75d9c35988a",
"message_uuid": "f734eeec-e59f-11e9-89dc-0242ac110003",
"size": 766424
},
{
"content_type": "image/jpeg",
"media_id": "455a2f85-acd5-4bb7-9a6a-a7b7341cd592",
"media_url": "http://127.0.0.1:80/media/MAODZKMDFJMJU3MTEYNG/f734eeec-e59f-11e9-89dc-0242ac110003/455a2f85-acd5-4bb7-9a6a-a7b7341cd592",
"message_uuid": "f734eeec-e59f-11e9-89dc-0242ac110003",
"size": 47343
}
]
}
50 changes: 50 additions & 0 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plivo

type MessageService struct {
client *Client
Message
}

type MessageCreateParams struct {
Expand All @@ -14,6 +15,7 @@ type MessageCreateParams struct {
Method string `json:"method,omitempty" url:"method,omitempty"`
Trackable bool `json:"trackable,omitempty" url:"trackable,omitempty"`
Log interface{} `json:"log,omitempty" url:"log,omitempty"`
MediaUrls []string `json:"media_urls" url:"media_urls,omitempty"`
// Either one of src and powerpackuuid should be given
PowerpackUUID string `json:"powerpack_uuid,omitempty" url:"powerpack_uuid,omitempty"`
}
Expand All @@ -40,15 +42,35 @@ type MessageCreateResponseBody struct {
Error string `json:"error" url:"error"`
}

type MediaDeleteResponse struct {
Error string `json:"error,omitempty"`
}
type MMSMedia struct {
ApiID string `json:"api_id,omitempty"`
ContentType string `json:"content_type,omitempty"`
MediaID string `json:"media_id,omitempty"`
MediaURL string `json:"media_url,omitempty"`
MessageUUID string `json:"message_uuid,omitempty"`
Size int64 `json:"size,omitempty"`
}

type MessageList struct {
BaseListResponse
Objects []Message `json:"objects" url:"objects"`
}

type MediaListResponseBody struct {
Objects []MMSMedia `json:"objects" url:"objects"`
}

type MessageListParams struct {
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
type GetMediaParams struct {
MediaID string `url:"media_id,omitempty"`
MessageUUID string `url:"message_uuid,omitempty"`
}

func (service *MessageService) List(params MessageListParams) (response *MessageList, err error) {
req, err := service.client.NewRequest("GET", params, "Message")
Expand Down Expand Up @@ -79,3 +101,31 @@ func (service *MessageService) Create(params MessageCreateParams) (response *Mes
err = service.client.ExecuteRequest(req, response)
return
}

func (service *MessageService) ListMedia(messageUuid string) (response *MediaListResponseBody, err error) {
req, err := service.client.NewRequest("GET", nil, "Message/%s/Media/", messageUuid)
if err != nil {
return
}
response = &MediaListResponseBody{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *MessageService) DeleteMedia(messageUuid string) (response *MediaDeleteResponse, err error) {
req, err := service.client.NewRequest("DELETE", nil, "Message/%s/Media/", messageUuid)
if err != nil {
return
}
response = &MediaDeleteResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *MessageService) GetMedia(params GetMediaParams) (response *MMSMedia, err error) {
req, err := service.client.NewRequest("GET", nil, "Message/%s/Media/%s/", params.MessageUUID, params.MediaID)
if err != nil {
return
}
response = &MMSMedia{}
err = service.client.ExecuteRequest(req, response)
return
}
41 changes: 41 additions & 0 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,47 @@ func TestMessageService_Get(t *testing.T) {
assertRequest(t, "GET", "Message/%s", uuid)
}

func TestMessageService_GetMedia(t *testing.T) {
expectResponse("mmsMediaGetResponse.json", 200)
uuid := "f734eeec-e59f-11e9-89dc-0242ac110003"
mediaID := "91f8f9ce-e236-474f-a2b8-f75d9c35988a"

if _, err := client.Messages.GetMedia(GetMediaParams{
MessageUUID: uuid,
MediaID: mediaID,
}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
if _, err := client.Messages.GetMedia(GetMediaParams{
MessageUUID: uuid,
MediaID: mediaID,
}); err == nil {
panic(errors.New("error expected"))
}
client.httpClient = cl

assertRequest(t, "GET", "Message/%s/Media/%s", uuid, mediaID)
}

func TestMessageService_ListMedia(t *testing.T) {
expectResponse("mmsMediaListResponse.json", 200)
uuid := "5b40a428-bfc7-4daf-9d06-726c558bf3b8"

if _, err := client.Messages.ListMedia(uuid); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
if _, err := client.Messages.ListMedia(uuid); err == nil {
panic(errors.New("error expected"))
}
client.httpClient = cl

assertRequest(t, "GET", "Message/%s/Media", uuid)
}

func TestMessageService_Create(t *testing.T) {
expectResponse("messageSendResponse.json", 202)

Expand Down

0 comments on commit 06679e2

Please sign in to comment.