From cc56b8cc73eee2581d025790446218628119f33f Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sat, 5 Sep 2015 13:07:47 -0400 Subject: [PATCH] add comment --- src/Untappd.Net/Request/Repository.cs | 203 +++++++++++++------------- 1 file changed, 102 insertions(+), 101 deletions(-) diff --git a/src/Untappd.Net/Request/Repository.cs b/src/Untappd.Net/Request/Repository.cs index ee64148..9bb35b8 100644 --- a/src/Untappd.Net/Request/Repository.cs +++ b/src/Untappd.Net/Request/Repository.cs @@ -9,117 +9,118 @@ using Untappd.Net.Exception; namespace Untappd.Net.Request { - public sealed partial class Repository - { - internal IRestClient Client; - internal IRestRequest Request; - public bool FailFast { get; set; } + public sealed partial class Repository + { + internal IRestClient Client; + internal IRestRequest Request; + public bool FailFast { get; set; } - /// - /// Event to listen to when failFast is set to false - /// This allows you to capture the excpetion, before its swallowed - /// - public event UnhandledExceptionEventHandler OnExceptionThrown; + /// + /// Event to listen to when failFast is set to false + /// This allows you to capture the excpetion, before its swallowed + /// + public event UnhandledExceptionEventHandler OnExceptionThrown; - /// - /// Make a repository - /// - /// Should we throw exceptions? or just return null - public Repository(bool failFast = true, int timeout = 0) - { - Client = new RestClient(Constants.BaseRequestString); - Request = new RestRequest - { - Timeout = timeout - }; - FailFast = failFast; - } + /// + /// Make a repository + /// + /// Should we throw exceptions? or just return null + /// Set a timeout in milliseconds + public Repository(bool failFast = true, int timeout = 0) + { + Client = new RestClient(Constants.BaseRequestString); + Request = new RestRequest + { + Timeout = timeout + }; + FailFast = failFast; + } - [Obsolete("This constructor is used for mocking purposes only", false)] - internal Repository(IRestClient client, IRestRequest request) - { - Client = client; - Request = request; - } + [Obsolete("This constructor is used for mocking purposes only", false)] + internal Repository(IRestClient client, IRestRequest request) + { + Client = client; + Request = request; + } - internal Repository ConfigureRequest(string endPoint, IDictionary bodyParameters = null, Method webMethod = Method.GET) - { - Request.Resource = endPoint; - Request.Method = webMethod; - if (Request.Parameters != null && Request.Parameters.Count > 0) - { - Request.Parameters.Clear(); - } + internal Repository ConfigureRequest(string endPoint, IDictionary bodyParameters = null, Method webMethod = Method.GET) + { + Request.Resource = endPoint; + Request.Method = webMethod; + if (Request.Parameters != null && Request.Parameters.Count > 0) + { + Request.Parameters.Clear(); + } - if (bodyParameters == null) return this; - foreach (var param in bodyParameters) - { - Request.AddParameter(param.Key, param.Value); - } - return this; - } + if (bodyParameters == null) return this; + foreach (var param in bodyParameters) + { + Request.AddParameter(param.Key, param.Value); + } + return this; + } - internal Repository ConfigureRequest(IUntappdCredentials credentials, string endPoint, IDictionary bodyParameters = null, Method webMethod = Method.GET) - { - ConfigureRequest(endPoint, bodyParameters, webMethod); - foreach (var untappdCredential in credentials.AuthenticationData) - { - Request.AddParameter(untappdCredential.Key, untappdCredential.Value); - } - return this; - } + internal Repository ConfigureRequest(IUntappdCredentials credentials, string endPoint, IDictionary bodyParameters = null, Method webMethod = Method.GET) + { + ConfigureRequest(endPoint, bodyParameters, webMethod); + foreach (var untappdCredential in credentials.AuthenticationData) + { + Request.AddParameter(untappdCredential.Key, untappdCredential.Value); + } + return this; + } - private TResult ExecuteRequest() - where TResult : class - { - return ProcessExecution(Client.Execute(Request)); - } + private TResult ExecuteRequest() + where TResult : class + { + return ProcessExecution(Client.Execute(Request)); + } - private async Task ExecuteRequestAsync() - where TResult : class - { - return ProcessExecution(await Client.ExecuteTaskAsync(Request)); - } + private async Task ExecuteRequestAsync() + where TResult : class + { + return ProcessExecution(await Client.ExecuteTaskAsync(Request)); + } - private TResult ProcessExecution(IRestResponse response) - where TResult : class - { - //if the return type is not 200 throw errors - if (response.StatusCode != HttpStatusCode.OK) - { - var excpetion = new HttpErrorException(Request, response); - var eventThrow = OnExceptionThrown; + private TResult ProcessExecution(IRestResponse response) + where TResult : class + { + //if the return type is not 200 throw errors + if (response.StatusCode != HttpStatusCode.OK) + { + var excpetion = new HttpErrorException(Request, response); + var eventThrow = OnExceptionThrown; - if (eventThrow != null) - { - eventThrow(this, new UnhandledExceptionEventArgs(excpetion, FailFast)); - } - if (FailFast) - { - throw excpetion; - } - return null; - } - //try to deserialize - try - { - return JsonConvert.DeserializeObject(response.Content); - } - catch (System.Exception e) - { - var eventThrow = OnExceptionThrown; + if (eventThrow != null) + { + eventThrow(this, new UnhandledExceptionEventArgs(excpetion, FailFast)); + } + if (FailFast) + { + throw excpetion; + } + return null; + } + //try to deserialize + try + { + return JsonConvert.DeserializeObject(response.Content); + } + catch (System.Exception e) + { + var eventThrow = OnExceptionThrown; - if (eventThrow != null) - { - eventThrow(this, new UnhandledExceptionEventArgs(e, FailFast)); - } - if (FailFast) - { - throw; - } + if (eventThrow != null) + { + eventThrow(this, new UnhandledExceptionEventArgs(e, FailFast)); + } + if (FailFast) + { + throw; + } - return null; - } - } - } + return null; + } + } + } } \ No newline at end of file