diff --git a/ButterCMS/ButterCMSClient.cs b/ButterCMS/ButterCMSClient.cs index 10c0ad9..66958e2 100644 --- a/ButterCMS/ButterCMSClient.cs +++ b/ButterCMS/ButterCMSClient.cs @@ -23,7 +23,7 @@ public class ButterCMSClient private TimeSpan defaultTimeout = new TimeSpan(0, 0, 10); private int maxRequestTries; - private const string apiBaseAddress = "https://api.buttercms.com/"; + private const string apiBaseAddressDefault = "https://api.buttercms.com/"; private const string listPostsEndpoint = "v2/posts/"; private const string retrievePostEndpoint = "v2/posts/{0}/"; @@ -56,6 +56,7 @@ public ButterCMSClient(string authToken, TimeSpan? timeOut = null, int maxReques System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; #endif + string apiBaseAddress = Environment.GetEnvironmentVariable("API_BASE_URL") ?? apiBaseAddressDefault; httpClient = new HttpClient(httpMessageHandler ?? new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip diff --git a/ButterCMS/Models/Page.cs b/ButterCMS/Models/Page.cs index 81ed039..f4304db 100644 --- a/ButterCMS/Models/Page.cs +++ b/ButterCMS/Models/Page.cs @@ -12,5 +12,8 @@ public class Page [JsonProperty("page_type")] public string PageType { get; set; } public T Fields { get; set; } + public StatusEnum Status { get; set; } + public DateTime? Scheduled { get; set; } } } + diff --git a/ButterCMS/Models/Post.cs b/ButterCMS/Models/Post.cs index 8e8d4e6..e56ea95 100644 --- a/ButterCMS/Models/Post.cs +++ b/ButterCMS/Models/Post.cs @@ -19,6 +19,8 @@ public class Post public string Summary { get; set; } public string SeoTitle { get; set; } public string MetaDescription { get; set; } - public PostStatusEnum Status { get; set; } + public StatusEnum Status { get; set; } + public DateTime? Scheduled { get; set; } } } + diff --git a/ButterCMS/Models/PostStatusEnum.cs b/ButterCMS/Models/StatusEnum.cs similarity index 54% rename from ButterCMS/Models/PostStatusEnum.cs rename to ButterCMS/Models/StatusEnum.cs index e03d8df..a28bfaf 100644 --- a/ButterCMS/Models/PostStatusEnum.cs +++ b/ButterCMS/Models/StatusEnum.cs @@ -1,9 +1,11 @@ namespace ButterCMS.Models { - public enum PostStatusEnum + public enum StatusEnum { Unknown = 0, Draft = 1, - Published = 2 + Published = 2, + Scheduled = 3 } } + diff --git a/Demo/Program.cs b/Demo/Program.cs new file mode 100644 index 0000000..6ea5613 --- /dev/null +++ b/Demo/Program.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using ButterCMS; +using ButterCMS.Models; +using Newtonsoft.Json; + +public class PageFields +{ + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } +} + + +namespace ButterCMSDemo +{ + class Program + { + static void Main(string[] args) + { + var apiKey = Environment.GetEnvironmentVariable("API_KEY"); + if (string.IsNullOrEmpty(apiKey)) + { + Console.WriteLine("API_KEY environment variable is not set"); + return; + } + + var client = new ButterCMSClient(apiKey); + + try + { + Dictionary parameters = new Dictionary(); + parameters.Add("preview", "1"); + + var pageResponse = client.RetrievePage("*", "test-page-1", parameters); + var page = pageResponse.Data; + Console.WriteLine("Page retrieved successfully"); + Console.WriteLine($"Page Slug: {page.Slug}"); + Console.WriteLine($"Page Status: {page.Status}"); + Console.WriteLine($"Page Scheduled: {page.Scheduled}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error fetching page: {ex.Message}"); + } + + try + { + var postResponse = client.RetrievePost("test-blog-post"); + var post = postResponse.Data; + Console.WriteLine("Post retrieved successfully"); + Console.WriteLine($"Post Slug: {post.Slug}"); + Console.WriteLine($"Post Status: {post.Status}"); + Console.WriteLine($"Post Scheduled: {post.Scheduled}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error fetching post: {ex.Message}"); + } + } + } +} diff --git a/Demo/buttercms-demo.csproj b/Demo/buttercms-demo.csproj new file mode 100644 index 0000000..a7a550b --- /dev/null +++ b/Demo/buttercms-demo.csproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..52c1030 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Stage 1: Build C# SDK and Demo +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build + +WORKDIR /src + +# Copy the library +COPY ButterCMS/ ./ButterCMS/ + +# Copy the demo app +COPY Demo/ ./Demo/ + +WORKDIR /src/Demo +RUN dotnet restore +RUN dotnet publish -c Release -o /app/out + +# Stage 2: Run the Demo +FROM mcr.microsoft.com/dotnet/runtime:6.0 +WORKDIR /app +COPY --from=build /app/out . + +ENV API_KEY=your_api_key +ENV API_BASE_URL=https://api.buttercms.com/ + +CMD ["dotnet", "buttercms-demo.dll"] \ No newline at end of file diff --git a/README.md b/README.md index 3027f12..d17b96e 100644 --- a/README.md +++ b/README.md @@ -532,15 +532,18 @@ Layout = "~/Views/Shared/Layouts/_Layout.cshtml"; |Summary|string| |SeoTitle|string| |MetaDescription|string| -|Status|[PostStatusEnum](#poststatusenum)| +|Status|[StatusEnum](#statusenum)| +|Scheduled|DateTime| -### PostStatusEnum +### StatusEnum |Constant|Value| |---|---| |Unknown|0| |Draft|1| |Published|2| +|Scheduled|3| + ### PostResponse Class @@ -620,6 +623,8 @@ Layout = "~/Views/Shared/Layouts/_Layout.cshtml"; |Published| DateTime?| |PageType| string| |Fields|T| +|Status|[StatusEnum](#statusenum)| +|Scheduled| DateTime| ## Exceptions @@ -644,3 +649,4 @@ This exception will be thrown when the library can't fit the returned data from ### PagesObjectMismatchException This exception will be thrown when the library can't fit the returned data from a Pages request into the passed object class. +