/// <summary> /// Gets JavaScript that mobile apps need to properly display pages using Page Content Service /// </summary> /// <param name="type">Type of JavaScript bundle to fetch</param> /// <returns>DownloadableArtifact information. NULL on errors.</returns> public async Task <DownloadableArtifact> GetJavaScript(JavaScriptType type = JavaScriptType.PageLib) { StringBuilder uri = new StringBuilder(); uri.Append(ENDPOINT_BASE_URI).Append("data/javascript/mobile/") .Append(Enum.GetName(typeof(JavaScriptType), type).ToLower()); // Since we get a download, we cannot use the GET() method in the base. RestApi.RestApiClient client = new RestApi.RestApiClient(new Uri(uri.ToString())); client.RequestHeaders.Add("Accept", "text/javascript"); HttpResponseMessage responseMessage = client.Get(); if (responseMessage.IsSuccessStatusCode) { return(new DownloadableArtifact() { ContentLength = responseMessage.Content.Headers.ContentLength.Value, ContentType = responseMessage.Content.Headers.ContentType.MediaType, Stream = await responseMessage.Content.ReadAsStreamAsync() }); } return(null); }
/// <summary> /// Gets the provided page as a PDF downloadable /// </summary> /// <param name="pageName">Exact title for the page. Function will convert spaces to underscores ('_').</param> /// <param name="pageSize">Size of page to use. Defaults to Letter size.</param> /// <param name="mobileOptimized">If set, gets mobile-optimized PDF (defaults to desktop)</param> /// <returns>DownloadableArtifact information. NULL on errors.</returns> public async Task <DownloadableArtifact> GetPDF(string pageName, PageSize pageSize = PageSize.Letter, bool mobileOptimized = false) { if (string.IsNullOrWhiteSpace(pageName)) { throw new ArgumentNullException(nameof(pageName)); } if (!Enum.IsDefined(typeof(PageSize), pageSize)) { throw new ArgumentOutOfRangeException(nameof(pageSize)); } StringBuilder uri = new StringBuilder(); uri.Append(ENDPOINT_BASE_URI).Append("/page/pdf/") .Append(pageName.Replace(" ", "_")).Append("/") .Append(Enum.GetName(typeof(PageSize), pageSize).ToLower()).Append("/") .Append((mobileOptimized ? "mobile" : "desktop")); // Since we get a download, we cannot use the GET() method in the base. RestApi.RestApiClient client = new RestApi.RestApiClient(new Uri(uri.ToString())); client.RequestHeaders.Add("Accept", "application/pdf"); HttpResponseMessage responseMessage = client.Get(); if (responseMessage.IsSuccessStatusCode) { return(new DownloadableArtifact() { ContentLength = responseMessage.Content.Headers.ContentLength.Value, ContentType = responseMessage.Content.Headers.ContentType.MediaType, Stream = await responseMessage.Content.ReadAsStreamAsync() }); } return(null); }