-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a quick manner to get the source values as returned by the API - instead of the enum values? #156
Comments
Hey, @dm007 sorry about the late reply, originally there was no I'd say the library doesn't really support the display name of the enum values, as the actual Enum values are just representations for the options (also we've not been able to have an enum of "England/Wales" as that's not supported by the language. Honestly, it'd be a nice feature to add in and I think it would be possible by adding some I'd imagine the code to look something like the following: var result = await client.GetCompanyProfileAsync("10440441");
// EnglandAndWales
var jurisdiction = result.Data.Jurisdiction;
Console.WriteLine(jurisdiction);
// England/Wales
var displayName = result.Data.GetDisplayName(x =>x.Jurisdiction);
Console.WriteLine(displayName); Alternately you could get the raw value returned back from the API and map it yourself and map it directly in your own code. // Actually get value from API
var companyProfile = new
{
Jurisdiction = Jurisdiction.EnglandAndWales
};
var enumType = typeof(Jurisdiction);
var memberInfos = enumType.GetMember(companyProfile.Jurisdiction.ToString());
var enumValueMemberInfo = memberInfos[0];
var valueAttributes = enumValueMemberInfo.GetCustomAttributes(typeof(EnumMemberAttribute), false);
var rawValue = ((EnumMemberAttribute)valueAttributes[0]).Value;
// england-wales
Console.WriteLine(rawValue); |
Thanks @kevbite. I'm using reflection right now in my poc to lookup the values as returned by the API. I will keep an eye here to see if/when DisplayName gets added, and can update as necessary. This is a great library though, as it makes it quick and easy to fetch data from Companies House. note: By the way, I'm trying to figure out a way to fetch document metadata and document pdf, as the document id seems to be issue and nothing seems to be working so far. Going to keep looking when I get chance, and hopefully, get figure out the gaps/issues. Thanks again. |
@dm007 glad the library is useful, if you fancy forking the code and pushing the changes in for the DisplayName stuff I'll happily accept it into the codebase. (I'm just fairly busy at the moment to implement it). I've raised an issue here for you to track - #157 Not sure what's going off with the document metadata, we do have some tests in the codebase that show them working which might be useful? https://github.com/kevbite/CompaniesHouse.NET/blob/master/src/CompaniesHouse.IntegrationTests/Tests/DocumentTests/DocumentMetadataTestsValid.cs |
@kevbite - Thanks! |
Is there a way to retrieve the source value as returned by the API instead of the enum values or look to include the following availalbe from Companies House documentation for proper mapping?
https://raw.githubusercontent.com/companieshouse/api-enumerations/master/constants.yml
For example:
Company Profile > Company Type:
Source from API: "ltd"
enum from the library: "Ltd"
The mapping from the constants.yml and as it appears on the Companies House site: "Private limited company"
Company Profile > Jurisdiction:
source from API: "england-wales"
enum from the library: "EnglandAndWales"
The mapping from the constants.yml and as it appears on the Companies House site: "England/Wales"
The text was updated successfully, but these errors were encountered: