Skip to content

Commit eeb1b76

Browse files
Merge pull request #201 from plivo/SMS-5025
SMS-5025: Add Requester IP to Get and List Messages
2 parents 68255bf + c0fffaa commit eeb1b76

12 files changed

+159
-25
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ tmp/
1212
bin/
1313
# rspec failure tracking
1414
.rspec_status
15+
ruby-sdk-test/

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Change Log
2+
3+
## [4.36.0](https://github.com/plivo/plivo-ruby/tree/v4.36.0) (2022-01-25)
4+
**Adding new attribute - 'requester_ip' in Get Message and List Mssage APIs**
5+
- 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)
6+
27
## [4.35.0](https://github.com/plivo/plivo-ruby/tree/v4.35.0) (2022-01-18)
38
**Adding new attribute - 'message_expiry' in Send Message API**
49
- Added new attribute - message_expiry in Send Message API

Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM ruby:3.0.1-alpine
2+
3+
RUN apk update && apk add git vim bash make gcc musl-dev
4+
5+
WORKDIR /usr/src/app
6+
RUN gem install json --source 'https://rubygems.org/'
7+
8+
# Copy setup script
9+
COPY setup_sdk.sh /usr/src/app/
10+
RUN chmod a+x /usr/src/app/setup_sdk.sh
11+
12+
ENTRYPOINT [ "/usr/src/app/setup_sdk.sh" ]

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.PHONY: build test
2+
3+
build:
4+
docker-compose up --build --remove-orphans
5+
6+
test:
7+
docker exec -it $$CONTAINER /bin/bash -c "bundle exec rake"

README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
99
Add this line to your application's Gemfile:
1010

1111
```ruby
12-
gem 'plivo', '>= 4.35.0'
12+
gem 'plivo', '>= 4.36.0'
1313
```
1414

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

174174
## Reporting issues
175175
Report any feedback or problems with this version by [opening an issue on Github](https://github.com/plivo/plivo-ruby/issues).
176+
177+
## Local Development
178+
> Note: Requires latest versions of Docker & Docker-Compose. If you're on MacOS, ensure Docker Desktop is running.
179+
1. Export the following environment variables in your host machine:
180+
```bash
181+
export PLIVO_AUTH_ID=<your_auth_id>
182+
export PLIVO_AUTH_TOKEN=<your_auth_token>
183+
export PLIVO_API_DEV_HOST=<plivoapi_dev_endpoint>
184+
export PLIVO_API_PROD_HOST=<plivoapi_public_endpoint>
185+
```
186+
2. Run `make build`. This will create a docker container in which the sdk will be setup and dependencies will be installed.
187+
> 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.
188+
3. The above command will print the docker container id (and instructions to connect to it) to stdout.
189+
4. The testing code can be added to `<sdk_dir_path>/ruby-sdk-test/test.rb` in host
190+
(or `/usr/src/app/ruby-sdk-test/test.rb` in container)
191+
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.
192+
> To use the local code in the test file, import the sdk in test file using:
193+
`require "/usr/src/app/lib/plivo.rb"`
194+
6. To run unit tests, run `make test CONTAINER=<cont_id>` in host, where `<cont_id>` is the docker container id created in 2.
195+
(The docker container should be running)

docker-compose.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: '3'
2+
3+
services:
4+
5+
rubySDK:
6+
build:
7+
context: .
8+
image: rubysdk
9+
container_name: rubySDK
10+
environment:
11+
- PLIVO_AUTH_ID=${PLIVO_AUTH_ID}
12+
- PLIVO_AUTH_TOKEN=${PLIVO_AUTH_TOKEN}
13+
- PLIVO_API_DEV_HOST=${PLIVO_API_DEV_HOST}
14+
- PLIVO_API_PROD_HOST=${PLIVO_API_PROD_HOST}
15+
volumes:
16+
- .:/usr/src/app
17+
stdin_open: true
18+
tty: true

lib/plivo/resources/messages.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def to_s
3030
total_amount: @total_amount,
3131
total_rate: @total_rate,
3232
powerpack_id: @powerpack_id,
33-
units: @units
33+
units: @units,
34+
requester_ip: @requester_ip
3435
}.to_s
3536
end
3637
end

lib/plivo/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Plivo
2-
VERSION = "4.35.0".freeze
2+
VERSION = "4.36.0".freeze
33
end

setup_sdk.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
set -e
4+
testDir="ruby-sdk-test"
5+
GREEN="\033[0;32m"
6+
NC="\033[0m"
7+
8+
if [ ! $PLIVO_API_PROD_HOST ] || [ ! $PLIVO_API_DEV_HOST ] || [ ! $PLIVO_AUTH_ID ] || [ ! $PLIVO_AUTH_TOKEN ]; then
9+
echo "Environment variables not properly set! Please refer to Local Development section in README!"
10+
exit 126
11+
fi
12+
13+
cd /usr/src/app
14+
15+
echo "Setting plivo-api endpoint to dev..."
16+
find /usr/src/app/lib/ -type f -exec sed -i "s/$PLIVO_API_PROD_HOST/$PLIVO_API_DEV_HOST/g" {} \;
17+
18+
bundle install
19+
20+
if [ ! -d $testDir ]; then
21+
echo "Creating test dir..."
22+
mkdir -p $testDir
23+
fi
24+
25+
if [ ! -f $testDir/test.rb ]; then
26+
echo "Creating test file..."
27+
cd $testDir
28+
echo -e "require \"rubygems\"" > test.rb
29+
echo -e "require \"/usr/src/app/lib/plivo.rb\"" >> test.rb
30+
echo -e "include Plivo\n" >> test.rb
31+
echo -e "api = RestClient.new(ENV[\"PLIVO_AUTH_ID\"], ENV[\"PLIVO_AUTH_TOKEN\"])" >> test.rb
32+
cd -
33+
fi
34+
35+
echo -e "\n\nSDK setup complete!"
36+
echo "To test your changes:"
37+
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)"
38+
echo -e "\t\tNote: To use sdk in test file, import using $GREEN require \"/usr/src/app/lib/plivo.rb\"$NC"
39+
echo -e "\t2. Run a terminal in the container using: $GREEN docker exec -it $HOSTNAME /bin/bash$NC"
40+
echo -e "\t3. Navigate to the test directory: $GREEN cd /usr/src/app/$testDir$NC"
41+
echo -e "\t4. Run your test file: $GREEN ruby test.rb$NC"
42+
echo -e "\t5. For running unit tests, run on host: $GREEN make test CONTAINER=$HOSTNAME$NC"
43+
44+
# To keep the container running post setup
45+
/bin/bash

spec/mocks/messageGetResponse.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"to_number": "911231231231",
1212
"total_amount": "0.00250",
1313
"total_rate": "0.00250",
14-
"units": 1
14+
"units": 1,
15+
"requester_ip": "192.168.1.1"
1516
}

spec/mocks/messageListResponse.json

+40-20
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"to_number": "911231231231",
2020
"total_amount": "0.00250",
2121
"total_rate": "0.00250",
22-
"units": 1
22+
"units": 1,
23+
"requester_ip": "192.168.1.1"
2324
},
2425
{
2526
"error_code": null,
@@ -33,7 +34,8 @@
3334
"to_number": "911231231231",
3435
"total_amount": "0.00250",
3536
"total_rate": "0.00250",
36-
"units": 1
37+
"units": 1,
38+
"requester_ip": "192.168.1.2"
3739
},
3840
{
3941
"error_code": null,
@@ -47,7 +49,8 @@
4749
"to_number": "911231231231",
4850
"total_amount": "0.00250",
4951
"total_rate": "0.00250",
50-
"units": 1
52+
"units": 1,
53+
"requester_ip": "192.168.1.3"
5154
},
5255
{
5356
"error_code": null,
@@ -61,7 +64,8 @@
6164
"to_number": "911231231231",
6265
"total_amount": "0.00250",
6366
"total_rate": "0.00250",
64-
"units": 1
67+
"units": 1,
68+
"requester_ip": "192.168.1.4"
6569
},
6670
{
6771
"error_code": null,
@@ -75,7 +79,8 @@
7579
"to_number": "911231231231",
7680
"total_amount": "0.00250",
7781
"total_rate": "0.00250",
78-
"units": 1
82+
"units": 1,
83+
"requester_ip": "192.168.1.5"
7984
},
8085
{
8186
"error_code": null,
@@ -89,7 +94,8 @@
8994
"to_number": "911231231231",
9095
"total_amount": "0.00250",
9196
"total_rate": "0.00250",
92-
"units": 1
97+
"units": 1,
98+
"requester_ip": "192.168.1.6"
9399
},
94100
{
95101
"error_code": null,
@@ -103,7 +109,8 @@
103109
"to_number": "911231231231",
104110
"total_amount": "0.00250",
105111
"total_rate": "0.00250",
106-
"units": 1
112+
"units": 1,
113+
"requester_ip": "192.168.1.7"
107114
},
108115
{
109116
"error_code": null,
@@ -117,7 +124,8 @@
117124
"to_number": "911231231231",
118125
"total_amount": "0.00250",
119126
"total_rate": "0.00250",
120-
"units": 1
127+
"units": 1,
128+
"requester_ip": "192.168.1.8"
121129
},
122130
{
123131
"error_code": "000",
@@ -131,7 +139,8 @@
131139
"to_number": "919876543210",
132140
"total_amount": "0.00250",
133141
"total_rate": "0.00250",
134-
"units": 1
142+
"units": 1,
143+
"requester_ip": "192.168.1.9"
135144
},
136145
{
137146
"error_code": null,
@@ -145,7 +154,8 @@
145154
"to_number": "911231231231",
146155
"total_amount": "0.00250",
147156
"total_rate": "0.00250",
148-
"units": 1
157+
"units": 1,
158+
"requester_ip": "192.168.1.10"
149159
},
150160
{
151161
"error_code": "000",
@@ -159,7 +169,8 @@
159169
"to_number": "919876543210",
160170
"total_amount": "0.00250",
161171
"total_rate": "0.00250",
162-
"units": 1
172+
"units": 1,
173+
"requester_ip": "192.168.1.11"
163174
},
164175
{
165176
"error_code": null,
@@ -173,7 +184,8 @@
173184
"to_number": "911231231231",
174185
"total_amount": "0.00250",
175186
"total_rate": "0.00250",
176-
"units": 1
187+
"units": 1,
188+
"requester_ip": "192.168.1.12"
177189
},
178190
{
179191
"error_code": "000",
@@ -187,7 +199,8 @@
187199
"to_number": "919876543210",
188200
"total_amount": "0.00250",
189201
"total_rate": "0.00250",
190-
"units": 1
202+
"units": 1,
203+
"requester_ip": "192.168.1.13"
191204
},
192205
{
193206
"error_code": null,
@@ -201,7 +214,8 @@
201214
"to_number": "911231231231",
202215
"total_amount": "0.00250",
203216
"total_rate": "0.00250",
204-
"units": 1
217+
"units": 1,
218+
"requester_ip": "192.168.1.14"
205219
},
206220
{
207221
"error_code": "000",
@@ -215,7 +229,8 @@
215229
"to_number": "919876543210",
216230
"total_amount": "0.00250",
217231
"total_rate": "0.00250",
218-
"units": 1
232+
"units": 1,
233+
"requester_ip": "192.168.1.15"
219234
},
220235
{
221236
"error_code": null,
@@ -229,7 +244,8 @@
229244
"to_number": "911231231231",
230245
"total_amount": "0.00250",
231246
"total_rate": "0.00250",
232-
"units": 1
247+
"units": 1,
248+
"requester_ip": "192.168.1.16"
233249
},
234250
{
235251
"error_code": "000",
@@ -243,7 +259,8 @@
243259
"to_number": "919876543210",
244260
"total_amount": "0.00250",
245261
"total_rate": "0.00250",
246-
"units": 1
262+
"units": 1,
263+
"requester_ip": "192.168.1.17"
247264
},
248265
{
249266
"error_code": "000",
@@ -257,7 +274,8 @@
257274
"to_number": "919876543210",
258275
"total_amount": "0.00250",
259276
"total_rate": "0.00250",
260-
"units": 1
277+
"units": 1,
278+
"requester_ip": "192.168.1.18"
261279
},
262280
{
263281
"error_code": "000",
@@ -271,7 +289,8 @@
271289
"to_number": "919876543210",
272290
"total_amount": "0.00250",
273291
"total_rate": "0.00250",
274-
"units": 1
292+
"units": 1,
293+
"requester_ip": "192.168.1.19"
275294
},
276295
{
277296
"error_code": "000",
@@ -285,7 +304,8 @@
285304
"to_number": "919876543210",
286305
"total_amount": "0.00250",
287306
"total_rate": "0.00250",
288-
"units": 1
307+
"units": 1,
308+
"requester_ip": "192.168.1.20"
289309
}
290310
]
291311
}

spec/resource_messages_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def to_json(message)
1515
to_number: message.to_number,
1616
total_amount: message.total_amount,
1717
total_rate: message.total_rate,
18-
units: message.units
18+
units: message.units,
19+
requester_ip: message.requester_ip
1920
}.to_json
2021
end
2122

@@ -73,6 +74,7 @@ def to_json_list(list_object)
7374
method: 'GET',
7475
data: nil)
7576
expect(response.id).to eql(response.message_uuid)
77+
expect(response.requester_ip).to eql("192.168.1.1")
7678
end
7779

7880
it 'lists all mms media' do
@@ -115,6 +117,8 @@ def to_json_list(list_object)
115117
message_direction: 'inbound',
116118
message_state: 'delivered'
117119
})
120+
expect(JSON.parse(response)['objects'][0]['requester_ip']). to eql("192.168.1.1")
121+
expect(JSON.parse(response)['objects'][19]['requester_ip']). to eql("192.168.1.20")
118122
end
119123

120124
it 'sends a message' do

0 commit comments

Comments
 (0)