Skip to content

Commit

Permalink
Merge pull request #235 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 0b4068c + 870af1d commit 6a45f01
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ Thumbs.db

# rider
.idea

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

## [v5.21.0](https://github.com/plivo/plivo-dotnet/tree/v5.21.0) (2023-01-25)
- Added new param `RequesterIp` 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)

## [v5.20.0](https://github.com/plivo/plivo-dotnet/tree/v5.20.0) (2023-01-18)
- Added new param - 'message_expiry' in plivo-dotnet

Expand Down
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:latest

WORKDIR /usr/src/app

RUN apt-get update && apt-get install -y wget git vim
RUN apt-get install -y apt-transport-https

# Install dotnet sdk and runtime: https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install
RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
RUN chmod +x ./dotnet-install.sh
RUN ./dotnet-install.sh --version latest
RUN rm ./dotnet-install.sh

ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT 1
ENV DOTNET_ROOT /root/.dotnet
ENV PATH $PATH:/root/.dotnet:/root/.dotnet/tools
RUN dotnet --info

# 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" ]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: build

build:
docker-compose up --build --remove-orphans
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,21 @@ Refer to the [Plivo API Reference](https://api-reference.plivo.com/latest/net/in

## Reporting issues
Report any feedback or problems with this version by [opening an issue on Github](https://github.com/plivo/plivo-dotnet/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. It will also package the sdk and reinstall it as a dependecy for the test program.
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>/dotnet-sdk-test/Program.cs` in host
(or `/usr/src/app/dotnet-sdk-test/Program.cs` 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. However, when any change is made, the dependencies for the test program need to be re-installed. To do that:
* Either restart the docker container
* Or Run the `setup_sdk.sh` script
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:

dotnetSDK:
build:
context: .
image: dotnetsdk
container_name: dotnetSDK
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
49 changes: 49 additions & 0 deletions setup_sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

set -e
testDir="dotnet-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/src/Plivo/Client -type f -exec sed -i "s/$PLIVO_API_PROD_HOST/$PLIVO_API_DEV_HOST/g" {} \;

if [ ! -d $testDir ]; then
echo "Creating test dir..."
mkdir -p $testDir
# Fix for library issue: See Dotnet section of https://plivo-team.atlassian.net/wiki/spaces/SMSTEAM/pages/3581313044/Local+Setup+for+SDKs
sed -i '/Nerdbank.GitVersioning/ {
n;
/Version/ {
s/<Version>[^<]*<\/Version>/<Version>3.4.244<\/Version>/g;
}
}' Directory.Build.props
sed -i '/Plivo.NetCore.Test/,+1d' Plivo.sln
fi

if [ ! -f $testDir/*.csproj ]; then
echo "Initialising test project"
cd $testDir
dotnet new console
dotnet add package Plivo
sed -i 's+<PackageReference Include="Plivo".*>+<ProjectReference Include="/usr/src/app/src/Plivo/Plivo.csproj"/>+' $testDir.csproj
echo "using Plivo;" > Program.cs
dotnet restore
fi

echo -e "\n\nSDK setup complete!"
echo "To test your changes:"
echo -e "\t1. Add your test code to <path_to_cloned_sdk>/$testDir/Program.cs on host (or /usr/src/app/$testDir/Program.cs in the container)"
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 dotnet run Program.cs$NC"

# To keep the container running post setup
/bin/bash
2 changes: 1 addition & 1 deletion src/Plivo/Plivo.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.3</TargetFrameworks>
<ReleaseVersion>5.20.0</ReleaseVersion>
<ReleaseVersion>5.21.0</ReleaseVersion>
<Version />
<Authors>Plivo SDKs Team</Authors>
<Owners>Plivo Inc.</Owners>
Expand Down
3 changes: 2 additions & 1 deletion src/Plivo/Plivo.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
<summary>A .NET SDK to make voice calls and send SMS using Plivo and to generate Plivo XML</summary>
<description>A .NET SDK to make voice calls and send SMS using Plivo and to generate Plivo XML</description>
<id>Plivo</id>
<version>5.20.0</version>
<version>5.21.0</version>
<title>Plivo</title>
<authors>Plivo SDKs Team</authors>
<owners>Plivo, Inc.</owners>
<licenseUrl>https://github.com/plivo/plivo-dotnet/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>http://github.com/plivo/plivo-dotnet</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>
* 5.21.0 Added New Param 'RequesterIp' to List Message and Get Message APIs
* 5.19.0 Added Update campaign endpoints
* 5.18.0 Added Delete campaign and brand endpoints
* 5.17.0 Added BrandUsecase Api, 10dlc enhancements
Expand Down
9 changes: 8 additions & 1 deletion src/Plivo/Resource/Message/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public class Message : Resource
/// <value>The powerpack id.</value>
public string PowerpackId { get; set; }

/// <summary>
/// Gets or sets the requester ip.
/// </summary>
/// <value>The requester ip.</value>
public string RequesterIp { get; set; }

public override string ToString()
{
return "\n" +
Expand All @@ -103,7 +109,8 @@ public override string ToString()
"TotalAmount: " + TotalAmount + "\n" +
"TotalRate: " + TotalRate + "\n" +
"PowerpackID: " + PowerpackId + "\n" +
"Units: " + Units + "\n";
"Units: " + Units + "\n" +
"RequesterIP: " + RequesterIp + "\n";
}
#region ListMedia
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Plivo/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Version
/// <summary>
/// DotNet SDK version
/// </summary>
public const string SdkVersion = "5.20.0";
public const string SdkVersion = "5.21.0";
/// <summary>
/// Plivo API version
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "5.20.0",
"version": "5.21.0",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/v\\d+(?:\\.\\d+)?$"
Expand Down

0 comments on commit 6a45f01

Please sign in to comment.