Skip to content

Commit

Permalink
Merge pull request #10 from hanssens/vnext
Browse files Browse the repository at this point in the history
Push changes from 'vnext' into 'master', for v1.2.0
  • Loading branch information
hanssens committed Sep 2, 2015
2 parents 086adba + 4881f7e commit 9eca6b7
Show file tree
Hide file tree
Showing 40 changed files with 26 additions and 14 deletions.
Binary file added package/Hanssens.Net.Extensions.1.2.0.nupkg
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Linq;

namespace Hanssens.Net.IO
{
Expand All @@ -20,8 +22,8 @@ public static class JsonRequest
/// </summary>
/// <param name="requestUri">The full request URI / endpoint to call.</param>
/// <param name="args">[Optional]Any given object which will be serialized to JSON and included as message body</param>
public static JsonResponse Delete(string requestUri, object args = null){
var response = _Execute (requestUri, "DELETE", args);
public static JsonResponse Delete(string requestUri, object args = null, Dictionary<string , string> headers = null){
var response = _Execute (requestUri, "DELETE", args, headers);
return response;
}

Expand All @@ -30,8 +32,9 @@ public static JsonResponse Delete(string requestUri, object args = null){
/// </summary>
/// <param name="requestUri">The full request URI / endpoint to call.</param>
/// <param name="args">[Optional]Any given object which will be serialized to JSON and included as message body</param>
public static JsonResponse Get(string requestUri, object args = null){
var response = _Execute (requestUri, "GET", args);
public static JsonResponse Get(string requestUri, Dictionary<string, string> headers = null)
{
var response = _Execute (requestUri, "GET", args: null, headers: headers);
return response;
}

Expand All @@ -40,8 +43,9 @@ public static JsonResponse Get(string requestUri, object args = null){
/// </summary>
/// <param name="requestUri">The full request URI / endpoint to call.</param>
/// <param name="args">[Optional]Any given object which will be serialized to JSON and included as message body</param>
public static JsonResponse Post(string requestUri, object args = null){
var response = _Execute (requestUri, "POST", args);
public static JsonResponse Post(string requestUri, object args = null, Dictionary<string, string> headers = null)
{
var response = _Execute (requestUri, "POST", args, headers);
return response;
}

Expand All @@ -50,16 +54,17 @@ public static JsonResponse Post(string requestUri, object args = null){
/// </summary>
/// <param name="requestUri">The full request URI / endpoint to call.</param>
/// <param name="args">[Optional]Any given object which will be serialized to JSON and included as message body</param>
public static JsonResponse Put(string requestUri, object args = null){
var response = _Execute (requestUri, "PUT", args);
public static JsonResponse Put(string requestUri, object args = null, Dictionary<string, string> headers = null)
{
var response = _Execute (requestUri, "PUT", args, headers);
return response;
}

private static JsonResponse _Execute(string requestUri, string httpMethod) {
return _Execute (requestUri, httpMethod, null);
return _Execute (requestUri, httpMethod, args: null, headers: null);
}

private static JsonResponse _Execute(string requestUri, string httpMethod, object args) {
private static JsonResponse _Execute(string requestUri, string httpMethod, object args, Dictionary<string, string> headers = null) {

// prepare the request for a specific json call
var request = (HttpWebRequest)WebRequest.Create(requestUri);
Expand All @@ -85,11 +90,18 @@ private static JsonResponse _Execute(string requestUri, string httpMethod, objec
// Also, specs at RFC4627: http://www.ietf.org/rfc/rfc4627.txt
request.ContentType = "application/json; charset=utf-8";

// append headers, if provided
if (headers != null && headers.Any())
{
request.Headers = new WebHeaderCollection();
foreach (var h in headers)
request.Headers.Add(h.Key, h.Value);
}

// determine if there are any arguments provided, which needs to be serialized to json and
// embedded into the request body, before we actually start asking for a response
if (args != null) {


// serialize the arguments to json
var jsonSerializedArguments = JsonConvert.SerializeObject(args);

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Juliën Hanssens @hanssens.com")]
[assembly: AssemblyProduct("Hanssens.Net")]
[assembly: AssemblyCopyright("Copyright © Juliën Hanssens @hanssens.com 2013")]
[assembly: AssemblyCopyright("Copyright © Juliën Hanssens @hanssens.com 2013-2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.1")]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: AssemblyVersion("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
File renamed without changes.

0 comments on commit 9eca6b7

Please sign in to comment.