Skip to content

Commit f996c9f

Browse files
committed
Implement GetStatusCodes and refactoring
1 parent 7880656 commit f996c9f

File tree

14 files changed

+80
-73
lines changed

14 files changed

+80
-73
lines changed

SSLLWrapper/ApiService.cs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using System;
2-
using Newtonsoft.Json;
32
using SSLLWrapper.Helpers;
43
using SSLLWrapper.Interfaces;
54
using SSLLWrapper.Models.Response;
6-
using SSLLWrapper.Models.Response.BaseResponseSubModels;
5+
using SSLLWrapper.Models.Response.BaseSubModels;
76

87
namespace SSLLWrapper
98
{
@@ -55,9 +54,9 @@ public ApiService(string apiUrl)
5554

5655
#endregion
5756

58-
public InfoModel Info()
57+
public Info Info()
5958
{
60-
var infoModel = new InfoModel();
59+
var infoModel = new Info();
6160

6261
// Building new request model
6362
var requestModel = _requestModelHelper.InfoProperties(ApiUrl, "info");
@@ -87,15 +86,15 @@ public InfoModel Info()
8786
return infoModel;
8887
}
8988

90-
public AnalyzeModel Analyze(string host)
89+
public Analyze Analyze(string host)
9190
{
9291
// overloaded method to provide a default set of options
9392
return Analyze(host, Publish.Off, ClearCache.On, FromCache.Off, All.On);
9493
}
9594

96-
public AnalyzeModel Analyze(string host, Publish publish, ClearCache clearCache, FromCache fromCache, All all)
95+
public Analyze Analyze(string host, Publish publish, ClearCache clearCache, FromCache fromCache, All all)
9796
{
98-
var analyzeModel = new AnalyzeModel();
97+
var analyzeModel = new Analyze();
9998

10099
// Checking host is valid before continuing
101100
if (!_urlHelper.IsValid(host))
@@ -129,21 +128,21 @@ public AnalyzeModel Analyze(string host, Publish publish, ClearCache clearCache,
129128
return analyzeModel;
130129
}
131130

132-
public EndpointDataModel GetEndpointData(string host, string s)
131+
public Endpoint GetEndpointData(string host, string s)
133132
{
134133
return GetEndpointData(host, s, FromCache.Off);
135134
}
136135

137-
public EndpointDataModel GetEndpointData(string host, string s, FromCache fromCache)
136+
public Endpoint GetEndpointData(string host, string s, FromCache fromCache)
138137
{
139-
var endpointDataModel = new EndpointDataModel();
138+
var endpointModel = new Endpoint();
140139

141140
// Checking host is valid before continuing
142141
if (!_urlHelper.IsValid(host))
143142
{
144-
endpointDataModel.HasErrorOccurred = true;
145-
endpointDataModel.Errors.Add(new Error { message = "Host does not pass preflight validation. No Api call has been made." });
146-
return endpointDataModel;
143+
endpointModel.HasErrorOccurred = true;
144+
endpointModel.Errors.Add(new Error { message = "Host does not pass preflight validation. No Api call has been made." });
145+
return endpointModel;
147146
}
148147

149148
// Building request model
@@ -156,23 +155,42 @@ public EndpointDataModel GetEndpointData(string host, string s, FromCache fromCa
156155
var webResponse = _api.MakeGetRequest(requestModel);
157156

158157
// Binding result to model
159-
_responsePopulationHelper.EndpointDataModel(webResponse, endpointDataModel);
158+
_responsePopulationHelper.EndpointModel(webResponse, endpointModel);
160159
}
161160
catch (Exception ex)
162161
{
163-
endpointDataModel.HasErrorOccurred = true;
164-
endpointDataModel.Errors.Add(new Error { message = ex.ToString() });
162+
endpointModel.HasErrorOccurred = true;
163+
endpointModel.Errors.Add(new Error { message = ex.ToString() });
165164
}
166165

167166
// Checking if errors have occoured either from ethier api or wrapper
168-
if (endpointDataModel.Errors.Count != 0 && !endpointDataModel.HasErrorOccurred) { endpointDataModel.HasErrorOccurred = true; }
167+
if (endpointModel.Errors.Count != 0 && !endpointModel.HasErrorOccurred) { endpointModel.HasErrorOccurred = true; }
169168

170-
return endpointDataModel;
169+
return endpointModel;
171170
}
172171

173-
public string GetStatusCodes()
172+
public StatusDetails GetStatusCodes()
174173
{
175-
throw new NotImplementedException();
174+
var statusDetailsModel = new StatusDetails();
175+
176+
// Building request model
177+
var requestModel = _requestModelHelper.GetStatusCodeProperties(ApiUrl, "getStatusCodes");
178+
179+
try
180+
{
181+
// Making Api request and gathering response
182+
var webResponse = _api.MakeGetRequest(requestModel);
183+
184+
// Binding result to model
185+
_responsePopulationHelper.StatusDetailsModel(webResponse, statusDetailsModel);
186+
}
187+
catch (Exception ex)
188+
{
189+
statusDetailsModel.HasErrorOccurred = true;
190+
statusDetailsModel.Errors.Add(new Error { message = ex.ToString() });
191+
}
192+
193+
return statusDetailsModel;
176194
}
177195
}
178196
}

SSLLWrapper/Helpers/RequestModelHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,10 @@ public RequestModel GetEndpointDataProperties(string apiBaseUrl, string action,
3535

3636
return requestModel;
3737
}
38+
39+
public RequestModel GetStatusCodeProperties(string apiBaseUrl, string action)
40+
{
41+
return new RequestModel() {ApiBaseUrl = apiBaseUrl, Action = action};
42+
}
3843
}
3944
}

SSLLWrapper/Helpers/ResponsePopulationHelper.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,48 @@ public ResponsePopulationHelper()
1818
_webResponseHelper = new HttpWebResponseHelper();
1919
}
2020

21-
public InfoModel InfoModel(HttpWebResponse webResponse, InfoModel infoModel)
21+
public Info InfoModel(HttpWebResponse webResponse, Info infoModel)
2222
{
2323
var webResult = _webResponseHelper.GetResponsePayload(webResponse);
2424

25-
infoModel = JsonConvert.DeserializeObject<InfoModel>(webResult, JsonSerializerSettings);
25+
infoModel = JsonConvert.DeserializeObject<Info>(webResult, JsonSerializerSettings);
2626
infoModel.Headers.statusCode = _webResponseHelper.GetStatusCode(webResponse);
2727
infoModel.Headers.statusDescription = _webResponseHelper.GetStatusDescription(webResponse);
2828

2929
return infoModel;
3030
}
3131

32-
public AnalyzeModel AnalyzeModel(HttpWebResponse webResponse, AnalyzeModel analyzeModel)
32+
public Analyze AnalyzeModel(HttpWebResponse webResponse, Analyze analyzeModel)
3333
{
3434
var webResult = _webResponseHelper.GetResponsePayload(webResponse);
3535

36-
analyzeModel = JsonConvert.DeserializeObject<AnalyzeModel>(webResult, JsonSerializerSettings);
36+
analyzeModel = JsonConvert.DeserializeObject<Analyze>(webResult, JsonSerializerSettings);
3737
analyzeModel.Headers.statusCode = _webResponseHelper.GetStatusCode(webResponse);
3838
analyzeModel.Headers.statusDescription = _webResponseHelper.GetStatusDescription(webResponse);
3939

4040
return analyzeModel;
4141
}
4242

43-
public EndpointDataModel EndpointDataModel(HttpWebResponse webResponse, EndpointDataModel endpointDataModel)
43+
public Endpoint EndpointModel(HttpWebResponse webResponse, Endpoint endpointModel)
4444
{
4545
var webResult = _webResponseHelper.GetResponsePayload(webResponse);
4646

47-
endpointDataModel = JsonConvert.DeserializeObject<EndpointDataModel>(webResult, JsonSerializerSettings);
48-
endpointDataModel.Headers.statusCode = _webResponseHelper.GetStatusCode(webResponse);
49-
endpointDataModel.Headers.statusDescription = _webResponseHelper.GetStatusDescription(webResponse);
47+
endpointModel = JsonConvert.DeserializeObject<Endpoint>(webResult, JsonSerializerSettings);
48+
endpointModel.Headers.statusCode = _webResponseHelper.GetStatusCode(webResponse);
49+
endpointModel.Headers.statusDescription = _webResponseHelper.GetStatusDescription(webResponse);
5050

51-
return endpointDataModel;
51+
return endpointModel;
52+
}
53+
54+
public StatusDetails StatusDetailsModel(HttpWebResponse webResponse, StatusDetails statusDetails)
55+
{
56+
var webResult = _webResponseHelper.GetResponsePayload(webResponse);
57+
58+
statusDetails = JsonConvert.DeserializeObject<StatusDetails>(webResult, JsonSerializerSettings);
59+
statusDetails.Headers.statusCode = _webResponseHelper.GetStatusCode(webResponse);
60+
statusDetails.Headers.statusDescription = _webResponseHelper.GetStatusDescription(webResponse);
61+
62+
return statusDetails;
5263
}
5364
}
5465
}

SSLLWrapper/Interfaces/IRequestModelHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ interface IRequestModelHelper
77
RequestModel InfoProperties(string apiBaseUrl, string action);
88
RequestModel AnalyzeProperties(string apiBaseUrl, string action, string host, string publish, string clearCache, string fromCache, string all);
99
RequestModel GetEndpointDataProperties(string apiBaseUrl, string action, string host, string s, string fromCache);
10+
RequestModel GetStatusCodeProperties(string apiBaseUrl, string action);
1011
}
1112
}

SSLLWrapper/Interfaces/IResponsePopulationHelper.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ namespace SSLLWrapper.Interfaces
55
{
66
interface IResponsePopulationHelper
77
{
8-
InfoModel InfoModel(HttpWebResponse webResponse, InfoModel infoModel);
9-
AnalyzeModel AnalyzeModel(HttpWebResponse webResponse, AnalyzeModel analyzeModel);
10-
EndpointDataModel EndpointDataModel(HttpWebResponse webResponse, EndpointDataModel endpointDataModel);
8+
Info InfoModel(HttpWebResponse webResponse, Info infoModel);
9+
Analyze AnalyzeModel(HttpWebResponse webResponse, Analyze analyzeModel);
10+
Endpoint EndpointModel(HttpWebResponse webResponse, Endpoint endpointDataModel);
11+
StatusDetails StatusDetailsModel(HttpWebResponse webResponse, StatusDetails statusDetails);
1112
}
1213
}

SSLLWrapper/Models/Response/AnalyzeModel.cs renamed to SSLLWrapper/Models/Response/Analyze.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace SSLLWrapper.Models.Response
44
{
5-
public class AnalyzeModel : BaseModel
5+
public class Analyze : BaseModel
66
{
77
public string host { get; set; }
88
public int port { get; set; }

SSLLWrapper/Models/Response/BaseModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using SSLLWrapper.Models.Response.BaseResponseSubModels;
2+
using SSLLWrapper.Models.Response.BaseSubModels;
33

44
namespace SSLLWrapper.Models.Response
55
{

SSLLWrapper/Models/Response/BaseResponseSubModels/Error.cs renamed to SSLLWrapper/Models/Response/BaseSubModels/Error.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace SSLLWrapper.Models.Response.BaseResponseSubModels
1+
namespace SSLLWrapper.Models.Response.BaseSubModels
22
{
33
public class Error
44
{

SSLLWrapper/Models/Response/BaseResponseSubModels/Header.cs renamed to SSLLWrapper/Models/Response/BaseSubModels/Header.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace SSLLWrapper.Models.Response.BaseResponseSubModels
1+
namespace SSLLWrapper.Models.Response.BaseSubModels
22
{
33
public class Header
44
{

SSLLWrapper/Models/Response/Endpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace SSLLWrapper.Models.Response
44
{
5-
public class Endpoint
5+
public class Endpoint : BaseModel
66
{
77
public string ipAddress { get; set; }
88
public string statusMessage { get; set; }

0 commit comments

Comments
 (0)