Skip to content

Commit 7551315

Browse files
committed
Complete GetEndpointData method
1 parent 151d717 commit 7551315

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

SSLLWrapper/ApiService.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,48 @@ public AnalyzeModel Analyze(string host, Publish publish, ClearCache clearCache,
139139
return analyzeModel;
140140
}
141141

142-
public string GetEndpointData(string host, string s)
142+
public EndpointDataModel GetEndpointData(string host, string s)
143143
{
144-
return GetEndpointData(host, s, "no");
144+
return GetEndpointData(host, s, FromCache.Off);
145145
}
146146

147-
public string GetEndpointData(string host, string s, string fromCache)
147+
public EndpointDataModel GetEndpointData(string host, string s, FromCache fromCache)
148148
{
149-
throw new NotImplementedException();
149+
var endpointDataModel = new EndpointDataModel();
150+
151+
// Checking host is valid before continuing
152+
if (!_urlHelper.IsValid(host))
153+
{
154+
endpointDataModel.HasErrorOccurred = true;
155+
endpointDataModel.Errors.Add(new Error { message = "Host does not pass preflight validation. No Api call has been made." });
156+
return endpointDataModel;
157+
}
158+
159+
// Building request model
160+
var requestModel = _requestModelHelper.GetEndpointDataProperties(ApiUrl, "getEndpointData", host, s,
161+
fromCache.ToString());
162+
163+
try
164+
{
165+
// Making Api request and gathering response
166+
var webResponse = _api.MakeGetRequest(requestModel);
167+
var webResult = _webResponseHelper.GetResponsePayload(webResponse);
168+
169+
// Trying to bind result to model
170+
endpointDataModel = JsonConvert.DeserializeObject<EndpointDataModel>(webResult, JsonSerializerSettings);
171+
endpointDataModel.Headers.statusCode = _webResponseHelper.GetStatusCode(webResponse);
172+
endpointDataModel.Headers.statusDescription = _webResponseHelper.GetStatusDescription(webResponse);
173+
}
174+
catch (Exception ex)
175+
{
176+
endpointDataModel.HasErrorOccurred = true;
177+
endpointDataModel.Errors.Add(new Error { message = ex.ToString() });
178+
}
179+
180+
// Checking if errors have occoured either from ethier api or wrapper
181+
if (endpointDataModel.Errors.Count != 0 && !endpointDataModel.HasErrorOccurred) { endpointDataModel.HasErrorOccurred = true; }
182+
183+
return endpointDataModel;
150184
}
151185

152186
public string GetStatusCodes()

SSLLWrapper/Helpers/RequestModelHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,16 @@ public RequestModel AnalyzeProperties(string apiBaseUrl, string action, string h
2424

2525
return requestModel;
2626
}
27+
28+
public RequestModel GetEndpointDataProperties(string apiBaseUrl, string action, string host, string s, string fromCache)
29+
{
30+
var requestModel = new RequestModel() {ApiBaseUrl = apiBaseUrl, Action = action};
31+
32+
requestModel.Parameters.Add("host", host);
33+
requestModel.Parameters.Add("s", s);
34+
requestModel.Parameters.Add("fromCache", fromCache);
35+
36+
return requestModel;
37+
}
2738
}
2839
}

SSLLWrapper/Interfaces/IRequestModelHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ interface IRequestModelHelper
66
{
77
RequestModel InfoProperties(string apiBaseUrl, string action);
88
RequestModel AnalyzeProperties(string apiBaseUrl, string action, string host, string publish, string clearCache, string fromCache, string all);
9+
RequestModel GetEndpointDataProperties(string apiBaseUrl, string action, string host, string s, string fromCache);
910
}
1011
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using SSLLWrapper.Models.Response.EndpointSubModels;
2+
3+
namespace SSLLWrapper.Models.Response
4+
{
5+
public class EndpointDataModel : BaseModel
6+
{
7+
public string ipAddress { get; set; }
8+
public string statusMessage { get; set; }
9+
public string statusDetails { get; set; }
10+
public string statusDetailsMessage { get; set; }
11+
public int progress { get; set; }
12+
public int eta { get; set; }
13+
public int delegation { get; set; }
14+
15+
// Two groups of poperities can be returned. Just seperating them out for my own reference.
16+
public int duration { get; set; }
17+
public string grade { get; set; }
18+
public bool hasWarnings { get; set; }
19+
public bool isExceptional { get; set; }
20+
21+
public Details Details { get; set; }
22+
23+
public EndpointDataModel()
24+
{
25+
Details = new Details();
26+
}
27+
}
28+
}

SSLLWrapper/SSLLWrapper.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<Compile Include="Models\Response\BaseModel.cs" />
6060
<Compile Include="Models\Response\BaseResponseSubModels\Header.cs" />
6161
<Compile Include="Models\Response\BaseResponseSubModels\Error.cs" />
62+
<Compile Include="Models\Response\EndpointDataModel.cs" />
6263
<Compile Include="Models\Response\EndpointSubModels\Cert.cs" />
6364
<Compile Include="Models\Response\EndpointSubModels\Cert2.cs" />
6465
<Compile Include="Models\Response\EndpointSubModels\Chain.cs" />

0 commit comments

Comments
 (0)