-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PRIME-2529 Fill missing organization registration id (#2483)
* initial commit * fix PR issue * more fix * fix PR issues
- Loading branch information
Showing
6 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
prime-dotnet-webapi/HttpClients/Org Book API/IOrgBookClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Threading.Tasks; | ||
|
||
using Prime.HttpClients.PharmanetCollegeApiDefinitions; | ||
|
||
namespace Prime.HttpClients | ||
{ | ||
public interface IOrgBookClient | ||
{ | ||
Task<string> GetOrgBookRegistrationIdAsync(string orgName); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
prime-dotnet-webapi/HttpClients/Org Book API/OrgBookClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using Newtonsoft.Json.Linq; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Prime.HttpClients | ||
{ | ||
public class OrgBookClient : BaseClient, IOrgBookClient | ||
{ | ||
private readonly HttpClient _client; | ||
private readonly ILogger _logger; | ||
|
||
public OrgBookClient(HttpClient client, | ||
ILogger<OrgBookClient> logger) | ||
: base(PropertySerialization.CamelCase) | ||
{ | ||
_client = client ?? throw new ArgumentNullException(nameof(client)); | ||
_logger = logger; | ||
} | ||
|
||
public async Task<string> GetOrgBookRegistrationIdAsync(string orgName) | ||
{ | ||
string registrationId = null; | ||
HttpResponseMessage response = null; | ||
try | ||
{ | ||
response = await _client.GetAsync($"https://www.orgbook.gov.bc.ca/api/v2/search/credential/topic/facets?name=${HttpUtility.UrlEncode(orgName)}"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError($"Exception: {ex.Message} for orgName: {orgName}"); | ||
} | ||
|
||
if (response != null) | ||
{ | ||
string searchResult = await response.Content.ReadAsStringAsync(); | ||
|
||
try | ||
{ | ||
var json = JObject.Parse(searchResult); | ||
|
||
var objectResults = json["objects"]["results"].Where(r => r["topic"]["names"][0]["text"].ToString() == orgName); | ||
if (objectResults.Count() > 0) | ||
{ | ||
registrationId = objectResults.First()["topic"]["source_id"].ToString(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError($"Exception: {ex.Message} for orgName: {orgName}"); | ||
} | ||
} | ||
|
||
return registrationId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters