This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Date and Timestamp predicates | |
var dateBefore = Predicates.dateBefore("my.product.releaseDate", new DateTime(2014, 6, 1)); | |
var dateAfter = Predicates.dateAfter("my.product.releaseDate", new DateTime(2014, 1, 1)); | |
var dateBetween = Predicates.dateBetween("my.product.releaseDate", new DateTime(2014, 1, 1), new DateTime(2014, 6, 1)); | |
var dayOfMonth = Predicates.dayOfMonth("my.product.releaseDate", 14); | |
var dayOfMonthAfter = Predicates.dayOfMonthAfter("my.product.releaseDate", 14); | |
var dayOfMonthBefore = Predicates.dayOfMonthBefore("my.product.releaseDate", 14); | |
var dayOfWeek = Predicates.dayOfWeek("my.product.releaseDate", DayOfWeek.Tuesday); | |
var dayOfWeekAfter = Predicates.dayOfWeekAfter("my.product.releaseDate", DayOfWeek.Wednesday); | |
var dayOfWeekBefore = Predicates.dayOfWeekBefore("my.product.releaseDate", DayOfWeek.Wednesday); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Number predicates | |
var gt = Predicates.gt("my.product.price", 10); | |
var lt = Predicates.lt("my.product.price", 20); | |
var inRange = Predicates.inRange("my.product.price", 10, 20); | |
// Accessing number fields | |
double price = doc.GetNumber("product.price").Value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var author = doc.GetText("blog-post.author"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "at" predicate: equality of a fragment to a value. | |
var at = Predicates.at("document.type", "article"); | |
// "any" predicate: equality of a fragment to a value. | |
var any = Predicates.any("document.type", new string[] {"article", "blog-post"}); | |
// "fulltext" predicate: fulltext search in a fragment. | |
var fulltext = Predicates.fulltext("my.article.body", "sausage"); | |
// "similar" predicate, with a document id as reference | |
var similar = Predicates.similar("UXasdFwe42D", 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Api api = await prismic.Api.Get("https://lesbonneschoses.cdn.prismic.io/api"); | |
var response = await api.Form("everything") | |
.Ref(api.Master) | |
.Query (@"[[:d = at(document.type, ""product"")]]") | |
.PageSize(100) | |
.Orderings("[my.product.price desc]") | |
.Submit(); | |
// The products are now ordered by price, highest first | |
var results = response.Results; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var previewToken = "MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70"; | |
Api api = await prismic.Api.Get("https://lesbonneschoses.cdn.prismic.io/api", previewToken); | |
Console.WriteLine ("API OK"); | |
var stPatrickRef = api.Ref("St-Patrick specials"); | |
Console.WriteLine ("StPar = " + stPatrickRef); | |
// Now we'll use this reference for all our calls | |
Response response = await api.Form("everything") | |
.Ref(stPatrickRef) | |
.Query (@"[[:d = at(document.type, ""product"")]]") | |
.Submit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will fail because the token is invalid, but this is how to access a private API | |
Api api = await prismic.Api.Get("https://lesbonneschoses.cdn.prismic.io/api", "MC5-XXXXXXX-vRfvv70"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group = document.get_group("article.documents") | |
docs = (group and group.value) or [] | |
for doc in docs: | |
# Desc and Link are Fragments, their type depending on what's declared in the Document Mask | |
desc = doc.get("desc", None) | |
link = doc.get("linktodoc", None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Just implement your own cache object by duck-typing | |
# https://github.com/prismicio/python-kit/blob/master/prismic/cache.py | |
no_cache = NoCache() | |
# This api will use the custom cache object | |
api = prismic.get('https://lesbonneschoses.prismic.io/api', cache=no_cache) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "near" predicate for GeoPoint fragments | |
near = predicates.near("my.store.location", 48.8768767, 2.3338802, 10) | |
# Accessing GeoPoint fragments | |
place = document.get_geopoint("article.location") | |
coordinates = place and ("%.6f,%.6f" % (place.latitude, place.longitude)) |