-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
becbcfd
commit 959c825
Showing
19 changed files
with
600 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="GotoBibleApiRenderer.cs" company="Conglomo"> | ||
// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace GoToBible.Engine | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Net.Http.Json; | ||
using System.Threading.Tasks; | ||
using GoToBible.Model; | ||
|
||
/// <summary> | ||
/// The GoTo.Bible API Renderer. | ||
/// </summary> | ||
/// <seealso cref="GoToBible.Model.IRenderer" /> | ||
public class GotoBibleApiRenderer : IRenderer | ||
{ | ||
/// <summary> | ||
/// The HTTP client. | ||
/// </summary> | ||
private readonly HttpClient httpClient; | ||
|
||
/// <summary> | ||
/// A value indicating whether or not this instance has been disposed. | ||
/// </summary> | ||
private bool disposedValue; | ||
|
||
/// <summary> | ||
/// Initialises a new instance of the <see cref="GotoBibleApiRenderer" /> class. | ||
/// </summary> | ||
public GotoBibleApiRenderer() | ||
{ | ||
this.Providers = new List<IProvider>(); | ||
this.httpClient = new HttpClient | ||
{ | ||
BaseAddress = new Uri("https://goto.bible/", UriKind.Absolute), | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Finalises an instance of the <see cref="GotoBibleApiRenderer"/> class. | ||
/// </summary> | ||
~GotoBibleApiRenderer() | ||
{ | ||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
this.Dispose(false); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IReadOnlyCollection<IProvider> Providers { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public void Dispose() | ||
{ | ||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
this.Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task<RenderedPassage> RenderAsync(RenderingParameters parameters, bool renderCompleteHtmlPage) | ||
{ | ||
string url = $"RenderPassage?renderCompleteHtmlPage={renderCompleteHtmlPage}"; | ||
HttpResponseMessage response = await this.httpClient.PostAsJsonAsync(url, parameters); | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
return await response.Content.ReadFromJsonAsync<RenderedPassage>() ?? new RenderedPassage(); | ||
} | ||
else | ||
{ | ||
return new RenderedPassage(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Releases unmanaged and - optionally - managed resources. | ||
/// </summary> | ||
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> | ||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!this.disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
// dispose managed state (managed objects) | ||
this.httpClient.Dispose(); | ||
} | ||
|
||
// free unmanaged resources (unmanaged objects) and override finalizer | ||
// set large fields to null | ||
this.disposedValue = true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="IRenderer.cs" company="Conglomo"> | ||
// Copyright 2020-2021 Conglomo Limited. Please see LICENSE for license details. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace GoToBible.Model | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// The renderer interface. | ||
/// </summary> | ||
public interface IRenderer : IDisposable | ||
{ | ||
/// <summary> | ||
/// Gets or sets the providers. | ||
/// </summary> | ||
/// <value> | ||
/// The providers. | ||
/// </value> | ||
/// <remarks> | ||
/// These can be all disposed by the renderer. | ||
/// </remarks> | ||
IReadOnlyCollection<IProvider> Providers { get; set; } | ||
|
||
/// <summary> | ||
/// Renders the specified parameters. | ||
/// </summary> | ||
/// <param name="parameters">The parameters.</param> | ||
/// <param name="renderCompleteHtmlPage">If set to <c>true</c>, render the complete HTML page.</param> | ||
/// <returns> | ||
/// The output of the rendering. | ||
/// </returns> | ||
Task<RenderedPassage> RenderAsync(RenderingParameters parameters, bool renderCompleteHtmlPage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.