Dave Boyle

project demos fetching single records, multiple records, filtering, and posting new records

Showing 542 changed files with 2679 additions and 0 deletions
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
# Autogenerated VS/MD solution and project files
*.csproj
*.unityproj
*.sln
*.suo
*.user
*.userprefs
*.pidb
*.booproj
#Unity3D Generated File On Crash Reports
sysinfo.txt
Build.zip
.DS_Store
bin
obj
\ No newline at end of file
using Contentful.Core;
using Contentful.Core.Configuration;
using Contentful.Core.Models;
using Contentful.Core.Search;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using UnityEngine;
using WebKit;
using Sirenix.OdinInspector;
[System.Serializable]
public class User
{
[JsonProperty("sys")]
public SystemProperties sys { get; set; }
public string firstName;
public string lastName;
public string email;
}
[System.Serializable]
public class Race
{
[JsonProperty("sys")]
public SystemProperties sys { get; set; }
public string time;
public string fuckinIdk;
}
public class DatabaseManager : MonoBehaviour
{
[FoldoutGroup("Contentful Initializer")]
[SerializeField]
private string _spaceId, _deliveryToken, _managementToken;
private ContentfulClient _client;
private ContentfulManagementClient _mClient;
void Start()
{
ContentfulOptions options = new ContentfulOptions()
{
ManagementApiKey = _managementToken,
DeliveryApiKey = _deliveryToken,
SpaceId = _spaceId
};
_client = new ContentfulClient(new HttpClient(), options);
_mClient = new ContentfulManagementClient(new HttpClient(), options);
}
#region GetSingle
[FoldoutGroup("Get Single User")]
[Button("Get Just Dave")]
public void FetchUser()
{
StartCoroutine(GetSpecificUserCoroutine("dave@globacore.com"));
}
private IEnumerator GetSpecificUserCoroutine(string email)
{
var query = new QueryBuilder<User>().ContentTypeIs("user").FieldEquals(userLambda => userLambda.email, email);
var fetchUserRequest = _client.GetEntries(query);
while (!fetchUserRequest.IsCompleted) yield return null;
fetchedUser = fetchUserRequest.Result.First();
}
[FoldoutGroup("Get Single User")]
[SerializeField]
private User fetchedUser;
#endregion
#region GetAll
[FoldoutGroup("Get All Users")]
[Button("Get All Users As List")]
public void GetAllUsers()
{
StartCoroutine(GetAllUserCoroutine());
}
private IEnumerator GetAllUserCoroutine()
{
var query = new QueryBuilder<User>().ContentTypeIs("user");
var fetchUsersRequest = _client.GetEntries(query);
while (!fetchUsersRequest.IsCompleted) yield return null;
allUsers = fetchUsersRequest.Result.ToList();
}
[FoldoutGroup("Get All Users")]
[SerializeField]
private List<User> allUsers;
#endregion
#region Create
[FoldoutGroup("Create New User")]
[SerializeField]
public User userToCreate = new User();
[FoldoutGroup("Create New User")]
[Button("Create User")]
public void CreateUser()
{
StartCoroutine(CreateUserCoroutine());
}
private IEnumerator CreateUserCoroutine()
{
var userEntry = new Entry<dynamic>();
userEntry.SystemProperties = new SystemProperties();
userEntry.SystemProperties.Id = "User";
userEntry.Fields = new
{
firstName = new Dictionary<string, string>()
{
{"en-US", userToCreate.firstName }
},
lastName = new Dictionary<string, string>()
{
{"en-US", userToCreate.lastName }
},
email = new Dictionary<string, string>()
{
{"en-US", userToCreate.email }
},
};
var createEntry = _mClient.CreateEntry(userEntry, "user");
while (!createEntry.IsCompleted) yield return null;
var createdEntry = createEntry.Result;
var publishEntry = _mClient.PublishEntry(createdEntry.SystemProperties.Id, 1);
while (!publishEntry.IsCompleted) yield return null;
print("dun did it");
}
#endregion
}
fileFormatVersion: 2
guid: 65d4e3a03ccf21d4883fe8222eb91969
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d3001a2d20c6b1e428a7de02b006a359
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 3346c73979bee184693caf6a30fb1761
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## Version [1.2.0]
- Adds method `CreateEntryForLocaleAsync` to the management client.
## Version [1.1.1]
- Adds missing properties for the `SystemProperties` object.
## Version [1.1.0]
- Adds convenience methods to `ContentfulManagementClient` for retrieveing, creating and updating entries without having to use `Entry<dynamic>`.
## Version [1.0.0]
- Initial stable release on NetStandard 2.0
\ No newline at end of file
fileFormatVersion: 2
guid: 5a38711534e97ba4ea583934bb102074
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
We appreciate any community contributions to this project, whether in the form of issues or Pull Requests.
This document outlines what we'd like you to follow in terms of commit messages and code style.
It also explains what to do in case you want to setup the project locally and run tests.
# Setup
This project is written using Visual Studio 2017 RC and the latest dotnet core SDKs. Clone the repository, run `dotnet restore`
and then `dotnet build` to compile.
# Code style
This project uses Microsoft standard code styles. They can be found in the `editorstyles.config` file. Read more at [editorconfig.org](http://EditorConfig.org)
# Running tests
To run the tests for this solution, either start the runner from within visual studio or run `dotnet test` in the test project directories.
fileFormatVersion: 2
guid: e52fa0c9828aa2a4da91c9d3724aef30
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 879b9410b271a044792eed618d52d937
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: c9d16f2f9d8374c4db1d19a0f0e3c395
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Contentful.Core.Configuration
{
/// <summary>
/// JsonConverter for converting Contentful assets into a simpler <see cref="Asset"/> structure.
/// </summary>
public class AssetJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">The type to convert to.</param>
public override bool CanConvert(Type objectType) => objectType == typeof(Asset);
/// <summary>
/// Gets a value indicating whether this JsonConverter can write JSON.
/// </summary>
public override bool CanWrite => false;
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The reader to use.</param>
/// <param name="objectType">The object type to serialize into.</param>
/// <param name="existingValue">The current value of the property.</param>
/// <param name="serializer">The serializer to use.</param>
/// <returns>The deserialized <see cref="Asset"/>.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) {
return null;
}
var asset = new Asset();
var jObject = JObject.Load(reader);
JToken refId;
if (jObject.TryGetValue("$ref", out refId))
{
return serializer.ReferenceResolver.ResolveReference(serializer, ((JValue) refId).Value.ToString());
}
asset.SystemProperties = jObject.SelectToken("$.sys")?.ToObject<SystemProperties>();
if (!string.IsNullOrEmpty(asset.SystemProperties.Locale))
{
asset.Title = jObject.SelectToken("$.fields.title")?.ToString();
asset.TitleLocalized = new Dictionary<string, string>();
asset.TitleLocalized.Add(asset.SystemProperties.Locale, asset.Title);
asset.Description = jObject.SelectToken("$.fields.description")?.ToString();
asset.DescriptionLocalized = new Dictionary<string, string>();
asset.DescriptionLocalized.Add(asset.SystemProperties.Locale, asset.Description);
asset.File = jObject.SelectToken("$.fields.file")?.ToObject<File>();
asset.FilesLocalized = new Dictionary<string, File>();
asset.FilesLocalized.Add(asset.SystemProperties.Locale, asset.File);
}
else
{
asset.TitleLocalized = jObject.SelectToken("$.fields.title")?.ToObject<Dictionary<string, string>>();
asset.DescriptionLocalized = jObject.SelectToken("$.fields.description")?.ToObject<Dictionary<string, string>>();
asset.FilesLocalized = jObject.SelectToken("$.fields.file")?.ToObject<Dictionary<string, File>>();
}
if (!serializer.ReferenceResolver.IsReferenced(serializer, asset))
{
serializer.ReferenceResolver.AddReference(serializer, asset.SystemProperties.Id, asset);
}
return asset;
}
/// <summary>
/// Writes the JSON representation of the object.
/// **NOTE: This method is not implemented and will throw an exception.**
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}
fileFormatVersion: 2
guid: f1f31d1e1ab0d9948887d7cdb5bdbe6f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Models;
using Contentful.Core.Models.Management;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Contentful.Core.Configuration
{
/// <summary>
/// JsonConverter for converting <see cref="Contentful.Core.Models.Management.IConstraint"/>.
/// </summary>
public class ConstraintJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">The type to convert to.</param>
public override bool CanConvert(Type objectType) => objectType == typeof(IConstraint);
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The reader to use.</param>
/// <param name="objectType">The object type to serialize into.</param>
/// <param name="existingValue">The current value of the property.</param>
/// <param name="serializer">The serializer to use.</param>
/// <returns>The deserialized <see cref="Asset"/>.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
var jObject = JObject.Load(reader);
return ConvertJsonToConstraint(jObject);
}
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var constraint = value as IConstraint;
if (constraint == null)
return;
serializer.Serialize(writer, ConvertConstraintToDynamic(constraint));
}
private IConstraint ConvertJsonToConstraint(JObject jObject)
{
if (jObject["and"] != null)
{
var andConstraint = new AndConstraint();
foreach(var item in jObject["and"])
{
andConstraint.Add(ConvertJsonToConstraint((item as JObject)));
}
return andConstraint;
}
if(jObject["or"] != null)
{
var orConstraint = new OrConstraint();
foreach (var item in jObject["or"])
{
orConstraint.Add(ConvertJsonToConstraint((item as JObject)));
}
return orConstraint;
}
if(jObject["equals"] != null)
{
var equalsConstraint = new EqualsConstraint();
equalsConstraint.Property = jObject["equals"][0]["doc"]?.ToString();
equalsConstraint.ValueToEqual = jObject["equals"][1]?.ToString();
return equalsConstraint;
}
if(jObject["paths"] != null)
{
var pathsConstraint = new PathConstraint();
pathsConstraint.Fields = jObject["paths"][0]["doc"]?.ToString();
return pathsConstraint;
}
if (jObject["not"] != null)
{
var notConstraint = new NotConstraint();
notConstraint.ConstraintToInvert = ConvertJsonToConstraint(jObject["not"] as JObject);
return notConstraint;
}
return null;
}
private dynamic ConvertConstraintToDynamic(IConstraint constraint)
{
if (constraint is AndConstraint)
{
return new { and = (constraint as AndConstraint).Select(c => ConvertConstraintToDynamic(c)) };
}
if(constraint is OrConstraint)
{
return new { or = (constraint as AndConstraint).Select(c => ConvertConstraintToDynamic(c)) };
}
if(constraint is EqualsConstraint)
{
return new { equals = new dynamic[] { new { doc = (constraint as EqualsConstraint).Property }, (constraint as EqualsConstraint).ValueToEqual } };
}
if(constraint is NotConstraint)
{
return new { not = ConvertConstraintToDynamic((constraint as NotConstraint).ConstraintToInvert) };
}
if (constraint is PathConstraint)
{
return new { paths = new dynamic[] { new { doc = (constraint as PathConstraint).Fields } } };
}
return null;
}
}
}
fileFormatVersion: 2
guid: 6a84520552e6eee49bd6869913656905
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Contentful.Core.Errors;
namespace Contentful.Core.Configuration
{
/// <summary>
/// Represents a set of options to configure a <see cref="ContentfulClient"/>.
/// </summary>
public class ContentfulOptions
{
/// <summary>
/// The api key used when communicating with the Contentful delivery API.
/// </summary>
public string DeliveryApiKey { get; set; }
/// <summary>
/// The api key used when communicating with the Contentful preview API.
/// <remarks>
/// To use the preview API the <see cref="UsePreviewApi"/> property must be set to true.
/// </remarks>
/// </summary>
public string PreviewApiKey { get; set; }
/// <summary>
/// The api key used when communicating with the Contentful management API.
/// </summary>
public string ManagementApiKey { get; set; }
/// <summary>
/// The ID of the space that you wish to get or manipulate content for.
/// </summary>
public string SpaceId { get; set; }
/// <summary>
/// Whether or not to use the Preview API for requests.
/// If this is set to true the preview API key needs to be used for <see cref="DeliveryApiKey"/>.
/// </summary>
public bool UsePreviewApi { get; set; }
/// <summary>
/// If set the client will evaluate the class to serialize into and only serialize the parts that are part of the class structure.
/// </summary>
public bool ResolveEntriesSelectively { get; set; }
/// <summary>
/// Sets the default number of times to retry after hitting a <see cref="Contentful.Core.Errors.ContentfulRateLimitException"/>.
/// 0 means that no retries will be made. Maximum is 10.
/// </summary>
public int MaxNumberOfRateLimitRetries { get; set; }
}
}
fileFormatVersion: 2
guid: a36d68d318f07b04995cae8a4285d198
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Models;
using Contentful.Core.Models.Management;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Configuration
{
/// <summary>
/// JsonConverter for converting <see cref="Contentful.Core.Models.Management.EditorInterface"/>.
/// </summary>
public class EditorInterfaceControlJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">The type to convert to.</param>
public override bool CanConvert(Type objectType) => objectType == typeof(EditorInterfaceControl);
/// <summary>
/// Gets a value indicating whether this JsonConverter can write JSON.
/// </summary>
public override bool CanWrite => false;
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The reader to use.</param>
/// <param name="objectType">The object type to serialize into.</param>
/// <param name="existingValue">The current value of the property.</param>
/// <param name="serializer">The serializer to use.</param>
/// <returns>The deserialized <see cref="Asset"/>.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
return null;
var jsonObject = JObject.Load(reader);
var settings = new EditorInterfaceControlSettings();
var editorInterfaceControl = new EditorInterfaceControl()
{
FieldId = jsonObject["fieldId"]?.ToString(),
WidgetId = jsonObject["widgetId"]?.ToString()
};
if (jsonObject["settings"] == null)
{
return editorInterfaceControl;
}
if (jsonObject["widgetId"]?.ToString() == "boolean")
{
var boolSettings = new BooleanEditorInterfaceControlSettings()
{
FalseLabel = jsonObject["settings"]?["falseLabel"]?.ToString(),
TrueLabel = jsonObject["settings"]?["trueLabel"]?.ToString()
};
settings = boolSettings;
}
if (jsonObject["widgetId"]?.ToString() == "rating")
{
var ratingSettings = new RatingEditorInterfaceControlSettings();
var stars = 0;
if (!int.TryParse(jsonObject["settings"]?["stars"]?.ToString(), out stars))
{
stars = 5;
}
ratingSettings.NumberOfStars = stars;
settings = ratingSettings;
}
if (jsonObject["widgetId"]?.ToString() == "datePicker")
{
var dateSettings = new DatePickerEditorInterfaceControlSettings()
{
ClockFormat = jsonObject["settings"]?["ampm"]?.ToString(),
DateFormat = (EditorInterfaceDateFormat)Enum.Parse(typeof(EditorInterfaceDateFormat), jsonObject["settings"]?["format"]?.ToString(), true)
};
settings = dateSettings;
}
settings.HelpText = jsonObject["settings"]?["helpText"]?.ToString();
editorInterfaceControl.Settings = settings;
return editorInterfaceControl;
}
/// <summary>
/// Writes the JSON representation of the object.
/// **NOTE: This method is not implemented and will throw an exception.**
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}
fileFormatVersion: 2
guid: e1173e2743f4d9346914bdf1854d325c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Models;
using Contentful.Core.Models.Management;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Contentful.Core.Configuration
{
/// <summary>
/// JsonConverter for converting <see cref="Contentful.Core.Models.Management.UiExtension"/>.
/// </summary>
public class ExtensionJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">The type to convert to.</param>
public override bool CanConvert(Type objectType) => objectType == typeof(UiExtension);
/// <summary>
/// Gets a value indicating whether this JsonConverter can write JSON.
/// </summary>
public override bool CanWrite => true;
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The reader to use.</param>
/// <param name="objectType">The object type to serialize into.</param>
/// <param name="existingValue">The current value of the property.</param>
/// <param name="serializer">The serializer to use.</param>
/// <returns>The deserialized <see cref="Asset"/>.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
var jObject = JObject.Load(reader);
var extensionProperties = jObject.SelectToken("$.extension");
var extension = new UiExtension();
extension.SystemProperties = jObject["sys"].ToObject<SystemProperties>();
extension.Src = extensionProperties["src"]?.ToString();
extension.Name = extensionProperties["name"]?.ToString();
extension.Sidebar = extensionProperties["sidebar"]?.Value<bool>() ?? false;
extension.FieldTypes = extensionProperties["fieldTypes"]?.Values<dynamic>()?.Select(c => c.type.ToString())?.Cast<string>().ToList();
extension.SrcDoc = extensionProperties["srcDoc"]?.ToString();
return extension;
}
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var extension = value as UiExtension;
if (extension == null)
{
return;
}
serializer.Serialize(writer,
new {
sys = extension.SystemProperties,
extension = new {
src = extension.Src,
name = extension.Name,
fieldTypes = extension.FieldTypes,
srcDoc = extension.SrcDoc,
sidebar = extension.Sidebar } });
}
}
}
fileFormatVersion: 2
guid: a8aeab2d5c797d548acbf53ab320d686
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Configuration
{
/// <summary>
/// An interface for a contenttype resolver to allow resolving contenttypes to concrete CLR types.
/// </summary>
public interface IContentTypeResolver
{
/// <summary>
/// Resolves a content type id to a concrete type.
/// </summary>
/// <param name="contentTypeId">The contenttype id to resolve.</param>
/// <returns>The type for the provided contenttype id.</returns>
Type Resolve(string contentTypeId);
}
}
fileFormatVersion: 2
guid: 2968a213a3166da4db7aea7e564e4204
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Models;
using Contentful.Core.Models.Management;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Configuration
{
/// <summary>
/// JsonConverter for converting <see cref="Contentful.Core.Models.Management.ManagementAsset"/>.
/// </summary>
public class ManagementAssetJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">The type to convert to.</param>
public override bool CanConvert(Type objectType) => objectType == typeof(ManagementAsset);
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The reader to use.</param>
/// <param name="objectType">The object type to serialize into.</param>
/// <param name="existingValue">The current value of the property.</param>
/// <param name="serializer">The serializer to use.</param>
/// <returns>The deserialized <see cref="Asset"/>.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
var asset = new ManagementAsset();
var jObject = JObject.Load(reader);
asset.Title = jObject.SelectToken("$.fields.title")?.ToObject<Dictionary<string, string>>();
asset.Description = jObject.SelectToken("$.fields.description")?.ToObject<Dictionary<string, string>>();
asset.Files = jObject.SelectToken("$.fields.file")?.ToObject<Dictionary<string, File>>();
asset.SystemProperties = jObject.SelectToken("$.sys")?.ToObject<SystemProperties>();
return asset;
}
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value == null)
return;
var asset = value as ManagementAsset;
serializer.Serialize(writer, new { sys = asset.SystemProperties,
fields = new { title = asset.Title, description = asset.Description, file = asset.Files } });
}
}
}
fileFormatVersion: 2
guid: c21f126aa37a31f4ab06c2c185877aa2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Models;
using Contentful.Core.Models.Management;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Configuration
{
/// <summary>
/// JsonConverter for converting <see cref="Contentful.Core.Models.Management.Snapshot"/>.
/// </summary>
public class SnapshotJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">The type to convert to.</param>
public override bool CanConvert(Type objectType) => objectType == typeof(Snapshot);
/// <summary>
/// Gets a value indicating whether this JsonConverter can write JSON.
/// </summary>
public override bool CanWrite => false;
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The reader to use.</param>
/// <param name="objectType">The object type to serialize into.</param>
/// <param name="existingValue">The current value of the property.</param>
/// <param name="serializer">The serializer to use.</param>
/// <returns>The deserialized <see cref="Asset"/>.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
var jObject = JObject.Load(reader);
var fields = jObject.SelectToken("$.snapshot.fields");
var snapshot = new Snapshot();
snapshot.SystemProperties = jObject["sys"].ToObject<SystemProperties>();
snapshot.Fields = fields.ToObject<Dictionary<string, Dictionary<string, dynamic>>>();
return snapshot;
}
/// <summary>
/// Writes the JSON representation of the object.
/// **NOTE: This method is not implemented and will throw an exception.**
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}
fileFormatVersion: 2
guid: cc9f5ae8ec6083d4c90dd90f27c77922
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Models;
using Contentful.Core.Models.Management;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Contentful.Core.Configuration
{
/// <summary>
/// JsonConverter for converting <see cref="Contentful.Core.Models.Management.SpaceMembership"/>.
/// </summary>
public class SpaceMembershipJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">The type to convert to.</param>
public override bool CanConvert(Type objectType) => objectType == typeof(SpaceMembership);
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The reader to use.</param>
/// <param name="objectType">The object type to serialize into.</param>
/// <param name="existingValue">The current value of the property.</param>
/// <param name="serializer">The serializer to use.</param>
/// <returns>The deserialized <see cref="Asset"/>.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
var jObject = JObject.Load(reader);
var spaceMembership = new SpaceMembership();
spaceMembership.SystemProperties = jObject["sys"]?.ToObject<SystemProperties>();
spaceMembership.Admin = jObject.Value<bool>("admin");
spaceMembership.Roles = jObject.SelectTokens("$.roles..id")?.Values<string>().ToList();
return spaceMembership;
}
/// <summary>
/// Writes the JSON representation of the object.
/// **NOTE: This method is not implemented and will throw an exception.**
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var spaceMembership = value as SpaceMembership;
if(spaceMembership == null)
{
return;
}
var jArray = new JArray();
if (spaceMembership.Roles != null)
{
foreach (var role in spaceMembership.Roles)
{
jArray.Add(new JObject(
new JProperty("type", "Link"),
new JProperty("linkType", "Role"),
new JProperty("id", role.ToString())
));
}
}
var jObject = new JObject(
new JProperty("admin", spaceMembership.Admin),
new JProperty("roles", jArray)
);
jObject.WriteTo(writer);
}
}
}
fileFormatVersion: 2
guid: 3785bde35e22fe6478075983bb36297a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Configuration
{
/// <summary>
/// JsonConverter to convert a list of string to a Contentful representation.
/// </summary>
public class StringAllToListJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">The type to convert to.</param>
public override bool CanConvert(Type objectType) => objectType == typeof(List<string>);
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The reader to use.</param>
/// <param name="objectType">The object type to serialize into.</param>
/// <param name="existingValue">The current value of the property.</param>
/// <param name="serializer">The serializer to use.</param>
/// <returns>The deserialized <see cref="Asset"/>.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
var jToken = JToken.Load(reader);
if ((jToken.Type == JTokenType.String) && jToken.ToString() == "all")
{
return new List<string>()
{
"all"
};
}
return new List<string>((jToken as JArray).Values<string>());
}
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var list = value as List<string>;
if(list == null)
{
return;
}
JToken token = JToken.FromObject(value);
if (list.Count == 1 && list[0] == "all")
{
writer.WriteValue("all");
}else
{
token.WriteTo(writer);
}
}
}
}
fileFormatVersion: 2
guid: b4570c77eee030444b86920b99fc64de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Extensions;
using Contentful.Core.Models;
using Contentful.Core.Models.Management;
using Contentful.Core.Search;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Contentful.Core.Configuration
{
/// <summary>
/// JsonConverter for converting <see cref="Contentful.Core.Models.Management.IFieldValidator"/>.
/// </summary>
public class ValidationsJsonConverter : JsonConverter
{
/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">The type to convert to.</param>
public override bool CanConvert(Type objectType)
{
return objectType is IFieldValidator;
}
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The reader to use.</param>
/// <param name="objectType">The object type to serialize into.</param>
/// <param name="existingValue">The current value of the property.</param>
/// <param name="serializer">The serializer to use.</param>
/// <returns>The deserialized <see cref="Asset"/>.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var jsonObject = JObject.Load(reader);
JToken jToken = null;
if (jsonObject.TryGetValue("size", out jToken))
{
return new SizeValidator(
jToken["min"].ToNullableInt(),
jToken["max"].ToNullableInt(),
jsonObject["message"]?.ToString());
}
if (jsonObject.TryGetValue("range", out jToken))
{
return new RangeValidator(
jToken["min"].ToNullableInt(),
jToken["max"].ToNullableInt(),
jsonObject["message"]?.ToString());
}
if (jsonObject.TryGetValue("in", out jToken))
{
return new InValuesValidator(jToken.Values<string>(), jsonObject["message"]?.ToString());
}
if (jsonObject.TryGetValue("linkMimetypeGroup", out jToken))
{
if(jToken is JValue)
{
//single string value returned for mime type field. This seems to be an inconsistency in the API that needs to be handled.
var type = jToken.Value<string>();
return new MimeTypeValidator(new[] { (MimeTypeRestriction)Enum.Parse(typeof(MimeTypeRestriction), type, true) },
jsonObject["message"]?.ToString());
}
var types = jToken.Values<string>();
return new MimeTypeValidator(types.Select(c => (MimeTypeRestriction)Enum.Parse(typeof(MimeTypeRestriction), c, true)),
jsonObject["message"]?.ToString());
}
if (jsonObject.TryGetValue("linkContentType", out jToken))
{
return new LinkContentTypeValidator(jToken.Values<string>(), jsonObject["message"]?.ToString());
}
if (jsonObject.TryGetValue("regexp", out jToken))
{
return new RegexValidator(jToken["pattern"]?.ToString(), jToken["flags"]?.ToString(), jsonObject["message"]?.ToString());
}
if (jsonObject.TryGetValue("unique", out jToken))
{
return new UniqueValidator();
}
if (jsonObject.TryGetValue("dateRange", out jToken))
{
return new DateRangeValidator(
jToken["min"]?.ToString(),
jToken["max"]?.ToString(),
jsonObject["message"]?.ToString());
}
if (jsonObject.TryGetValue("assetFileSize", out jToken))
{
return new FileSizeValidator(
jToken["min"].ToNullableInt(),
jToken["max"].ToNullableInt(),
SystemFileSizeUnits.Bytes,
SystemFileSizeUnits.Bytes,
jsonObject["message"]?.ToString());
}
if (jsonObject.TryGetValue("assetImageDimensions", out jToken))
{
int? minWidth = null;
int? maxWidth = null;
int? minHeight = null;
int? maxHeight = null;
if (jToken["width"] != null)
{
var width = jToken["width"];
minWidth = width["min"].ToNullableInt();
maxWidth = width["max"].ToNullableInt();
}
if (jToken["height"] != null)
{
var height = jToken["height"];
minHeight = height["min"].ToNullableInt();
maxHeight = height["max"].ToNullableInt();
}
return new ImageSizeValidator(minWidth, maxWidth, minHeight, maxHeight, jsonObject["message"]?.ToString());
}
return Activator.CreateInstance(objectType);
}
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, (value as IFieldValidator).CreateValidator());
}
}
}
fileFormatVersion: 2
guid: bda39ee26dd18d0429006a7a12fc1491
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: c68faacb9f3bc514cb38adb5ee511d61
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f4fdb0c5ae37b3f40a18b161d939976e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b55a9724fbe697042beaff53a020d957
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b9d00fe738eec3a44a5d30c0bc86dbb6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Contentful.Core.Models;
namespace Contentful.Core.Errors
{
/// <summary>
/// Represents errors that occurr when calling the Contentful APIs.
/// </summary>
public class ContentfulException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="ContentfulException"/> class.
/// </summary>
/// <param name="statusCode">The http status code of the exception.</param>
/// <param name="message">The message of the exception.</param>
public ContentfulException(int statusCode, string message) : base(message)
{
StatusCode = statusCode;
}
/// <summary>
/// The http status code of the exception.
/// </summary>
public int StatusCode { get; set; }
/// <summary>
/// Common system managed metadata properties.
/// </summary>
public SystemProperties SystemProperties { get; set; }
/// <summary>
/// The details of the exception.
/// </summary>
public ErrorDetails ErrorDetails { get; set; }
/// <summary>
/// The ID of the request to the Contentful API.
/// </summary>
public string RequestId { get; set; }
}
}
fileFormatVersion: 2
guid: b42e2aa282b19d445a9cef53ae0425bf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Errors
{
/// <summary>
/// Represents errors that occurr when a call hit the rate limit of the API.
/// </summary>
public class ContentfulRateLimitException : ContentfulException
{
/// <summary>
/// Initializes a new instance of <see cref="Contentful.Core.Errors.ContentfulRateLimitException"/>.
/// </summary>
/// <param name="message">The message of the exception.</param>
public ContentfulRateLimitException(string message) : base(429, message)
{
}
/// <summary>
/// The number of seconds until the next request can be made to the API.
/// </summary>
public int SecondsUntilNextRequest { get; set; }
}
}
fileFormatVersion: 2
guid: 074e9c573be89214fbe02f4c438eb862
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Contentful.Core.Errors
{
/// <summary>
/// Represents detailed information about a <see cref="ContentfulException"/>
/// </summary>
public class ErrorDetails
{
/// <summary>
/// The dynamic representation of errors returned from the API.
/// </summary>
public dynamic Errors { get; set; }
}
}
fileFormatVersion: 2
guid: 25f4b12592bdef8489bcbaccc8cffc15
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 30f0d70760bb57d40aed3770afa5c3a5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Extensions
{
/// <summary>
/// Extensionmethods for JToken
/// </summary>
public static class JTokenExtensions
{
/// <summary>
/// Checks whether a JToken is null or of null type.
/// </summary>
/// <param name="token">The token to validate.</param>
/// <returns>Whether the token is null or not.</returns>
public static bool IsNull(this JToken token)
{
return token == null || token.Type == JTokenType.Null;
}
/// <summary>
/// Returns an int value from a JToken.
/// </summary>
/// <param name="token">The token to retrieve a value from.</param>
/// <returns>The int value.</returns>
public static int ToInt(this JToken token)
{
if (token.IsNull())
{
return 0;
}
return int.Parse(token.ToString());
}
/// <summary>
/// Returns a nullable int value from a JToken.
/// </summary>
/// <param name="token">The token to retrieve a value from.</param>
/// <returns>The nullable int value.</returns>
public static int? ToNullableInt(this JToken token)
{
if (token.IsNull())
{
return new int?();
}
return new int?(token.ToInt());
}
}
}
fileFormatVersion: 2
guid: 32dd31e007179e942b0c3f22cd222c63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ae858612cfb0f6240a10b47b7d097d5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 5084e085ca0d6da47b995578ebf3a535
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7f20d4cc169002a4caa0f7e9b7a5f6cf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Images
{
/// <summary>
/// Represents the different kinds of areas to focus an image on when using the <see cref="ImageResizeBehaviour.Thumb"/>.
/// </summary>
public enum ImageFocusArea
{
/// <summary>
/// Center of image.
/// </summary>
Default,
/// <summary>
/// Top of the image.
/// </summary>
Top,
/// <summary>
/// Right side of the image.
/// </summary>
Right,
/// <summary>
/// Left side of the image.
/// </summary>
Left,
/// <summary>
/// Bottom side of the image.
/// </summary>
Bottom,
/// <summary>
/// Top right of the image.
/// </summary>
Top_Right,
/// <summary>
/// Top left of the image.
/// </summary>
Top_Left,
/// <summary>
/// Bottom right of the image.
/// </summary>
Bottom_Right,
/// <summary>
/// Bottom left of the image.
/// </summary>
Bottom_Left,
/// <summary>
/// Focuses on a face of an image using face detection.
/// </summary>
Face,
/// <summary>
/// Focuses on multiple faces of an image using face detection.
/// </summary>
Faces
}
}
fileFormatVersion: 2
guid: de655b35d030910459281b8ce8aed523
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Images
{
/// <summary>
/// An enumeration representing the different kind of image formats available for images in Contentful.
/// </summary>
public enum ImageFormat
{
/// <summary>
/// Keeps the original image format.
/// </summary>
Default,
/// <summary>
/// Turns the image into a JPG.
/// </summary>
Jpg,
/// <summary>
/// Turns the image into a PNG.
/// </summary>
Png,
/// <summary>
/// Turns the image into a WEBP.
/// </summary>
Webp
}
}
fileFormatVersion: 2
guid: 2662a8a0765cc5b4286b7da3d22041ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Images
{
/// <summary>
/// Represents the different kinds of resizing behaviours for images available.
/// </summary>
public enum ImageResizeBehaviour
{
/// <summary>
/// Resizes the image to fit within the bounding box specified by the width and height parameters, while maintaining aspect ratio.
/// </summary>
Default,
/// <summary>
/// Pads the image so that the resulting image has the exact size of the width and height parameters.
/// </summary>
Pad,
/// <summary>
/// Crops the image to match the specified size.
/// </summary>
Crop,
/// <summary>
/// Crops the image to match the specified size, if the original image is smaller it will be upscaled.
/// </summary>
Fill,
/// <summary>
/// Creates a thumbnail from an image based on a focus area.
/// </summary>
Thumb,
/// <summary>
/// Scale the image regardless of original aspect ratio.
/// </summary>
Scale
}
}
fileFormatVersion: 2
guid: 816302f26fda4724a9d18a9c78a7c92d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Images
{
/// <summary>
/// Utility builder class to construct a correct image manipulation query string for a Contentful image.
/// </summary>
public class ImageUrlBuilder
{
private readonly List<KeyValuePair<string, string>> _querystringValues = new List<KeyValuePair<string, string>>();
/// <summary>
/// Creates a new instance of an ImageUrlBuilder.
/// </summary>
/// <returns>The created <see cref="ImageUrlBuilder"/>.</returns>
public static ImageUrlBuilder New()
{
return new ImageUrlBuilder();
}
/// <summary>
/// Sets the format of the image returned.
/// </summary>
/// <param name="format">The <see cref="ImageFormat"/> of the image returned.</param>
/// <returns>The <see cref="ImageUrlBuilder"/> instance.</returns>
public ImageUrlBuilder SetFormat(ImageFormat format)
{
if(format == ImageFormat.Default)
{
return this;
}
_querystringValues.Add(new KeyValuePair<string, string>("fm", format.ToString().ToLower()));
return this;
}
/// <summary>
/// Sets the quality of the jpg image returned.
/// </summary>
/// <param name="quality">The quality as a percentage between 0 and 100.</param>
/// <returns>The <see cref="ImageUrlBuilder"/> instance.</returns>
public ImageUrlBuilder SetJpgQuality(int quality)
{
_querystringValues.Add(new KeyValuePair<string, string>("q", quality.ToString()));
return this;
}
/// <summary>
/// Sets the returned jpg to be progressive.
/// </summary>
/// <returns>The <see cref="ImageUrlBuilder"/> instance.</returns>
public ImageUrlBuilder UseProgressiveJpg()
{
_querystringValues.Add(new KeyValuePair<string, string>("fl", "progressive"));
return this;
}
/// <summary>
/// Sets the width of the returned image.
/// </summary>
/// <param name="width">The width of the image.</param>
/// <returns>The <see cref="ImageUrlBuilder"/> instance.</returns>
public ImageUrlBuilder SetWidth(int width)
{
_querystringValues.Add(new KeyValuePair<string, string>("w", width.ToString()));
return this;
}
/// <summary>
/// Sets the height of the returned image.
/// </summary>
/// <param name="height">The height of the image.</param>
/// <returns>The <see cref="ImageUrlBuilder"/> instance.</returns>
public ImageUrlBuilder SetHeight(int height)
{
_querystringValues.Add(new KeyValuePair<string, string>("h", height.ToString()));
return this;
}
/// <summary>
/// Sets how an image should be resized to fit inside the height and width specified.
/// </summary>
/// <param name="resizeBehaviour">The resizebehaviour.</param>
/// <returns>The <see cref="ImageUrlBuilder"/> instance.</returns>
public ImageUrlBuilder SetResizingBehaviour(ImageResizeBehaviour resizeBehaviour)
{
if(resizeBehaviour == ImageResizeBehaviour.Default)
{
return this;
}
_querystringValues.Add(new KeyValuePair<string, string>("fit", resizeBehaviour.ToString().ToLower()));
return this;
}
/// <summary>
/// Sets what focus area should be used when resizing.
/// </summary>
/// <param name="focusArea">The area to focus the image on.</param>
/// <returns>The <see cref="ImageUrlBuilder"/> instance.</returns>
public ImageUrlBuilder SetFocusArea(ImageFocusArea focusArea)
{
if(focusArea == ImageFocusArea.Default)
{
return this;
}
_querystringValues.Add(new KeyValuePair<string, string>("f", focusArea.ToString().ToLower()));
return this;
}
/// <summary>
/// Set the corner radius of the image.
/// </summary>
/// <param name="radius">The radius to set.</param>
/// <returns>The <see cref="ImageUrlBuilder"/> instance.</returns>
public ImageUrlBuilder SetCornerRadius(int radius)
{
_querystringValues.Add(new KeyValuePair<string, string>("r", radius.ToString()));
return this;
}
/// <summary>
/// Sets the background color when using <see cref="ImageResizeBehaviour.Pad"/> or <see cref="SetCornerRadius"/>.
/// </summary>
/// <param name="rgbColor">The background color in RGB format, starts with "rgb:" or "#" e.g. rgb:000080 or #000080.</param>
/// <returns></returns>
public ImageUrlBuilder SetBackgroundColor(string rgbColor)
{
if (string.IsNullOrEmpty(rgbColor))
{
return this;
}
if (rgbColor.StartsWith("#"))
{
rgbColor = "rgb:" + rgbColor.Substring(1);
}
_querystringValues.Add(new KeyValuePair<string, string>("bg", rgbColor));
return this;
}
/// <summary>
/// Builds the query and returns the formatted querystring.
/// </summary>
/// <returns>The formatted querystring.</returns>
public string Build()
{
var sb = new StringBuilder();
var hasQuery = false;
foreach (var parameter in _querystringValues)
{
sb.Append(hasQuery ? '&' : '?');
sb.Append(parameter.Key);
sb.Append('=');
sb.Append(parameter.Value);
hasQuery = true;
}
return sb.ToString();
}
}
}
fileFormatVersion: 2
guid: a38d3be09f7a1e24da4131bc50a29ac8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: be4cd388102194240aca6ad3bf1e08bc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents a single asset of a <see cref="Space"/>.
/// </summary>
public class Asset : IContentfulResource
{
/// <summary>
/// Common system managed metadata properties.
/// </summary>
[JsonProperty("sys")]
public SystemProperties SystemProperties { get; set; }
/// <summary>
/// The description of the asset.
/// </summary>
public string Description { get; set; }
/// <summary>
/// The title of the asset.
/// </summary>
public string Title { get; set; }
/// <summary>
/// Encapsulates information about the binary file of the asset.
/// </summary>
public File File { get; set; }
/// <summary>
/// The titles of the asset per locale.
/// </summary>
public Dictionary<string, string> TitleLocalized { get; set; }
/// <summary>
/// The descriptions of the asset per locale.
/// </summary>
public Dictionary<string, string> DescriptionLocalized { get; set; }
/// <summary>
/// Information about the file in respective language.
/// </summary>
public Dictionary<string, File> FilesLocalized { get; set; }
}
}
fileFormatVersion: 2
guid: 356c9efa84752f4429a55ba24af206ae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents a single content type.
/// </summary>
public class ContentType : IContentfulResource
{
/// <summary>
/// Common system managed metadata properties.
/// </summary>
[JsonProperty("sys")]
public SystemProperties SystemProperties { get; set; }
/// <summary>
/// The name of the content type.
/// </summary>
public string Name { get; set; }
/// <summary>
/// The description of the content type.
/// </summary>
public string Description { get; set; }
/// <summary>
/// The ID of the main field used for display.
/// </summary>
public string DisplayField { get; set; }
/// <summary>
/// List of <seealso cref="Field"/> this content type contains.
/// </summary>
public List<Field> Fields { get; set; }
}
}
fileFormatVersion: 2
guid: bdd2eea2c8af55f4a8058316967bf2a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents a collection of contentful resources with additional medadata regarding, skip, limit and total amount of items.
/// </summary>
/// <typeparam name="T">The type to serialize the items array from the API response into.</typeparam>
[JsonObject]
public class ContentfulCollection<T> : IEnumerable<T>
{
/// <summary>
/// Common system managed metadata properties.
/// </summary>
[JsonProperty("sys")]
public SystemProperties SystemProperties { get; set; }
/// <summary>
/// The number of items skipped in this resultset.
/// </summary>
public int Skip { get; set; }
/// <summary>
/// The maximum number of items returned in this result.
/// </summary>
public int Limit { get; set; }
/// <summary>
/// The total number of items available.
/// </summary>
public int Total { get; set; }
/// <summary>
/// The <see cref="IEnumerable{T}"/> of items to be serialized from the API response.
/// </summary>
public IEnumerable<T> Items { get; set; }
/// <summary>
/// The <see cref="IEnumerable{Entry}" /> of included referenced entries
/// </summary>
public IEnumerable<Entry<dynamic>> IncludedEntries { get; set; }
/// <summary>
/// The <see cref="IEnumerable{Asset}" /> of included referenced assets
/// </summary>
public IEnumerable<Asset> IncludedAssets { get; set; }
/// <summary>
/// An enumerable of errors while deserializing. Will be null if no errors are present.
/// </summary>
public IEnumerable<ContentfulError> Errors { get; set; }
/// <summary>
/// Returns an enumerator that iterates through the <see cref="Items"/> collection
/// </summary>
public IEnumerator<T> GetEnumerator()
{
return Items.GetEnumerator();
}
/// <summary>
/// Returns an enumerator that iterates through the <see cref="Items"/> collection
/// </summary>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
fileFormatVersion: 2
guid: 4d7e86313523a514cbb6b4405aa4a1ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Models
{
/// <summary>
/// Encapsulates an error returned from the Contentful API.
/// </summary>
public class ContentfulError : IContentfulResource
{
/// <summary>
/// Common system managed metadata properties.
/// </summary>
[JsonProperty("sys")]
public SystemProperties SystemProperties { get; set; }
/// <summary>
/// Encapsulates the details of the error.
/// </summary>
public ContentfulErrorDetails Details { get; set; }
}
/// <summary>
/// Encapsulates detailed information about an error returned by the Contentful API.
/// </summary>
public class ContentfulErrorDetails
{
/// <summary>
/// The type of error.
/// </summary>
public string Type { get; set; }
/// <summary>
/// The type of link causing the error.
/// </summary>
public string LinkType { get; set; }
/// <summary>
/// The id of the resource causing issues.
/// </summary>
public string Id { get; set; }
}
}
fileFormatVersion: 2
guid: 741427c5eeea981478993a300c350ce6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents a single entry of a <seealso cref="ContentType"/> in a <seealso cref="Space"/>.
/// </summary>
/// <typeparam name="T">The type the fields of the entry should be serialized into.</typeparam>
public class Entry<T> : IEntry<T>
{
/// <summary>
/// Common system managed metadata properties.
/// </summary>
[JsonProperty("sys")]
public SystemProperties SystemProperties { get; set; }
/// <summary>
/// The fields of the entry deserialized to the type T.
/// </summary>
public T Fields { get; set; }
}
}
fileFormatVersion: 2
guid: fbbd1fd2d090ca740a4917a4d7b726ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Models.Management;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents a field in a <seealso cref="ContentType"/>. Note that this is not the representation of a field with
/// actual value in an <seealso cref="Entry{T}"/> or <seealso cref="Asset"/>, but merely a representation of the fields data structure.
/// </summary>
public class Field
{
/// <summary>
/// The ID of the field. It must be unique among all fields of the <seealso cref="ContentType"/>.
/// </summary>
public string Id { get; set; }
/// <summary>
/// The name of the field. This will be the label of the field in the Contentful web app.
/// </summary>
public string Name { get; set; }
/// <summary>
/// The type of field. Determines what type of data can be stored in the field.
/// </summary>
public string Type { get; set; }
/// <summary>
/// Whether this field is mandatory or not.
/// </summary>
public bool Required { get; set; }
/// <summary>
/// Whether this field supports different values for different locales.
/// </summary>
public bool Localized { get; set; }
/// <summary>
/// The type of link, if any. Normally Asset or Entry.
/// </summary>
public string LinkType { get; set; }
/// <summary>
/// Whether this field is disabled. Disabled fields are not visible in the Contentful web app.
/// </summary>
public bool Disabled { get; set; }
/// <summary>
/// Whether this field is omitted in the response from the Content Delivery and Preview APIs.
/// </summary>
public bool Omitted { get; set; }
/// <summary>
/// Defines a schema for the elements of an array field. Will be null for other types.
/// </summary>
public Schema Items { get; set; }
/// <summary>
/// The validations that should be applied to the field.
/// </summary>
public List<IFieldValidator> Validations { get; set; }
}
}
fileFormatVersion: 2
guid: 64558a1efa4af7545bc1e8bce651111a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Configuration;
using Contentful.Core.Models.Management;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents information about the actual binary file of an <see cref="Asset"/>.
/// </summary>
public class File
{
/// <summary>
/// The original name of the file.
/// </summary>
public string FileName { get; set; }
/// <summary>
/// The content type of the data contained within this file.
/// </summary>
public string ContentType { get; set; }
/// <summary>
/// An absolute URL to this file.
/// </summary>
public string Url { get; set; }
/// <summary>
/// The url to upload this file from.
/// </summary>
[JsonProperty("upload")]
public string UploadUrl { get; set; }
/// <summary>
/// A reference to a SystemProperties metadata object with a type of upload.
/// </summary>
[JsonProperty("uploadFrom")]
public UploadReference UploadReference { get; set; }
/// <summary>
/// Detailed information about the file stored by Contentful.
/// </summary>
public FileDetails Details { get; set; }
}
}
fileFormatVersion: 2
guid: 219a05fc552628f499897d2701d6b30b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents detailed information about a <see cref="File"/>.
/// </summary>
public class FileDetails
{
/// <summary>
/// The size of the file in bytes.
/// </summary>
public long Size { get; set; }
/// <summary>
/// The image details of the file if applicable, will be null for non image types.
/// </summary>
public ImageDetails Image { get; set; }
}
}
fileFormatVersion: 2
guid: 943ed0e8082742b418c77882f453f7d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents a single Contentful resource.
/// </summary>
public interface IContentfulResource
{
/// <summary>
/// Common system managed metadata properties.
/// </summary>
SystemProperties SystemProperties { get; set; }
}
}
fileFormatVersion: 2
guid: d89beb8afe78a644bbaf06aa6160039e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents a Contentful entry resource.
/// </summary>
/// <typeparam name="T">The type the fields of the entry should be serialized into.</typeparam>
public interface IEntry<T> : IContentfulResource
{
/// <summary>
/// The fields of the entry deserialized to the type T.
/// </summary>
T Fields { get; set; }
}
}
fileFormatVersion: 2
guid: 64565a6cbc61f3649844c3d5f9244a3f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents details about an image <see cref="File"/>.
/// </summary>
public class ImageDetails
{
/// <summary>
/// The original height of the image.
/// </summary>
public int Height { get; set; }
/// <summary>
/// The original width of the image.
/// </summary>
public int Width { get; set; }
}
}
fileFormatVersion: 2
guid: aa24f5807cea88d4eb3924298043fe7f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
namespace Contentful.Core.Models
{
/// <summary>
/// Represents a location field in a <seealso cref="Space"/>.
/// </summary>
public class Location
{
/// <summary>
/// The latitude of the location.
/// </summary>
public double Lat { get; set; }
/// <summary>
/// The longitude of the location.
/// </summary>
public double Lon { get; set; }
}
}
fileFormatVersion: 2
guid: 30c972b23bc6e8b44a8e19997baa880b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 1ff6d026930b4eb4ab5ca9203bd94f80
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Models.Management
{
/// <summary>
/// Represents an api key for the Contentful Content Delivery API.
/// </summary>
public class ApiKey : IContentfulResource
{
/// <summary>
/// Common system managed metadata properties.
/// </summary>
[JsonProperty("sys", NullValueHandling = NullValueHandling.Ignore)]
public SystemProperties SystemProperties { get; set; }
/// <summary>
/// The name of the API key.
/// </summary>
public string Name { get; set; }
/// <summary>
/// The description of the API key.
/// </summary>
public string Description { get; set; }
/// <summary>
/// The access token for the API key.
/// </summary>
public string AccessToken { get; set; }
}
}
fileFormatVersion: 2
guid: 979a7e73bb91a7d4696383e9677016e5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Models.Management
{
/// <summary>
/// Represents a collection of permissions for different parts of the Contentful APIs.
/// </summary>
public class ContentfulPermissions
{
/// <summary>
/// Adds permissions to modify the content model.
/// </summary>
[JsonProperty("ContentModel")]
[JsonConverter(typeof(StringAllToListJsonConverter))]
public List<string> ContentModel { get; set; }
/// <summary>
/// Adds permissions to modify settings.
/// </summary>
[JsonProperty("Settings")]
[JsonConverter(typeof(StringAllToListJsonConverter))]
public List<string> Settings { get; set; }
/// <summary>
/// Adds permissions to access the Content Delivery.
/// </summary>
[JsonProperty("ContentDelivery")]
[JsonConverter(typeof(StringAllToListJsonConverter))]
public List<string> ContentDelivery { get; set; }
}
}
fileFormatVersion: 2
guid: 75ac5ba8ba3e4e046a8d9c50d7860feb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Models.Management
{
/// <summary>
/// Represents the editor interface of a <see cref="ContentType"/>.
/// </summary>
public class EditorInterface : IContentfulResource
{
/// <summary>
/// Common system managed metadata properties.
/// </summary>
[JsonProperty("sys")]
public SystemProperties SystemProperties { get; set; }
/// <summary>
/// List of <see cref="EditorInterfaceControl"/> representing the type of editor interface for each field of a <see cref="ContentType"/>.
/// </summary>
public List<EditorInterfaceControl> Controls { get; set; }
}
}
fileFormatVersion: 2
guid: 3ed240a2594b53348b4a2ec5c7d3be26
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Contentful.Core.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Models.Management
{
/// <summary>
/// Represents how a specific field of a <see cref="ContentType"/> should be represented visually.
/// </summary>
[JsonConverter(typeof(EditorInterfaceControlJsonConverter))]
public class EditorInterfaceControl
{
/// <summary>
/// The id of the field that this control represents.
/// </summary>
public string FieldId { get; set; }
/// <summary>
/// The id of the type of widget to use for this field. See also <seealso cref="SystemWidgetIds"/> for a list of system widget ids.
/// </summary>
public string WidgetId { get; set; }
/// <summary>
/// Represents custom settings for a widget.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public EditorInterfaceControlSettings Settings { get; set; }
}
}
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.