Example #1
0
        public async Task <BlogPostDetailViewModel> GetBlogPostDetail(int blogPostId)
        {
            var requestMessage = _apiClient.CreateGetRequest($"{_appSettings.BlogApiUrl}{BasePath}/BlogPostDetail?blogPostId={blogPostId}");
            var response       = await _apiClient.SendAsync(requestMessage);

            string responseBody = await response.Content.ReadAsStringAsync();

            var blogPostList = JsonConvert.DeserializeObject <BlogPostDetailViewModel>(responseBody);

            return(blogPostList);
        }
Example #2
0
        public async Task <bool> CanCreatePost(string token)
        {
            var requestMessage = _apiClient.CreateGetRequest($"{_appSettings.AdminApiUrl}{BasePath}/CanCreatePost");

            requestMessage.Headers.Add("Authorization", "Bearer " + token);
            var response = await _apiClient.SendAsync(requestMessage);

            string responseBody = await response.Content.ReadAsStringAsync();

            return(true);
        }
Example #3
0
 private static UpdateInfo?FindNewRelease(IHttpClient hc,
                                          string url,
                                          string?assetName,
                                          Predicate <GitHubRelease> condition)
 {
     try
     {
         var request = hc.CreateGetRequest(new Uri(url), new Dictionary <string, List <string> >
         {
             ["User-Agent"] = new List <string> {
                 UserAgent
             }
         });
         using var response     = hc.Send(request);
         using var stream       = response.GetResponseStream();
         using var streamReader = new StreamReader(stream);
         using var r            = new JsonTextReader(streamReader);
         var serializer = new JsonSerializer();
         var release    = serializer.Deserialize <GitHubRelease?>(r);
         if (!release.HasValue)
         {
             return(null);
         }
         if (condition.Invoke(release.Value))
         {
             if (release.Value.Assets == null)
             {
                 return(null);
             }
             foreach (var asset in release.Value.Assets)
             {
                 if (asset.Name == assetName || assetName == null)
                 {
                     return(new UpdateInfo
                     {
                         Url = asset.Url,
                         Name = asset.Name,
                         Size = asset.Size,
                         TagName = release.Value.TagName,
                         IsExternal = true
                     });
                 }
             }
             return(null);
         }
     }
     catch (Exception ex)
     {
         Log.Debug(ex, "Error in FindNewRelease");
     }
     return(null);
 }