Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WorkspaceApi and supporting classes #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions Genesys.Workspace.userprefs
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
<Properties>
<MonoDevelop.Ide.Workbench ActiveDocument="src/Genesys.Workspace/Client/ApiClient.cs">
<Files>
<File FileName="src/Genesys.Workspace/Client/ApiClient.cs" Line="1" Column="1" />
<File FileName="src/Genesys.Workspace/WorkspaceApiException.cs" Line="1" Column="1" />
<File FileName="src/Genesys.Workspace/WorkspaceApi.cs" Line="31" Column="41" />
<File FileName="src/Genesys.Workspace/Api/ReportingApi.cs" Line="36" Column="18" />
</Files>
<Pads>
<Pad Id="ProjectPad">
<State name="__root__">
<Node name="Genesys.Workspace" expanded="True">
<Node name="Genesys.Workspace" expanded="True">
<Node name="Api" expanded="True" selected="True" />
<Node name="Client" expanded="True" />
</Node>
</Node>
</State>
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.Workbench />
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
Expand Down
71 changes: 71 additions & 0 deletions src/Genesys.Workspace/ApiClientLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Linq;
using Newtonsoft.Json;
using RestSharp;

namespace Genesys.Workspace.Internal.Client
{
public partial class ApiClient
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

/// <summary>
/// Allows for extending request processing for <see cref="ApiClient"/> generated code.
/// </summary>
/// <param name="request">The RestSharp request object</param>
partial void InterceptRequest(IRestRequest request)
{
string contentType = null;

foreach(Parameter p in request.Parameters)
{
if ( p.Type == ParameterType.RequestBody)
{
contentType = p.Name;
}
}

if (contentType == null)
{
request.AddHeader("Content-type", "application/json");
}
}

/// <summary>
/// Allows for extending response processing for <see cref="ApiClient"/> generated code.
/// </summary>
/// <param name="request">The RestSharp request object</param>
/// <param name="response">The RestSharp response object</param>
partial void InterceptResponse(IRestRequest request, IRestResponse response)
{
var requestToLog = new
{
// ToString() here to have the method as a nice string otherwise it will just show the enum value
method = request.Method.ToString(),
resource = request.Resource,
// Parameters are custom anonymous objects in order to have the parameter type as a nice string
// otherwise it will just show the enum value
parameters = request.Parameters.Select(parameter => new
{
name = parameter.Name,
value = parameter.Value,
type = parameter.Type.ToString()
}),
};

var responseToLog = new
{
statusCode = response.StatusCode,
content = response.Content,
headers = response.Headers,
// The Uri that actually responded (could be different from the requestUri if a redirection occurred)
responseUri = response.ResponseUri,
errorMessage = response.ErrorMessage,
};

log.Debug(string.Format("\nRequest: {0}\nResponse: {1}",
JsonConvert.SerializeObject(requestToLog),
JsonConvert.SerializeObject(responseToLog)));
}
}
}
Loading