Advertisement
Guest User

Contentful Entry Model Class

a guest
Jul 21st, 2020
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace cfclt
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Net.Http;
  6.  
  7.     using Contentful.Core;
  8.     using Contentful.Core.Configuration;
  9.     using Contentful.Core.Models;
  10.  
  11.     class Program
  12.     {
  13.         public class FieldTypesEntry
  14.         {
  15.             public double? NumberField { get; set; }
  16.             public string StringField { get; set; }
  17.             public Document RichTextField { get; set; }
  18.             public List<Asset> AssetField { get; set; }
  19.             public DateTime DateTimeField { get; set; }
  20.  
  21.             public void Render()
  22.             {
  23.                 Console.WriteLine(GetType());
  24.                 Console.WriteLine("NumberField: " + NumberField);
  25.                 Console.WriteLine("StringField: " + StringField);
  26.                 Console.WriteLine("DateTimeField: " + DateTimeField);
  27.                 Console.WriteLine("RichTextField: " +
  28.                                   new HtmlRenderer().ToHtml(RichTextField).GetAwaiter().GetResult());
  29.  
  30.                 foreach (Asset assetField in AssetField)
  31.                 {
  32.                     Console.WriteLine("AssetField: " + assetField.File.Url);
  33.                 }
  34.             }
  35.         }
  36.  
  37.         static void Main(string[] args)
  38.         {
  39.             HttpClient httpClient = new HttpClient();
  40.             ContentfulOptions options = new ContentfulOptions
  41.             {
  42.                 DeliveryApiKey = "Gg3vpa21vheFi28wzcPT7LDy3CgOEb0VJ62cGiPi0JQ",
  43.                 PreviewApiKey = "aVrO8Fhmoq-hNEDa78_QHkeqKIxgG6-JhofdnNpCj00",
  44.                 SpaceId = "qjiunow8a0ig"
  45.             };
  46.  
  47.             ContentfulClient client = new ContentfulClient(httpClient, options);
  48.             client.GetEntry<FieldTypesEntry>("7gRkxpacpEf7yLjL1ukb4G").GetAwaiter().GetResult().Render();
  49.         }
  50.     }
  51. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement