Skip to content

Commit

Permalink
Merge pull request #201 from plivo/SMS-5025
Browse files Browse the repository at this point in the history
SMS-5025: Add Requester IP to Get and List Messages
  • Loading branch information
renoldthomas-plivo authored Jan 30, 2023
2 parents 68255bf + c0fffaa commit eeb1b76
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ tmp/
bin/
# rspec failure tracking
.rspec_status
ruby-sdk-test/
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Change Log

## [4.36.0](https://github.com/plivo/plivo-ruby/tree/v4.36.0) (2022-01-25)
**Adding new attribute - '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)

## [4.35.0](https://github.com/plivo/plivo-ruby/tree/v4.35.0) (2022-01-18)
**Adding new attribute - 'message_expiry' in Send Message API**
- Added new attribute - 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 ruby:3.0.1-alpine

RUN apk update && apk add git vim bash make gcc musl-dev

WORKDIR /usr/src/app
RUN gem install json --source 'https://rubygems.org/'

# 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 "bundle exec rake"
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
Add this line to your application's Gemfile:

```ruby
gem 'plivo', '>= 4.35.0'
gem 'plivo', '>= 4.36.0'
```

And then execute:
Expand Down Expand Up @@ -173,3 +173,23 @@ More examples are available [here](https://github.com/plivo/plivo-examples-ruby)

## Reporting issues
Report any feedback or problems with this version by [opening an issue on Github](https://github.com/plivo/plivo-ruby/issues).

## 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>/ruby-sdk-test/test.rb` in host
(or `/usr/src/app/ruby-sdk-test/test.rb` 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.
> To use the local code in the test file, import the sdk in test file using:
`require "/usr/src/app/lib/plivo.rb"`
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)
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:

rubySDK:
build:
context: .
image: rubysdk
container_name: rubySDK
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 lib/plivo/resources/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def to_s
total_amount: @total_amount,
total_rate: @total_rate,
powerpack_id: @powerpack_id,
units: @units
units: @units,
requester_ip: @requester_ip
}.to_s
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/plivo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Plivo
VERSION = "4.35.0".freeze
VERSION = "4.36.0".freeze
end
45 changes: 45 additions & 0 deletions setup_sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -e
testDir="ruby-sdk-test"
GREEN="\033[0;32m"
NC="\033[0m"

if [ ! $PLIVO_API_PROD_HOST ] || [ ! $PLIVO_API_DEV_HOST ] || [ ! $PLIVO_AUTH_ID ] || [ ! $PLIVO_AUTH_TOKEN ]; then
echo "Environment variables not properly set! Please refer to Local Development section in README!"
exit 126
fi

cd /usr/src/app

echo "Setting plivo-api endpoint to dev..."
find /usr/src/app/lib/ -type f -exec sed -i "s/$PLIVO_API_PROD_HOST/$PLIVO_API_DEV_HOST/g" {} \;

bundle install

if [ ! -d $testDir ]; then
echo "Creating test dir..."
mkdir -p $testDir
fi

if [ ! -f $testDir/test.rb ]; then
echo "Creating test file..."
cd $testDir
echo -e "require \"rubygems\"" > test.rb
echo -e "require \"/usr/src/app/lib/plivo.rb\"" >> test.rb
echo -e "include Plivo\n" >> test.rb
echo -e "api = RestClient.new(ENV[\"PLIVO_AUTH_ID\"], ENV[\"PLIVO_AUTH_TOKEN\"])" >> test.rb
cd -
fi

echo -e "\n\nSDK setup complete!"
echo "To test your changes:"
echo -e "\t1. Add your test code in <path_to_cloned_sdk>/$testDir/test.rb on host (or /usr/src/app/$testDir/test.rb in the container)"
echo -e "\t\tNote: To use sdk in test file, import using $GREEN require \"/usr/src/app/lib/plivo.rb\"$NC"
echo -e "\t2. Run a terminal in the container using: $GREEN docker exec -it $HOSTNAME /bin/bash$NC"
echo -e "\t3. Navigate to the test directory: $GREEN cd /usr/src/app/$testDir$NC"
echo -e "\t4. Run your test file: $GREEN ruby test.rb$NC"
echo -e "\t5. For running unit tests, run on host: $GREEN make test CONTAINER=$HOSTNAME$NC"

# To keep the container running post setup
/bin/bash
3 changes: 2 additions & 1 deletion spec/mocks/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 spec/mocks/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"
}
]
}
6 changes: 5 additions & 1 deletion spec/resource_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def to_json(message)
to_number: message.to_number,
total_amount: message.total_amount,
total_rate: message.total_rate,
units: message.units
units: message.units,
requester_ip: message.requester_ip
}.to_json
end

Expand Down Expand Up @@ -73,6 +74,7 @@ def to_json_list(list_object)
method: 'GET',
data: nil)
expect(response.id).to eql(response.message_uuid)
expect(response.requester_ip).to eql("192.168.1.1")
end

it 'lists all mms media' do
Expand Down Expand Up @@ -115,6 +117,8 @@ def to_json_list(list_object)
message_direction: 'inbound',
message_state: 'delivered'
})
expect(JSON.parse(response)['objects'][0]['requester_ip']). to eql("192.168.1.1")
expect(JSON.parse(response)['objects'][19]['requester_ip']). to eql("192.168.1.20")
end

it 'sends a message' do
Expand Down

0 comments on commit eeb1b76

Please sign in to comment.