Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
darrelmiller committed May 19, 2016
1 parent 883a006 commit 1699696
Show file tree
Hide file tree
Showing 21 changed files with 1,300 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[Rr]eleases/
[Xx]64/
[Xx]86/
[Bb]uild/
#[Bb]uild/
bld/
[Bb]in/
[Oo]bj/
Expand Down
5 changes: 5 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Tavis.HttpResponseMachine #

##0.9.0-beta
- Initial release outside of Hapikit

23 changes: 22 additions & 1 deletion Tavis.HttpResponseMachine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tavis.HttpResponseMachine", "Tavis.HttpResponseMachine\Tavis.HttpResponseMachine.csproj", "{2F00C1F7-D0EC-4139-8307-0FAB1F3869E0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpResponseMachine", "src\HttpResponseMachine\HttpResponseMachine.csproj", "{2F00C1F7-D0EC-4139-8307-0FAB1F3869E0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpResponseMachineTests", "src\HttpResponseMachineTests\HttpResponseMachineTests.csproj", "{848C5E4A-2BC6-4B46-BAA4-12AA399161EE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A423DD46-C368-4EA7-B573-FCF8BFB10E2B}"
ProjectSection(SolutionItems) = preProject
readme.md = readme.md
ReleaseNotes.md = ReleaseNotes.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{369D79D7-FCF6-492C-943F-DFE5EDCBC052}"
ProjectSection(SolutionItems) = preProject
build\Build.proj = build\Build.proj
build\Tavis.HttpResponseMachine.nuspec = build\Tavis.HttpResponseMachine.nuspec
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,8 +29,15 @@ Global
{2F00C1F7-D0EC-4139-8307-0FAB1F3869E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F00C1F7-D0EC-4139-8307-0FAB1F3869E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F00C1F7-D0EC-4139-8307-0FAB1F3869E0}.Release|Any CPU.Build.0 = Release|Any CPU
{848C5E4A-2BC6-4B46-BAA4-12AA399161EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{848C5E4A-2BC6-4B46-BAA4-12AA399161EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{848C5E4A-2BC6-4B46-BAA4-12AA399161EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{848C5E4A-2BC6-4B46-BAA4-12AA399161EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{369D79D7-FCF6-492C-943F-DFE5EDCBC052} = {A423DD46-C368-4EA7-B573-FCF8BFB10E2B}
EndGlobalSection
EndGlobal
11 changes: 0 additions & 11 deletions Tavis.HttpResponseMachine/Class1.cs

This file was deleted.

29 changes: 29 additions & 0 deletions build/Build.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="default">
<PropertyGroup>
<BaseDir>$(MSBuildProjectDirectory)\..</BaseDir>
<Configuration Condition="'$(Configuration)'==''" >Release</Configuration>
<ArtifactsDir>$(BaseDir)\artifacts</ArtifactsDir>
<BuildDir>$(BaseDir)\build</BuildDir>
<PackageDir>$(BuildDir)\Packages</PackageDir>

<Project>HttpResponseMachine</Project>
<ProjectFilePCL>$(BaseDir)\src\$(Project)\$(Project).csproj</ProjectFilePCL>
<OutputDir>$(BaseDir)\src\$(Project)\bin\$(Configuration)</OutputDir>
<SolutionDir>$(BaseDir)</SolutionDir> <!-- Needed or import of nuget targets in csproj file fails-->
</PropertyGroup>


<Target Name="default" DependsOnTargets="Compile; Package" />

<Target Name="Compile">
<MSBuild Projects="$(ProjectFilePCL)"
Properties="Configuration=$(Configuration);SolutionDir=$(SolutionDir);OutputPath=$(ArtifactsDir)\$(Project)\lib\portable-net45+netcore45+wpa81" />

</Target>

<Target Name="Package">

<Exec WorkingDirectory="$(BuildDir)"
Command="nuget.exe pack $(BuildDir)\Tavis.$(Project).nuspec -OutputDirectory $(ArtifactsDir) " />
</Target>
</Project>
20 changes: 20 additions & 0 deletions build/Tavis.HttpResponseMachine.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Tavis.HttpResponseMachine</id>
<version>0.9.0-beta</version>
<authors>Darrel Miller</authors>
<owners>Darrel Miller</owners>
<projectUrl>https://github.com/tavis-software/Tavis.HttpResponseMachine</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Declarative binding of HTTP Response handlers</description>
<releaseNotes>
<![CDATA[
For full release notes see https://github.com/tavis-software/Tavis.HttpResponseMachine/blob/master/ReleaseNotes.md
]]>
</releaseNotes>
</metadata>
<files>
<file src="..\artifacts\HttpResponseMachine\lib\**\Tavis.HttpResponseMachine.dll" target="lib" />
</files>
</package>
41 changes: 41 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Tavis.HttpResponseMachine

This library provides a declarative way of handling HTTP responses.


Responses can be dispatched based on status code, media type and link relation type.

machine.When(HttpStatusCode.OK, null, new MediaTypeHeaderValue("application/json"))
.Then(async (l, r) =>
{
var text = await r.Content.ReadAsStringAsync();
root = JToken.Parse(text);
});

Declarative parsers can be defined to map HttpContent to strongly typed objects

parserStore.AddMediaTypeParser<JToken>("application/json", async (content) =>
{
var stream = await content.ReadAsStreamAsync();
return JToken.Load(new JsonTextReader(new StreamReader(stream)));
});

// Define method to translate media type DOM into application domain object instance based on profile
parserStore.AddProfileParser<JToken, Person>(new Uri("http://example.org/person"), (jt) =>
{
var person = new Person();
var jobject = (JObject)jt;
person.FirstName = (string)jobject["FirstName"];
person.LastName = (string)jobject["LastName"];

return person;
});

var machine = new HttpResponseMachine(parserStore);

// Define action in HttpResponseMachine for all responses that return 200 OK and can be translated somehow to a Person
machine
.When(HttpStatusCode.OK)
.Then<Person>((m, l, p) => { testPerson = p; });


39 changes: 39 additions & 0 deletions src/HttpResponseMachine/DelegatingResponseHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Net.Http;
using System.Threading.Tasks;
using Tavis.Http;

namespace Tavis.HttpResponseMachine
{
/// <summary>
/// HttpResponseHandler that can be chained into a response pipeline
/// </summary>
public abstract class DelegatingResponseHandler : IResponseHandler
{
public DelegatingResponseHandler InnerResponseHandler { get; set; }

protected DelegatingResponseHandler()
{

}

protected DelegatingResponseHandler(DelegatingResponseHandler innerResponseHandler)
{
InnerResponseHandler = innerResponseHandler;
}

public virtual Task<HttpResponseMessage> HandleResponseAsync(IRequestFactory requestFactory, HttpResponseMessage responseMessage)
{
if (InnerResponseHandler != null)
{
return InnerResponseHandler.HandleResponseAsync(requestFactory, responseMessage);
}

var tcs = new TaskCompletionSource<HttpResponseMessage>();
tcs.SetResult(responseMessage);
return tcs.Task;
}
}



}
Loading

0 comments on commit 1699696

Please sign in to comment.