public async Task <string> ExtractFromApi(int maxRecords, IeeeXploreSubmissionKind submissionKind, int?startYear, int?endYear) { var contentType = ContentTypeForSubmissionKind(submissionKind); var query = $"?apikey={apiKey}&format=json&max_records={maxRecords}&content_type={contentType}"; if (startYear is not null) { query += $"&start_year={startYear}"; } if (endYear is not null) { query += $"&end_year={endYear}"; } var response = await client.GetAsync(query); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsStringAsync()); } else { throw new WebException($"IEEE Xplore API request failed: {(int)response.StatusCode} {response.StatusCode}"); } }
static string ContentTypeForSubmissionKind(IeeeXploreSubmissionKind submissionKind) { var contentType = submissionKind switch { IeeeXploreSubmissionKind.Books => "Books", IeeeXploreSubmissionKind.InProceedings => "Conferences", _ => "Journals", }; return(contentType); }