misolutions

PublicationRepository.cs

Jun 16th, 2020
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Linq;
  8. using RestSharp;
  9. using RmcUtmScholar.Models;
  10.  
  11. namespace RmcScholar.Helper
  12. {
  13.     [Route("api/[controller]")]
  14.     public class PublicationRepository : Controller
  15.     {
  16.         public async Task<SCHOLAR_INFO_DETAILS> GetH_Index_Citations(string id)
  17.         {
  18.             var client = new RestClient("https://api.elsevier.com/content/author/author_id/{id}?apiKey=91d28f0563469b909bacc58574650b33&httpAccept=application/json&view=METRICS");
  19.             client.Timeout = -1;
  20.             var request = new RestRequest(Method.GET);
  21.             request.AddHeader("apiKey", "7169c2716d70c8dcff9124532b65e173");
  22.             IRestResponse response = await client.ExecuteAsync(request);
  23.  
  24.             if (response.IsSuccessful)
  25.             {
  26.                 var content = JsonConvert.DeserializeObject<JToken>(response.Content);
  27.                 var h_index = content["h-index"].Value<String>();
  28.                 var coauthor_count = content["coauthor-count"].Value<String>();
  29.  
  30.                 return new SCHOLAR_INFO_DETAILS
  31.                 {
  32.                     H_INDEX = h_index,
  33.                     CITATIONS = coauthor_count
  34.                 };
  35.                
  36.             }            
  37.  
  38.             return null;
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment