Skip to content

Commit

Permalink
test mode logging support
Browse files Browse the repository at this point in the history
  • Loading branch information
4kimov committed Mar 5, 2024
1 parent 1b2aa7e commit f9308ed
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# CHANGELOG

**Unreleased:**
- `README.md`: markdown supports ordered/unordered lists
**v0.1.5:**
- `README.md`
- markdown supports ordered/unordered lists
- notice about test mode
- Support for test mode logging

**v0.1.4:**
- `README.md` cleanup (listing of components)
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ There are more C# examples in the [examples](examples) folder ✨
> [!NOTE]
> 🚧 **The SDK is not stable yet.** This API might change as more features are added. Please watch the repo for the changes in the [CHANGELOG](CHANGELOG.md).
## 🏗 Debugging

You can generate _test API keys_ by activating the **Test Mode** in your dashboard. By using these keys, you'll be able to view your fully rendered emails without actually sending them.

When you use a test API key in your SDK, the following output will appear in your logs when you try to send an email:

```log
Templateless [TEST MODE]: Emailed user@example.com, preview: https://tmpl.sh/ATMxHLX4r9aE
```

The preview link will display the email, but you must be logged in to Templateless to view it.

## 🔳 Components

Emails are crafted programmatically by making function calls. There's no dealing with HTML or drag-and-drop builders.
Expand Down Expand Up @@ -260,7 +272,7 @@ If you'd like your recipients to be able to read the email in a browser, you can

You can optionally provide the text for the link. If none is provided, default is used: "View in browser"

**This will make the email public to anyone that has access to the link.**
**Anyone who knows the link will be able to see the email.**

```cs
Content.Builder()
Expand Down
2 changes: 1 addition & 1 deletion src/Templateless/Templateless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>

<PackageId>Templateless</PackageId>
<Version>0.1.4</Version>
<Version>0.1.5</Version>
<Description>Ship faster by sending elegant emails using just code</Description>
<PackageTags>Templateless;email;templates</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/templateless/templateless-dotnet/main/icon.png</PackageIconUrl>
Expand Down
23 changes: 21 additions & 2 deletions src/Templateless/TemplatelessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,17 @@ public async Task<List<string>> SendEmailsAsync(List<Email> emails)
}

var responseContent = await response.Content.ReadAsStringAsync();
var sentEmailIds = JsonConvert.DeserializeObject<EmailResponse>(responseContent)?.Emails;
return sentEmailIds ?? new List<string>();
var res = JsonConvert.DeserializeObject<EmailResponse>(responseContent);

if (res.Previews != null)

Check warning on line 60 in src/Templateless/TemplatelessClient.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.

Check warning on line 60 in src/Templateless/TemplatelessClient.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
{
foreach (var preview in res.Previews)
{
Console.WriteLine($"Templateless [TEST MODE]: Emailed {preview.Email}, preview: https://tmpl.sh/{preview.Preview}");
}
}

return res?.Emails ?? new List<string>();
}

private ErrorType ParseErrorType(HttpStatusCode statusCode)
Expand All @@ -73,9 +82,19 @@ private ErrorType ParseErrorType(HttpStatusCode statusCode)
}
}

public class EmailResponsePreview
{
[JsonProperty("preview")]
public string Preview { get; set; }

Check warning on line 88 in src/Templateless/TemplatelessClient.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'Preview' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 88 in src/Templateless/TemplatelessClient.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'Preview' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[JsonProperty("email")]
public string Email { get; set; }

Check warning on line 90 in src/Templateless/TemplatelessClient.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'Email' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 90 in src/Templateless/TemplatelessClient.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'Email' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}

public class EmailResponse
{
[JsonProperty("emails")]
public List<string>? Emails { get; set; }
[JsonProperty("previews")]
public List<EmailResponsePreview>? Previews { get; set; }
}
}

0 comments on commit f9308ed

Please sign in to comment.