-
-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from reactiveui/master
Update
- Loading branch information
Showing
8 changed files
with
230 additions
and
1 deletion.
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
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.28711.60 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Meow", "Meow\Meow.csproj", "{F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F89AADAA-1C9E-4125-B6CF-9AD1E6CD94F1}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {DCB37AC1-9A6D-4947-AA9D-61B0A757E0D6} | ||
EndGlobalSection | ||
EndGlobal |
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Refit" Version="4.6.99" /> | ||
<PackageReference Include="Serilog" Version="2.8.0" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,50 @@ | ||
using Serilog; | ||
using System.Diagnostics; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace HttpClientDiagnostics | ||
{ | ||
[DebuggerStepThrough] | ||
public class HttpClientDiagnosticsHandler : DelegatingHandler | ||
{ | ||
public HttpClientDiagnosticsHandler(HttpMessageHandler innerHandler) : base(innerHandler) | ||
{ | ||
} | ||
|
||
public HttpClientDiagnosticsHandler() | ||
{ | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
var totalElapsedTime = Stopwatch.StartNew(); | ||
|
||
Log.Debug(string.Format("Request: {0}", request)); | ||
if (request.Content != null) | ||
{ | ||
var content = await request.Content.ReadAsStringAsync().ConfigureAwait(false); | ||
Log.Debug(string.Format("Request Content: {0}", content)); | ||
} | ||
|
||
var responseElapsedTime = Stopwatch.StartNew(); | ||
var response = await base.SendAsync(request, cancellationToken); | ||
|
||
Log.Debug(string.Format("Response: {0}", response)); | ||
if (response.Content != null) | ||
{ | ||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); | ||
Log.Debug(string.Format("Response Content: {0}", content)); | ||
} | ||
|
||
responseElapsedTime.Stop(); | ||
Log.Debug(string.Format("Response elapsed time: {0} ms", responseElapsedTime.ElapsedMilliseconds)); | ||
|
||
totalElapsedTime.Stop(); | ||
Log.Debug(string.Format("Total elapsed time: {0} ms", totalElapsedTime.ElapsedMilliseconds)); | ||
|
||
return response; | ||
} | ||
} | ||
} |
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,28 @@ | ||
using Serilog; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Meow | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.MinimumLevel.Verbose() | ||
.CreateLogger(); | ||
|
||
Task.Run(() => AsyncMain()).Wait(); | ||
} | ||
|
||
static async Task AsyncMain() | ||
{ | ||
var service = new CatsService("https://api.thecatapi.com"); | ||
var results = await service.Search("bengal"); | ||
|
||
Log.Debug("{results}", results); | ||
|
||
} | ||
} | ||
} |
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,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Meow.Responses | ||
{ | ||
|
||
public class BreedsResponse | ||
{ | ||
public Class1[] Property1 { get; set; } | ||
} | ||
|
||
public class Class1 | ||
{ | ||
public Breed[] breeds { get; set; } | ||
public string id { get; set; } | ||
public string url { get; set; } | ||
} | ||
|
||
public class Breed | ||
{ | ||
public Weight weight { get; set; } | ||
public string id { get; set; } | ||
public string name { get; set; } | ||
public string cfa_url { get; set; } | ||
public string vetstreet_url { get; set; } | ||
public string vcahospitals_url { get; set; } | ||
public string temperament { get; set; } | ||
public string origin { get; set; } | ||
public string country_codes { get; set; } | ||
public string country_code { get; set; } | ||
public string description { get; set; } | ||
public string life_span { get; set; } | ||
public int indoor { get; set; } | ||
public int lap { get; set; } | ||
public int adaptability { get; set; } | ||
public int affection_level { get; set; } | ||
public int child_friendly { get; set; } | ||
public int cat_friendly { get; set; } | ||
public int dog_friendly { get; set; } | ||
public int energy_level { get; set; } | ||
public int grooming { get; set; } | ||
public int health_issues { get; set; } | ||
public int intelligence { get; set; } | ||
public int shedding_level { get; set; } | ||
public int social_needs { get; set; } | ||
public int stranger_friendly { get; set; } | ||
public int vocalisation { get; set; } | ||
public int bidability { get; set; } | ||
public int experimental { get; set; } | ||
public int hairless { get; set; } | ||
public int natural { get; set; } | ||
public int rare { get; set; } | ||
public int rex { get; set; } | ||
public int suppressed_tail { get; set; } | ||
public int short_legs { get; set; } | ||
public string wikipedia_url { get; set; } | ||
public int hypoallergenic { get; set; } | ||
} | ||
|
||
public class Weight | ||
{ | ||
public string imperial { get; set; } | ||
public string metric { get; set; } | ||
} | ||
|
||
} |
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,28 @@ | ||
using HttpClientDiagnostics; | ||
using Meow.Responses; | ||
using Refit; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Meow | ||
{ | ||
public class CatsService | ||
{ | ||
private readonly HttpClient _httpClient; | ||
private readonly ITheCatsAPI _theCatsApi; | ||
|
||
public CatsService(string baseUrl) | ||
{ | ||
_httpClient = new HttpClient(new HttpClientDiagnosticsHandler()); | ||
_theCatsApi = RestService.For<ITheCatsAPI>(baseUrl); | ||
} | ||
|
||
public async Task<BreedsResponse> Search(string breed) | ||
{ | ||
return await _theCatsApi.Search(breed).ConfigureAwait(false); | ||
} | ||
} | ||
} |
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,17 @@ | ||
using Meow.Responses; | ||
using Refit; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Meow | ||
{ | ||
[Headers("x-api-key: redacted")] | ||
|
||
public interface ITheCatsAPI | ||
{ | ||
[Get("/v1/images/search")] | ||
Task<BreedsResponse> Search([AliasAs("breed_id")] string breedIdentifier); | ||
} | ||
} |