Skip to content

Commit 4a728d0

Browse files
Merge branch 'master' into messaging-list-ext
2 parents 8af947e + eeb1b76 commit 4a728d0

11 files changed

+172
-22
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

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
**Feature - Enhance MDR filtering capabilities **
44
- Added new fields on MDR object response
55

6+
7+
## [4.36.0](https://github.com/plivo/plivo-ruby/tree/v4.36.0) (2022-01-25)
8+
**Adding new attribute - 'requester_ip' in Get Message and List Mssage APIs**
9+
- 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)
10+
11+
## [4.35.0](https://github.com/plivo/plivo-ruby/tree/v4.35.0) (2022-01-18)
12+
**Adding new attribute - 'message_expiry' in Send Message API**
13+
- Added new attribute - message_expiry in Send Message API
14+
15+
616
## [4.34.0](https://github.com/plivo/plivo-ruby/tree/v4.34.0) (2022-12-16)
717
**10DLC: Update Campaign API**
818
- Added Update Campaign 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

+20
Original file line numberDiff line numberDiff line change
@@ -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

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def to_s
3434
tendlc_campaign_id: @tendlc_campaign_id,
3535
destination_country_iso2: @destination_country_iso2,
3636
tendlc_registration_status: @tendlc_registration_status
37+
requester_ip: @requester_ip
3738
}.to_s
3839
end
3940
end
@@ -72,6 +73,7 @@ def get(message_uuid)
7273
# @option options [String] :method The method used to call the url. Defaults to POST.
7374
# @option options [String] :log If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
7475
# @option options [String] :trackable set to false
76+
# @option options[Int]: message_expiry, int value
7577
# @option options[List]: media_urls Minimum one media url should be present in Media urls list to send mms. Maximum allowd 10 media urls inside the list (e.g, media_urls : ['https//example.com/test.jpg', 'https://example.com/abcd.gif'])
7678
# @option options[List]: media_ids Minimum one media ids should be present in Media ids list to send mms. Maximum allowd 10 media ids inside the list (e.g, media_ids : ['1fs211ba-355b-11ea-bbc9-02121c1190q7'])
7779

@@ -125,6 +127,11 @@ def create(src = nil, dst = nil, text = nil, options = nil, powerpack_uuid = nil
125127
if value.key?(:log) &&
126128
valid_param?(:log, value[:log], [TrueClass, FalseClass], true)
127129
params[:log] = value[:log]
130+
end
131+
132+
if value.key?(:message_expiry) &&
133+
valid_param?(:message_expiry, value[:message_expiry], [Integer, Integer], true)
134+
params[:message_expiry] = value[:message_expiry]
128135
end
129136

130137
if value.key?(:trackable) &&
@@ -222,6 +229,11 @@ def create(src = nil, dst = nil, text = nil, options = nil, powerpack_uuid = nil
222229
params[:media_ids] = options[:media_ids]
223230
end
224231

232+
if options.key?(:message_expiry) &&
233+
valid_param?(:message_expiry, options[:message_expiry], [Integer, Integer], true)
234+
params[:message_expiry] = options[:message_expiry]
235+
end
236+
225237
if options.key?(:trackable) &&
226238
valid_param?(:trackable, options[:trackable], [TrueClass, FalseClass], true)
227239
params[:trackable] = options[:trackable]

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
}

0 commit comments

Comments
 (0)