Skip to content

Commit

Permalink
SMS-5025: Add Requester IP to Get and List Messages (#157)
Browse files Browse the repository at this point in the history
* SMS-5025: Add requester ip to List and Get MDR

* Dockerisation setup

* Address review comments

* Bump version
  • Loading branch information
mohsin-plivo authored Jan 31, 2023
1 parent 6dd1280 commit 6bed2dc
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 25 deletions.
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
Expand All @@ -11,6 +12,11 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
.DS_Store
# Dependency directories (remove the comment below to include it)
vendor/

# Go workspace file
go.work

# testing files
go-sdk-test/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [7.18.0](https://github.com/plivo/plivo-go/tree/v7.18.0) (2023-01-25)
**Feature - Added New Param 'requester_ip' in Get Message and List Mssage APIs**
- Add `requester_ip` to the response for the [list all messages API](https://www.plivo.com/docs/sms/api/message/list-all-messages/) and the [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message)

## [7.17.1](https://github.com/plivo/plivo-go/tree/v7.17.1) (2023-01-18)
**Feature - Adding new param 'message_expiry' in Send Message API**
- Added new param 'message_expiry' in Send Message API
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.17-alpine

WORKDIR /usr/src/app
RUN apk update && apk add git vim bash gcc musl-dev

ENV PATH $PATH:/usr/local/go/bin

# Copy setup script
COPY setup_sdk.sh /usr/src/app/
RUN chmod a+x /usr/src/app/setup_sdk.sh

ENTRYPOINT [ "/usr/src/app/setup_sdk.sh" ]
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: build test

build:
docker-compose up --build --remove-orphans

test:
docker exec -it $$CONTAINER /bin/bash -c "go test -v -race -cover"
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,21 @@ func testPhloRunWithParams() {

### More examples
Refer to the [Plivo API Reference](https://www.plivo.com/docs/sms/api/overview/) for more examples.

## Local Development
> Note: Requires latest versions of Docker & Docker-Compose. If you're on MacOS, ensure Docker Desktop is running.
1. Export the following environment variables in your host machine:
```bash
export PLIVO_AUTH_ID=<your_auth_id>
export PLIVO_AUTH_TOKEN=<your_auth_token>
export PLIVO_API_DEV_HOST=<plivoapi_dev_endpoint>
export PLIVO_API_PROD_HOST=<plivoapi_public_endpoint>
```
2. Run `make build`. This will create a docker container in which the sdk will be setup and dependencies will be installed.
> The entrypoint of the docker container will be the `setup_sdk.sh` script. The script will handle all the necessary changes required for local development.
3. The above command will print the docker container id (and instructions to connect to it) to stdout.
4. The testing code can be added to `<sdk_dir_path>/go-sdk-test/test.go` in host
(or `/usr/src/app/go-sdk-test/test.go` in container)
5. The sdk directory will be mounted as a volume in the container. So any changes in the sdk code will also be reflected inside the container.
6. To run unit tests, run `make test CONTAINER=<cont_id>` in host, where `<cont_id>` is the docker container id created in 2.
(The docker container should be running)
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 = "7.17.1"
const sdkVersion = "7.18.0"

const lookupBaseUrl = "lookup.plivo.com"

Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3'

services:

goSDK:
build:
context: .
image: gosdk
container_name: goSDK
environment:
- PLIVO_AUTH_ID=${PLIVO_AUTH_ID}
- PLIVO_AUTH_TOKEN=${PLIVO_AUTH_TOKEN}
- PLIVO_API_DEV_HOST=${PLIVO_API_DEV_HOST}
- PLIVO_API_PROD_HOST=${PLIVO_API_PROD_HOST}
volumes:
- .:/usr/src/app
stdin_open: true
tty: true
3 changes: 2 additions & 1 deletion fixtures/messageGetResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.1"
}
60 changes: 40 additions & 20 deletions fixtures/messageListResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.1"
},
{
"error_code": null,
Expand All @@ -33,7 +34,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.2"
},
{
"error_code": null,
Expand All @@ -47,7 +49,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.3"
},
{
"error_code": null,
Expand All @@ -61,7 +64,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.4"
},
{
"error_code": null,
Expand All @@ -75,7 +79,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.5"
},
{
"error_code": null,
Expand All @@ -89,7 +94,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.6"
},
{
"error_code": null,
Expand All @@ -103,7 +109,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.7"
},
{
"error_code": null,
Expand All @@ -117,7 +124,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.8"
},
{
"error_code": "000",
Expand All @@ -131,7 +139,8 @@
"to_number": "919876543210",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.9"
},
{
"error_code": null,
Expand All @@ -145,7 +154,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.10"
},
{
"error_code": "000",
Expand All @@ -159,7 +169,8 @@
"to_number": "919876543210",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.11"
},
{
"error_code": null,
Expand All @@ -173,7 +184,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.12"
},
{
"error_code": "000",
Expand All @@ -187,7 +199,8 @@
"to_number": "919876543210",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.13"
},
{
"error_code": null,
Expand All @@ -201,7 +214,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.14"
},
{
"error_code": "000",
Expand All @@ -215,7 +229,8 @@
"to_number": "919876543210",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.15"
},
{
"error_code": null,
Expand All @@ -229,7 +244,8 @@
"to_number": "911231231231",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.16"
},
{
"error_code": "000",
Expand All @@ -243,7 +259,8 @@
"to_number": "919876543210",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.17"
},
{
"error_code": "000",
Expand All @@ -257,7 +274,8 @@
"to_number": "919876543210",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.18"
},
{
"error_code": "000",
Expand All @@ -271,7 +289,8 @@
"to_number": "919876543210",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.19"
},
{
"error_code": "000",
Expand All @@ -285,7 +304,8 @@
"to_number": "919876543210",
"total_amount": "0.00250",
"total_rate": "0.00250",
"units": 1
"units": 1,
"requester_ip": "192.168.1.20"
}
]
}
1 change: 1 addition & 0 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Message struct {
MessageTime string `json:"message_time,omitempty" url:"message_time,omitempty"`
ErrorCode string `json:"error_code,omitempty" url:"error_code,omitempty"`
PowerpackID string `json:"powerpack_id,omitempty" url:"powerpack_id,omitempty"`
RequesterIP string `json:"requester_ip,omitempty" url:"requester_ip,omitempty"`
}

// Stores response for ending a message.
Expand Down
3 changes: 3 additions & 0 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func TestMessageService_List(t *testing.T) {
assert.NotNil(resp)
assert.Nil(err)
assert.NotEmpty(resp.Objects[0].MessageUUID)
assert.Equal(resp.Objects[0].RequesterIP, "192.168.1.1")
assert.Equal(resp.Objects[19].RequesterIP, "192.168.1.20")
assert.NotNil(resp.Objects)
assert.NotNil(resp.Meta)
cl := client.httpClient
Expand All @@ -32,6 +34,7 @@ func TestMessageService_Get(t *testing.T) {
assert.NotNil(resp)
assert.Nil(err)
assert.Equal(resp.MessageUUID, uuid)
assert.Equal(resp.RequesterIP, "192.168.1.1")
cl := client.httpClient
client.httpClient = nil
resp, err = client.Messages.Get(uuid)
Expand Down
Loading

0 comments on commit 6bed2dc

Please sign in to comment.