Skip to content

Commit

Permalink
This closes tmenier#61
Browse files Browse the repository at this point in the history
  • Loading branch information
kroniak committed Apr 5, 2016
1 parent 235d1f6 commit 8aa329b
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ packages
*.suo
*.nupkg
*.DotSettings.user
*.xproj.user
.vs
*.lock.json
*.log
19 changes: 15 additions & 4 deletions Build/Flurl.Http.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Flurl.Http</id>
<version>0.7.0</version>
<version>0.8.0</version>
<title>Flurl.Http</title>
<authors>Todd Menier</authors>
<projectUrl>http://tmenier.github.io/Flurl</projectUrl>
Expand All @@ -13,6 +13,7 @@
A fluent, portable, testable HTTP client library that extends Flurl's URL builder chain.
</description>
<releaseNotes>
0.8.0 - Support for the NETCore (github #61)
0.7.0 - BREAKING CHANGES: https://github.com/tmenier/Flurl/wiki/Release-Notes
0.6.4 - nuspec fix for Xamarin/non-PCL, AllowHttpStatus overloads with HttpStatusCode enum.
0.6.3 - Updated Flurl dependency to 1.0.9.
Expand All @@ -34,24 +35,34 @@
0.2.1 - Added support for getting streams and byte arrays.
0.2.0 - Added .NET 4.5 specific version with fewer dependencies.
0.1.3 - Added support for HEAD requests via HeadAsync (thanks to @benb1n).
</releaseNotes>
</releaseNotes>
<tags>httpclient rest json http fluent portable url uri tdd assert async</tags>
<dependencies>
<group targetFramework="net45">
<dependency id="Newtonsoft.Json" version="6.0.3" />
<dependency id="Flurl" version="1.0.10" />
<dependency id="Flurl" version="1.1.0" />
</group>
<group targetFramework="portable-net45+sl50+win+wpa81+wp80">
<dependency id="Microsoft.Bcl.Async" version="1.0.168" />
<dependency id="Microsoft.Net.Http" version="2.2.22" />
<dependency id="PCLStorage" version="0.9.6" />
<dependency id="Newtonsoft.Json" version="6.0.3" />
<dependency id="Flurl" version="1.0.10" />
<dependency id="Flurl" version="1.1.0" />
</group>
<group targetFramework=".NETPlatform5.4">
<dependency id="Flurl" version="1.1.0" />
<dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="System.Dynamic.Runtime" version="4.0.10" />
<dependency id="System.IO.FileSystem" version="4.0.0" />
<dependency id="System.Net.Http" version="4.0.0" />
<dependency id="System.Text.RegularExpressions" version="4.0.10" />
<dependency id="System.Threading" version="4.0.10" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\Flurl.Http.NET45\bin\Release\Flurl.Http.*" target="lib\net45" />
<file src="..\Flurl.Http.PCL\bin\Release\Flurl.Http.*" target="lib\portable-net45+sl50+win+wpa81+wp80" />
<file src="..\artifacts\bin\Flurl.Http.NETCore\Release\dotnet5.4\Flurl.Http.*" target="lib\dotnet5.4" />
</files>
</package>
10 changes: 9 additions & 1 deletion Build/Flurl.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Flurl</id>
<version>1.0.10</version>
<version>1.1.0</version>
<title>Flurl</title>
<authors>Todd Menier</authors>
<projectUrl>http://tmenier.github.io/Flurl</projectUrl>
Expand All @@ -13,6 +13,7 @@
A fluent, portable URL builder. To make HTTP calls off the fluent chain, check out Flurl.Http.
</description>
<releaseNotes>
1.1.0 - Support for the NETCore (github #61)
1.0.10 - More flexible kv parsing (github pr #16)
1.0.9 - Decode + as space, optionally encode space as + (github #41)
1.0.8 - Don't trim trailing slash (github #37)
Expand All @@ -29,8 +30,15 @@
0.2.0 - Added PCL support.
</releaseNotes>
<tags>fluent portable url uri querystring builder</tags>
<dependencies>
<group targetFramework=".NETPlatform5.4">
<dependency id="System.Linq" version="4.0.0" />
<dependency id="System.Reflection.TypeExtensions" version="4.0.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\Flurl\bin\Release\Flurl.*" target="lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+MonoTouch10" />
<file src="..\artifacts\bin\Flurl.NETCore\Release\dotnet5.4\Flurl.*" target="lib\dotnet5.4" />
</files>
</package>
Binary file modified Build/NuGet.exe
Binary file not shown.
9 changes: 9 additions & 0 deletions Build/Publish.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off

set workDir=%1
set publishSpec=%2
set publishDir=%3

cd %workDir%
if not exist "%publishDir%" mkdir "%publishDir%"
call NuGet.exe pack %publishSpec% -OutputDirectory %publishDir%
22 changes: 22 additions & 0 deletions Flurl.Http.NETCore/Flurl.Http.NETCore.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>52c8c00d-9bd2-4642-b103-f0a8c564fe05</ProjectGuid>
<RootNamespace>Flurl.Http.NETCore</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
31 changes: 31 additions & 0 deletions Flurl.Http.NETCore/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"title": "Flurl.Http.NETCore",

"dependencies": {
"Flurl": "1.1.0",
"Newtonsoft.Json": "8.0.3"
},

"compile": [ "../Flurl.Http.Shared/**/*.cs", "../Flurl.Http.NET45/**/*.cs" ],
"compileExclude": [ "../**/AssemblyInfo.cs" ],

"configurations": {
"Release": {
"compilationOptions": {
"optimize": true
}
}
},

"frameworks": {
"dotnet54": {
"dependencies": {
"System.Dynamic.Runtime": "4.0.10",
"System.IO.FileSystem": "4.0.0",
"System.Net.Http": "4.0.0",
"System.Text.RegularExpressions": "4.0.10",
"System.Threading": "4.0.10"
}
}
}
}
2 changes: 1 addition & 1 deletion Flurl.Http.PCL/Flurl.Http.PCL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if $(ConfigurationName) == Release (
"$(SolutionDir)Build\nuget.exe" pack "$(SolutionDir)Build\Flurl.Http.nuspec" -o "$(SolutionDir)Publish" -IncludeReferencedProjects
call $(SolutionDir)Build\publish.cmd $(SolutionDir)Build\ Flurl.Http.nuspec $(SolutionDir)Publish &gt;&gt; $(SolutionDir)Build\publish.log
)</PostBuildEvent>
</PropertyGroup>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
Expand Down
22 changes: 22 additions & 0 deletions Flurl.NETCore/Flurl.NETCore.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>52ce5e08-8f02-4f75-8b64-8e00e3262a0f</ProjectGuid>
<RootNamespace>Flurl.NETCore</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
77 changes: 77 additions & 0 deletions Flurl.NETCore/Util/CommonExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;

namespace Flurl.Util
{
public static class CommonExtensions
{
/// <summary>
/// Converts an object's public properties to a collection of string-based key-value pairs. If the object happens
/// to be an IDictionary, the IDictionary's keys and values converted to strings and returned.
/// </summary>
/// <param name="obj">The object to parse into key-value pairs</param>
/// <returns></returns>
public static IEnumerable<KeyValuePair<string, object>> ToKeyValuePairs(this object obj)
{
if (obj == null)
throw new ArgumentNullException(nameof(obj));

return
(obj is string) ? QueryParamCollection.Parse((string)obj) :
(obj is IEnumerable) ? CollectionToKV((IEnumerable)obj) :
ObjectToKV(obj);
}

/// <summary>
/// Returns a string that represents the current object, using CultureInfo.InvariantCulture where possible.
/// </summary>
public static string ToInvariantString(this object obj)
{
// inspired by: http://stackoverflow.com/a/19570016/62600

var c = obj as IConvertible;
if (c != null)
return c.ToString(CultureInfo.InvariantCulture);

var f = obj as IFormattable;
return f?.ToString(null, CultureInfo.InvariantCulture) ?? obj.ToString();
}

private static IEnumerable<KeyValuePair<string, object>> ObjectToKV(object obj)
{
return from prop in obj.GetType().GetProperties()
let val = prop.GetValue(obj, null)
select new KeyValuePair<string, object>(prop.Name, val);
}

private static IEnumerable<KeyValuePair<string, object>> CollectionToKV(IEnumerable col)
{
// Accepts KeyValuePairs or any aribitray types that contain a property called "Key" or "Name" and a property called "Value".
foreach (var item in col)
{
if (item == null)
continue;

var type = item.GetType();
var keyProp = type.GetProperty("Key") ?? type.GetProperty("key") ?? type.GetProperty("Name") ?? type.GetProperty("name");
if (keyProp == null)
throw new ArgumentException("Cannot parse " + type.Name + " to key-value pair. Type must contain a property called 'Key' or 'Name'.");

var valProp = type.GetProperty("Value") ?? type.GetProperty("value");
if (valProp == null)
throw new ArgumentException("Cannot parse " + type.Name + " to key-value pair. Type must contain a property called 'Value'.");

var key = keyProp.GetValue(item, null);
if (key == null)
continue;

var val = valProp.GetValue(item, null);
yield return new KeyValuePair<string, object>(key.ToInvariantString(), val);
}
}
}
}
23 changes: 23 additions & 0 deletions Flurl.NETCore/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"title": "Flurl.NETCore",

"compile": [ "../Flurl/**/*.cs" ],
"compileExclude": [ "../**/AssemblyInfo.cs", "../Flurl/Util/CommonExtensions.cs" ],

"configurations": {
"Release": {
"compilationOptions": {
"optimize": true
}
}
},

"frameworks": {
"dotnet54": {
"dependencies": {
"System.Linq": "4.0.0",
"System.Reflection.TypeExtensions": "4.0.0"
}
}
}
}
Loading

0 comments on commit 8aa329b

Please sign in to comment.