forked from BAPostma/PostcodeAPI.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostcodeApiClientBase.cs
More file actions
44 lines (34 loc) · 1.28 KB
/
Copy pathPostcodeApiClientBase.cs
File metadata and controls
44 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Text.RegularExpressions;
using PostcodeAPI.V1;
using RestSharp;
namespace PostcodeAPI
{
public abstract class PostcodeApiClientBase
{
protected RestClient Client;
public string EndpointUrl { get; set; }
public string HeaderKey { get; set; }
public string APIKey { get; set; }
protected PostcodeApiClientBase(string apiKey)
{
APIKey = apiKey;
}
protected void InitaliseClient()
{
Client = new RestClient(EndpointUrl);
Client.AddDefaultHeader(HeaderKey, APIKey);
}
//public abstract ApiResultWrapper GetAddress(string postcode);
//public abstract ApiResultWrapper GetAddress(string postcode, int number);
/// <summary>
/// Returns the P4, P5 or P6 format detected by the input.
/// </summary>
public string FindPostcodeType(string postcode)
{
if (Regex.IsMatch(postcode, @"^[0-9]{4}[a-zA-Z]{2}$")) return Constants.PostcodeFormatTypes.P6;
if (Regex.IsMatch(postcode, @"^[0-9]{4}[a-zA-Z]{1}$")) return Constants.PostcodeFormatTypes.P5;
if (Regex.IsMatch(postcode, @"^[0-9]{4}$")) return Constants.PostcodeFormatTypes.P4;
return string.Empty;
}
}
}