Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ContinuousIntegration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ jobs:
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10
- name: Set up PowerShell
shell: bash
run: |
wget --output-document=var/PowerShell.deb --quiet "https://github.com/PowerShell/PowerShell/releases/download/v7.5.4/powershell_7.5.4-1.deb_amd64.deb"
sudo apt-get --assume-yes --quiet install ./var/PowerShell.deb
- name: Install dependencies
run: ./Invoke.ps1 Install
- name: Run tests
run: ./Invoke.ps1 Test
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
/.idea/
/.vs/
/bin/
/*/obj/
/src/*/obj/
/test/obj/
/var/
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Script",
"request": "launch",
"type": "PowerShell",
"script": "${workspaceFolder}/Debug.ps1"
}
]
}
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Version [3.3.0](https://github.com/cedx/free-mobile.net/compare/v3.2.0...v3.3.0)
- Merged the [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [PowerShell](https://learn.microsoft.com/en-us/powershell) projects into one solution.

## Version [3.2.0](https://github.com/cedx/free-mobile.net/compare/v3.1.0...v3.2.0)
- Restored support for [.NET](https://dotnet.microsoft.com/en-us) 9.

Expand Down
7 changes: 7 additions & 0 deletions Debug.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env pwsh
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true
Set-StrictMode -Version Latest

Import-Module "$PSScriptRoot/FreeMobile.psd1"
# Insert the command to be debugged here.
19 changes: 18 additions & 1 deletion FreeMobile.psd1
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
@{
ModuleVersion = "3.2.0"
DefaultCommandPrefix = "FreeMobile"
ModuleVersion = "3.3.0"
PowerShellVersion = "7.5"
RootModule = "bin/Belin.FreeMobile.Cmdlets.dll"

Author = "Cédric Belin <[email protected]>"
CompanyName = "Cedric-Belin.fr"
Copyright = "© Cédric Belin"
Description = "Send SMS messages to your Free Mobile device."
GUID = "8a16d600-a064-4037-9147-d13059c6abf7"

AliasesToExport = @()
FunctionsToExport = @()
VariablesToExport = @()

CmdletsToExport = @(
"New-Client"
"Send-Message"
)

RequiredAssemblies = @(
"bin/Belin.FreeMobile.dll"
)

PrivateData = @{
PSData = @{
LicenseUri = "https://github.com/cedx/free-mobile.net/blob/main/License.md"
ProjectUri = "https://github.com/cedx/free-mobile.net"
ReleaseNotes = "https://github.com/cedx/free-mobile.net/releases"
Tags = "api", "client", "free", "mobile", "sms"
}
}
}
8 changes: 7 additions & 1 deletion FreeMobile.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
<Folder Name="/Examples/">
<File Path="example/SendMessage.cs" />
</Folder>
<Folder Name="/Examples/Cmdlets/">
<File Path="example/Cmdlets/Send-Message.ps1" />
</Folder>
<Folder Name="/Shared/">
<File Path="share/SendMessage.http" />
</Folder>
<Folder Name="/Scripts/">
<File Path="Debug.ps1" />
<File Path="Invoke.ps1" />
</Folder>
<Folder Name="/Scripts/Tools/">
Expand All @@ -33,11 +37,13 @@
<File Path="tool/Test.ps1" />
<File Path="tool/Update.ps1" />
<File Path="tool/Version.ps1" />
<File Path="tool/Watch.ps1" />
</Folder>
<Folder Name="/Workflows/">
<File Path=".github/workflows/ContinuousIntegration.yaml" />
</Folder>
<Project Path="src/FreeMobile.csproj" />
<Project Path="src/FreeMobile/FreeMobile.csproj" />
<Project Path="src/FreeMobile.Cmdlets/FreeMobile.Cmdlets.csproj" />
<Project Path="test/FreeMobile.Tests.csproj">
<Build Solution="Release|*" Project="false" />
</Project>
Expand Down
1 change: 1 addition & 0 deletions PSModules.psd1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@{
Pester = @{}
PSScriptAnalyzer = @{}
}
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Free Mobile for .NET
Send SMS messages to your [Free Mobile](https://mobile.free.fr) device,
in [C#](https://learn.microsoft.com/en-us/dotnet/csharp).
in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [PowerShell](https://learn.microsoft.com/en-us/powershell).

## Documentation
- [User guide](https://github.com/cedx/free-mobile.net/wiki)
Expand Down
9 changes: 9 additions & 0 deletions example/Cmdlets/Send-Message.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<#
.SYNOPSIS
Sends an SMS notification.
#>
Import-Module FreeMobile

$credential = [pscredential]::new("Your account identifier", (ConvertTo-SecureString "Your API key" -AsPlainText))
Send-FreeMobileMessage "Hello World from PowerShell!" -Credential $credential
Write-Output "The message was sent successfully."
39 changes: 39 additions & 0 deletions src/FreeMobile.Cmdlets/FreeMobile.Cmdlets.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Company>Cedric-Belin.fr</Company>
<Copyright>© Cédric Belin</Copyright>
<Description>Send SMS messages to your Free Mobile device.</Description>
<Product>Free Mobile for PowerShell</Product>
<Version>2.0.0</Version>
</PropertyGroup>

<PropertyGroup>
<Authors>CedX</Authors>
<IncludeSymbols>true</IncludeSymbols>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>ReadMe.md</PackageReadmeFile>
<PackageTags>api;client;free;mobile;sms</PackageTags>
<RepositoryUrl>https://github.com/cedx/free-mobile.net.git</RepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AssemblyName>Belin.FreeMobile.Cmdlets</AssemblyName>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutDir>../../bin</OutDir>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<None Include="../../ReadMe.md" Pack="true" PackagePath="/" />
<PackageReference Include="System.Management.Automation" Version="7.*" PrivateAssets="all" />
<ProjectReference Include="../FreeMobile/FreeMobile.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="System.Management.Automation" />
</ItemGroup>
</Project>
29 changes: 29 additions & 0 deletions src/FreeMobile.Cmdlets/New-Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Belin.FreeMobile.Cmdlets;

using System.Net;

/// <summary>
/// Creates a new Free Mobile client.
/// </summary>
[Cmdlet(VerbsCommon.New, "Client")]
[OutputType(typeof(Client))]
public class NewClient: PSCmdlet {

/// <summary>
/// The Free Mobile user name and password.
/// </summary>
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true), Credential]
public required PSCredential Credential { get; set; }

/// <summary>
/// The base URL of the remote API endpoint.
/// </summary>
[Parameter]
public Uri? Uri { get; set; }

/// <summary>
/// Performs execution of this command.
/// </summary>
protected override void ProcessRecord() =>
WriteObject(new Client((NetworkCredential) Credential, Uri));
}
48 changes: 48 additions & 0 deletions src/FreeMobile.Cmdlets/Send-Message.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace Belin.FreeMobile.Cmdlets;

using System.Net;

/// <summary>
/// Sends an SMS message to the specified Free Mobile account.
/// </summary>
[Cmdlet(VerbsCommunications.Send, "Message", DefaultParameterSetName = "Credential")]
[OutputType(typeof(void))]
public class SendMessage: PSCmdlet {

/// <summary>
/// The Free Mobile client to use.
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = "Client")]
public required Client Client { get; set; }

/// <summary>
/// The Free Mobile user name and password.
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = "Credential"), Credential]
public required PSCredential Credential { get; set; }

/// <summary>
/// The message text.
/// </summary>
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
public required string Message { get; set; }

/// <summary>
/// The base URL of the remote API endpoint.
/// </summary>
[Parameter(ParameterSetName = "Credential")]
public Uri? Uri { get; set; }

/// <summary>
/// Performs initialization of command execution.
/// </summary>
protected override void BeginProcessing() {
if (ParameterSetName == "Credential") Client = new Client((NetworkCredential) Credential, Uri);
}

/// <summary>
/// Performs execution of this command.
/// </summary>
protected override void ProcessRecord() =>
Client.SendMessage(Message).GetAwaiter().GetResult();
}
File renamed without changes.
4 changes: 2 additions & 2 deletions src/FreeMobile.csproj → src/FreeMobile/FreeMobile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<AssemblyName>Belin.FreeMobile</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutDir>../bin</OutDir>
<OutDir>../../bin</OutDir>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<None Include="../ReadMe.md" Pack="true" PackagePath="/" />
<None Include="../../ReadMe.md" Pack="true" PackagePath="/" />
</ItemGroup>
</Project>
24 changes: 24 additions & 0 deletions test/Cmdlets/Send-Message.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<#
.SYNOPSIS
Tests the features of the `Send-Message` cmdlet.
#>
Describe "Send-Message" {
BeforeAll {
Import-Module ./FreeMobile.psd1
}

It "should throw an exception if a network error occurred" {
$credential = [pscredential]::new("anonymous", (ConvertTo-SecureString "secret" -AsPlainText))
{ "Hello World!" | Send-FreeMobileMessage -Credential $credential -Uri "http://localhost:666" } | Should -Throw
}

It "should throw an exception if the credentials are invalid" {
$credential = [pscredential]::new("anonymous", (ConvertTo-SecureString "secret" -AsPlainText))
{ "Hello World!" | Send-FreeMobileMessage -Credential $credential } | Should -Throw
}

It "should send SMS messages if the credentials are valid" {
$credential = [pscredential]::new($Env:FREEMOBILE_ACCOUNT, (ConvertTo-SecureString $Env:FREEMOBILE_API_KEY -AsPlainText))
{ "Hello Cédric, from PowerShell!" | Send-FreeMobileMessage -Credential $credential } | Should -Not -Throw
}
}
5 changes: 3 additions & 2 deletions test/FreeMobile.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Company>Cedric-Belin.fr</Company>
<Copyright>© Cédric Belin</Copyright>
<Product>Free Mobile for .NET</Product>
<Version>3.2.0</Version>
<Version>3.3.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -20,7 +20,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.*" />
<PackageReference Include="MSTest" Version="4.*" />
<ProjectReference Include="../src/FreeMobile.csproj" />
<ProjectReference Include="../src/FreeMobile/FreeMobile.csproj" />
<ProjectReference Include="../src/FreeMobile.Cmdlets/FreeMobile.Cmdlets.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion tool/Clean.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"Deleting all generated files..."
Remove-Item "bin" -ErrorAction Ignore -Force -Recurse
Remove-Item "*/obj" -Force -Recurse
Remove-Item "src/*/obj" -Force -Recurse
Remove-Item "test/obj" -ErrorAction Ignore -Force -Recurse
Remove-Item "var/*" -Exclude ".gitkeep" -Force -Recurse
1 change: 1 addition & 0 deletions tool/Lint.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"Performing the static analysis of source code..."
Import-Module PSScriptAnalyzer
Invoke-ScriptAnalyzer $PSScriptRoot -Recurse
Invoke-ScriptAnalyzer test -Recurse
Test-ModuleManifest FreeMobile.psd1 | Out-Null
32 changes: 27 additions & 5 deletions tool/Publish.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
& "$PSScriptRoot/Clean.ps1"
& "$PSScriptRoot/Version.ps1"
if ($Release) {
& "$PSScriptRoot/Clean.ps1"
& "$PSScriptRoot/Version.ps1"
}
else {
"The ""-Release"" switch must be set!"
exit 1
}

"Publishing the package..."
$version = (Import-PowerShellDataFile "FreeMobile.psd1").ModuleVersion
$module = Import-PowerShellDataFile "FreeMobile.psd1"
$version = $module.ModuleVersion
git tag "v$version"
git push origin "v$version"

dotnet pack --output var
foreach ($item in Get-Item "var/*.nupkg") {
$output = "var/NuGet"
dotnet pack --output $output
foreach ($item in Get-Item "$output/*.nupkg") {
dotnet nuget push $item --api-key $Env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json
}

$output = "var/PSModule"
New-Item $output/bin -ItemType Directory | Out-Null
Copy-Item "FreeMobile.psd1" $output
Copy-Item *.md $output
Copy-Item $module.RootModule $output/bin
if ("RequiredAssemblies" -in $module.Keys) { Copy-Item $module.RequiredAssemblies $output/bin }

$output = "var/PSGallery"
New-Item $output -ItemType Directory | Out-Null
Compress-PSResource var/PSModule $output
foreach ($item in Get-Item "$output/*.nupkg") {
Publish-PSResource -ApiKey $Env:PSGALLERY_API_KEY -NupkgPath $item
}
5 changes: 5 additions & 0 deletions tool/Test.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
"Running the test suite..."
dotnet test --results-directory var
pwsh -Command {
Import-Module Pester
Invoke-Pester test
exit $LASTEXITCODE
}
2 changes: 1 addition & 1 deletion tool/Version.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"Updating the version number in the sources..."
$version = (Import-PowerShellDataFile "FreeMobile.psd1").ModuleVersion
foreach ($item in Get-Item "*/*.csproj") {
foreach ($item in Get-ChildItem "*/*.csproj" -Recurse) {
(Get-Content $item) -replace "<Version>\d+(\.\d+){2}</Version>", "<Version>$version</Version>" | Out-File $item
}
3 changes: 3 additions & 0 deletions tool/Watch.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Watching for file changes..."
$configuration = $Release ? "Release" : "Debug"
Start-Process dotnet "watch build --configuration $configuration" -NoNewWindow -Wait -WorkingDirectory src