Skip to content

Commit

Permalink
Merge pull request #56 from hyrmn/master
Browse files Browse the repository at this point in the history
Added ability to fetch a single template
  • Loading branch information
shawnmclean committed Mar 7, 2014
2 parents 2ced85f + d55e465 commit 3eb1250
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Asychronous:
1. Render
2. Add
3. Update
4. Info
5. Senders
1. List

Expand All @@ -76,6 +77,9 @@ For running tests, ensure to rename `AppSettings.example.config` to `AppSettings
set your own Api Key in the test project. Tests can be executed from rake: `rake test` or from any nunit test runner
tool.

You will also need to create a test template in your Mandrill account. The template's html content must be set to '<span mc:edit="model1"></span>'.
The template's name must match the TemplateExample setting in the AppSettings.config; 'Test' by default.

#### Contributors

1. [Eli Schleifer](https://github.com/EliSchleifer)
Expand Down
38 changes: 38 additions & 0 deletions src/Mandrill/Templates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,44 @@ public Task<List<TemplateInfo>> ListTemplatesAsync()
TaskContinuationOptions.ExecuteSynchronously);
}

/// <summary>
/// Fetch a specific template.
/// </summary>
/// <param name="name">
/// The unique name of the template.
/// </param>
/// <returns>
/// A <see cref="TemplateInfo"/> object.
/// </returns>
public TemplateInfo TemplateInfo(string name)
{
return TemplateInfoAsync(name).Result;
}

/// <summary>
/// Fetch a specific template.
/// </summary>
/// <param name="name">
/// The unique name of the template.
/// </param>
/// <returns>
/// The <see cref="Task" />.
/// </returns>
public Task<TemplateInfo> TemplateInfoAsync(string name)
{
const string path = "/templates/info.json";

dynamic payload = new ExpandoObject();

payload.name = name;

Task<IRestResponse> post = this.PostAsync(path, payload);

return post.ContinueWith(
p => JSON.Parse<TemplateInfo>(p.Result.Content),
TaskContinuationOptions.ExecuteSynchronously);
}

/// <summary>
/// The render.
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions tests/IntegrationTests/TemplatesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ public void Render_Template_Returns_Correct_Content()
Assert.AreEqual(expected, result.html);
}

[Test]
public void Can_Return_Individial_Template()
{
// Setup
var apiKey = ConfigurationManager.AppSettings["APIKey"];
var templateName = ConfigurationManager.AppSettings["TemplateExample"];

// Exercise
var api = new MandrillApi(apiKey);
var result = api.TemplateInfo(templateName);

var expected = "<span mc:edit=\"model1\"></span>";

// Verify
Assert.AreEqual(expected, result.code);
}

[Test]
public void List_Templates_Returns_Correct_Count()
{
Expand Down

0 comments on commit 3eb1250

Please sign in to comment.