Skip to content

Repository files navigation

OpenActive.DatasetSite.NET Nuget

C# .NET helper functions supporting dataset site creation, to create something like this example (or any of the other examples listed here).

This package intends to simplify creation of OpenActive Dataset Sites using templates.

For comparison, see the PHP and Ruby implementations.

Please find full documentation that covers creation of the accompanying GitHub issues board at https://developer.openactive.io/publishing-data/dataset-sites.

Table Of Contents

Requirements

This project requires .NET Framework 4.5 or .NET Standard 2.0.

Dependencies

This library makes use of datasetsite.mustache, which is designed to conform to the Dataset API Discovery specification. Pull requests and suggestions for improvements to datasetsite.mustache are welcome via its GitHub repository.

OpenActive.NET is also used for strongly typed OpenActive models, and Stubble for rendering the dataset site mustache template.

Usage options

Simply call one of the Render methods detailed below to output self-contained HTML of the dataset site, which includes embedded styles.

Simple implementation

RenderSimpleDatasetSite(settings, supportedOpportunityTypes, staticAssetsPathUrl)

Returns a string corresponding to the compiled HTML, based on an embedded version of datasetsite.mustache, the provided settings, and supportedOpportunityTypes.

If staticAssetsPathUrl is provided, the CSP-compatible template is rendered. In this case you must ensure that you are serving the contents of CSP compatible static assets archive v7 at this location.

supportedOpportunityTypes must be a List<OpportunityType>, which auto-generates the metadata associated which each feed using best-practice values.

settings must contain the following object:

DatasetSiteGeneratorSettings

PropertyTypeDescription
OpenDataFeedBaseUrlUriThe base URL for the open data feeds (must not contain trailing /)
DatasetSiteUrlUriThe URL where this dataset site is displayed (the page's own URL)
DatasetDiscussionUrlUriThe GitHub issues page for the dataset
DatasetDocumentationUrlUriAny documentation specific to the dataset. Defaults to https://permalink.openactive.io/dataset-site/open-data-documentation if not provided, which should be used if no documentation is available .
DatasetLanguagesList<string>The languages available in the dataset, following the IETF BCP 47 standard. Defaults to 'en-GB'.
OrganisationNamestringThe publishing organisation's name
OrganisationUrlUriThe publishing organisation's URL
OrganisationLegalEntitystringThe legal name of the publishing organisation of this dataset
OrganisationPlainTextDescriptionstringA plain text description of this organisation
OrganisationLogoUrlUriAn image URL of the publishing organisation's logo, ideally in PNG format
OrganisationEmailstringThe contact email of the publishing organisation of this dataset
PlatformNamestringThe software platform's name. Only set this if different from the publishing organisation, otherwise leave as null to exclude platform metadata.
PlatformUrlUriThe software platform's website
PlatformSoftwareVersionstringThe software platform's software version
BackgroundImageUrlUriThe background image to show on the Dataset Site page
DateFirstPublishedDateTimeOffsetThe date the dataset was first published
OpenBookingAPIBaseUrlUriThe Base URI of this implementation of the Open Booking API
OpenBookingAPIAuthenticationAuthorityUrlUriThe location of the OpenID Provider that must be used to access the API
OpenBookingAPIDocumentationUrlUriThe URL of documentation related to how to use the Open Booking API. Defaults to https://permalink.openactive.io/dataset-site/open-booking-api-documentation if not provided, which should be use if no documentation is available.
OpenBookingAPITermsOfServiceUrlUriThe URL of terms of service related to the use of this API
OpenBookingAPIRegistrationUrlUriThe URL of a web page that the Broker may use to obtain access to the API, e.g. via a web form
TestSuiteCertificateUrlUriThe URL of the OpenActive Test Suite certificate for this booking system

Example

[Route("openactive")]publicclassDatasetSiteController:Controller{// GET: /openactive/publicIActionResultIndex(){// Customer-specific settings for dataset JSON (these should come from a database)varsettings=newDatasetSiteGeneratorSettings{OpenDataFeedBaseUrl="https://customer.example.com/feed".ParseUrlOrNull(),DatasetSiteUrl="https://halo-odi.legendonlineservices.co.uk/openactive/".ParseUrlOrNull(),DatasetDiscussionUrl="https://github.com/gll-better/opendata".ParseUrlOrNull(),DatasetDocumentationUrl="https://permalink.openactive.io/dataset-site/open-data-documentation".ParseUrlOrNull(),DatasetLanguages=newList<string>{"en-GB"},OrganisationName="Better",OrganisationUrl="https://www.better.org.uk/".ParseUrlOrNull(),OrganisationLegalEntity="GLL",OrganisationPlainTextDescription="Established in 1993, GLL is the largest UK-based charitable social enterprise delivering leisure, health and community services. Under the consumer facing brand Better, we operate 258 public Sports and Leisure facilities, 88 libraries, 10 children’s centres and 5 adventure playgrounds in partnership with 50 local councils, public agencies and sporting organisations. Better leisure facilities enjoy 46 million visitors a year and have more than 650,000 members.",OrganisationLogoUrl="http://data.better.org.uk/images/logo.png".ParseUrlOrNull(),OrganisationEmail="info@better.org.uk",PlatformName="AcmeBooker",PlatformUrl="https://acmebooker.example.com/".ParseUrlOrNull(),PlatformVersion="2.0",BackgroundImageUrl="https://data.better.org.uk/images/bg.jpg".ParseUrlOrNull(),DateFirstPublished=newDateTimeOffset(newDateTime(2019,01,14)),OpenBookingAPIBaseUrl="https://reference-implementation.openactive.io/api/openbooking".ParseUrlOrNull(),OpenBookingAPIAuthenticationAuthorityUrl="https://auth.reference-implementation.openactive.io".ParseUrlOrNull(),OpenBookingAPIDocumentationUrl="https://permalink.openactive.io/dataset-site/open-booking-api-documentation".ParseUrlOrNull(),OpenBookingAPITermsOfServiceUrl="https://example.com/api-terms-page".ParseUrlOrNull(),OpenBookingAPIRegistrationUrl="https://example.com/api-landing-page".ParseUrlOrNull(),TestSuiteCertificateUrl="https://certificates.reference-implementation.openactive.io/examples/all-features/controlled/".ParseUrlOrNull()};varsupportedFeeds=newList<OpportunityType>{OpportunityType.SessionSeries,OpportunityType.ScheduledSession,OpportunityType.FacilityUse,OpportunityType.FacilityUseSlot,OpportunityType.CourseInstance};returnContent(DatasetSiteGenerator.RenderSimpleDatasetSite(settings,supportedFeeds),"text/html");}}

Feed-level customisation

RenderSimpleDatasetSiteFromDataDownloads(settings, dataDownloads, dataFeedDescriptions, staticAssetsPathUrl)

Returns a string corresponding to the compiled HTML, based on an embedded version of datasetsite.mustache, the provided settings, dataDownloads and dataFeedDescriptions.

The dataDownloads argument must be a List<OpenActive.NET.DataDownload>, which each describe an available open data feed.

The dataFeedDescriptions must be a List<string> of strings that each describe the dataset, e.g:

vardataFeedDescriptions=newList<string>{"Sessions","Facilities"};

If staticAssetsPathUrl is provided, the CSP-compatible template is rendered. In this case you must ensure that you are serving the contents of CSP compatible static assets archive v7 at this location.

Example

[Route("openactive")]publicclassDatasetSiteController:Controller{// GET: /openactive/publicIActionResultIndex(){// Customer-specific settings for dataset JSON (these should come from a database)varsettings=newDatasetSiteGeneratorSettings{OpenDataFeedBaseUrl="https://customer.example.com/feed".ParseUrlOrNull(),DatasetSiteUrl="https://halo-odi.legendonlineservices.co.uk/openactive/".ParseUrlOrNull(),DatasetDiscussionUrl="https://github.com/gll-better/opendata".ParseUrlOrNull(),DatasetDocumentationUrl="https://permalink.openactive.io/dataset-site/open-data-documentation".ParseUrlOrNull(),DatasetLanguages=newList<string>{"en-GB"},OrganisationName="Better",OrganisationUrl="https://www.better.org.uk/".ParseUrlOrNull(),OrganisationLegalEntity="GLL",OrganisationPlainTextDescription="Established in 1993, GLL is the largest UK-based charitable social enterprise delivering leisure, health and community services. Under the consumer facing brand Better, we operate 258 public Sports and Leisure facilities, 88 libraries, 10 children’s centres and 5 adventure playgrounds in partnership with 50 local councils, public agencies and sporting organisations. Better leisure facilities enjoy 46 million visitors a year and have more than 650,000 members.",OrganisationLogoUrl="http://data.better.org.uk/images/logo.png".ParseUrlOrNull(),OrganisationEmail="info@better.org.uk",PlatformName="AcmeBooker",PlatformUrl="https://acmebooker.example.com/".ParseUrlOrNull(),PlatformVersion="2.0",BackgroundImageUrl="https://data.better.org.uk/images/bg.jpg".ParseUrlOrNull(),DateFirstPublished=newDateTimeOffset(newDateTime(2019,01,14)),OpenBookingAPIBaseUrl="https://reference-implementation.openactive.io/api/openbooking".ParseUrlOrNull(),OpenBookingAPIAuthenticationAuthorityUrl="https://auth.reference-implementation.openactive.io".ParseUrlOrNull(),OpenBookingAPIDocumentationUrl="https://permalink.openactive.io/dataset-site/open-booking-api-documentation".ParseUrlOrNull(),OpenBookingAPITermsOfServiceUrl="https://example.com/api-terms-page".ParseUrlOrNull(),OpenBookingAPIRegistrationUrl="https://example.com/api-landing-page".ParseUrlOrNull(),TestSuiteCertificateUrl="https://certificates.reference-implementation.openactive.io/examples/all-features/controlled/".ParseUrlOrNull()};vardataDownloads=newList<DataDownload>{newDataDownload{Name="SessionSeries",AdditionalType=newUri("https://openactive.io/SessionSeries"),EncodingFormat=OpenActiveMediaTypes.RealtimePagedDataExchange.Version1,ContentUrl=newUri(settings.OpenDataFeedBaseUrl+"/session-series"),Identifier="SessionSeries"},newDataDownload{Name="ScheduledSession",AdditionalType=newUri("https://openactive.io/ScheduledSession"),EncodingFormat=OpenActiveMediaTypes.RealtimePagedDataExchange.Version1,ContentUrl=newUri(settings.OpenDataFeedBaseUrl+"/scheduled-sessions"),Identifier="ScheduledSession"},newDataDownload{Name="FacilityUse",AdditionalType=newUri("https://openactive.io/FacilityUse"),EncodingFormat=OpenActiveMediaTypes.RealtimePagedDataExchange.Version1,ContentUrl=newUri(settings.OpenDataFeedBaseUrl+"/facility-uses"),Identifier="FacilityUse"},newDataDownload{Name="Slot for FacilityUse",AdditionalType=newUri("https://openactive.io/Slot"),EncodingFormat=OpenActiveMediaTypes.RealtimePagedDataExchange.Version1,ContentUrl=newUri(settings.OpenDataFeedBaseUrl+"/slots"),Identifier="FacilityUseSlot"}};vardataFeedDescriptions=newList<string>{"Sessions","Facilities"};returnContent(DatasetSiteGenerator.RenderSimpleDatasetSiteFromDataDownloads(settings,dataDownloads,dataFeedDescriptions),"text/html");}}

Model-level customisation

RenderDatasetSite(dataset, staticAssetsPathUrl)

Returns a string corresponding to the compiled HTML, based on an embedded version of datasetsite.mustache, and the provided dataset.

The dataset argument must be an object of type OpenActive.NET.Dataset, and must contain the properties required to render the dataset site.

If staticAssetsPathUrl is provided, the CSP-compatible template is rendered. In this case you must ensure that you are serving the contents of CSP compatible static assets archive v7 at this location.

Example

[Route("openactive")]publicclassDatasetSiteController:Controller{// GET: /openactive/publicIActionResultIndex(){// Customer-specific settings for dataset JSON (these should come from a database)varsettings=newDatasetSiteGeneratorSettings{OpenDataFeedBaseUrl="https://customer.example.com/feed".ParseUrlOrNull(),DatasetSiteUrl="https://halo-odi.legendonlineservices.co.uk/openactive/".ParseUrlOrNull(),DatasetDiscussionUrl="https://github.com/gll-better/opendata".ParseUrlOrNull(),DatasetDocumentationUrl="https://permalink.openactive.io/dataset-site/open-data-documentation".ParseUrlOrNull(),DatasetLanguages=newList<string>{"en-GB"},OrganisationName="Better",OrganisationUrl="https://www.better.org.uk/".ParseUrlOrNull(),OrganisationLegalEntity="GLL",OrganisationPlainTextDescription="Established in 1993, GLL is the largest UK-based charitable social enterprise delivering leisure, health and community services. Under the consumer facing brand Better, we operate 258 public Sports and Leisure facilities, 88 libraries, 10 children’s centres and 5 adventure playgrounds in partnership with 50 local councils, public agencies and sporting organisations. Better leisure facilities enjoy 46 million visitors a year and have more than 650,000 members.",OrganisationLogoUrl="http://data.better.org.uk/images/logo.png".ParseUrlOrNull(),OrganisationEmail="info@better.org.uk",PlatformName="AcmeBooker",PlatformUrl="https://acmebooker.example.com/".ParseUrlOrNull(),PlatformVersion="2.0",BackgroundImageUrl="https://data.better.org.uk/images/bg.jpg".ParseUrlOrNull(),DateFirstPublished=newDateTimeOffset(newDateTime(2019,01,14)),OpenBookingAPIBaseUrl="https://reference-implementation.openactive.io/api/openbooking".ParseUrlOrNull(),OpenBookingAPIAuthenticationAuthorityUrl="https://auth.reference-implementation.openactive.io".ParseUrlOrNull(),OpenBookingAPIDocumentationUrl="https://permalink.openactive.io/dataset-site/open-booking-api-documentation".ParseUrlOrNull(),OpenBookingAPITermsOfServiceUrl="https://example.com/api-terms-page".ParseUrlOrNull(),OpenBookingAPIRegistrationUrl="https://example.com/api-landing-page".ParseUrlOrNull(),TestSuiteCertificateUrl="https://certificates.reference-implementation.openactive.io/examples/all-features/controlled/".ParseUrlOrNull()};vardataFeedHumanisedList="Sessions and Facilities";vardataset=newDataset{Id=settings.DatasetSiteUrl,Url=settings.DatasetSiteUrl,Name=settings.OrganisationName+" "+dataFeedHumanisedList,Description=$"Near real-time availability and rich descriptions relating to the {dataFeedHumanisedList.ToLowerInvariant()} available from {settings.OrganisationName}",Keywords=newList<string>{"Sessions","Facilities","Activities","Sports","Physical Activity","OpenActive"},License=newUri("https://creativecommons.org/licenses/by/4.0/"),DiscussionUrl=settings.DatasetDiscussionUrl,Documentation=settings.DatasetDocumentationUrl,InLanguage=settings.DatasetLanguages,SchemaVersion=newUri("https://www.openactive.io/modelling-opportunity-data/2.0/"),Publisher=newOpenActive.NET.Organization{Name=settings.OrganisationName,LegalName=settings.OrganisationLegalEntity,Description=settings.OrganisationPlainTextDescription,Email=settings.OrganisationEmail,Url=settings.OrganisationUrl,Logo=newOpenActive.NET.ImageObject{Url=settings.OrganisationLogoUrl}},Distribution=newList<DataDownload>{newDataDownload{Name="SessionSeries",AdditionalType=newUri("https://openactive.io/SessionSeries"),EncodingFormat=OpenActiveMediaTypes.RealtimePagedDataExchange.Version1,ContentUrl=newUri(settings.OpenDataFeedBaseUrl+"/session-series"),Identifier="SessionSeries"},newDataDownload{Name="ScheduledSession",AdditionalType=newUri("https://openactive.io/ScheduledSession"),EncodingFormat=OpenActiveMediaTypes.RealtimePagedDataExchange.Version1,ContentUrl=newUri(settings.OpenDataFeedBaseUrl+"/scheduled-sessions"),Identifier="ScheduledSession"},newDataDownload{Name="FacilityUse",AdditionalType=newUri("https://openactive.io/FacilityUse"),EncodingFormat=OpenActiveMediaTypes.RealtimePagedDataExchange.Version1,ContentUrl=newUri(settings.OpenDataFeedBaseUrl+"/facility-uses"),Identifier="FacilityUse"},newDataDownload{Name="Slot for FacilityUse",AdditionalType=newUri("https://openactive.io/Slot"),EncodingFormat=OpenActiveMediaTypes.RealtimePagedDataExchange.Version1,ContentUrl=newUri(settings.OpenDataFeedBaseUrl+"/slots"),Identifier="FacilityUseSlot"}},DatePublished=settings.DateFirstPublished,DateModified=DateTimeOffset.UtcNow,BackgroundImage=newImageObject{Url=settings.BackgroundImageUrl},BookingService=settings.PlatformName==null?null:newBookingService{Name=settings.PlatformName,Url=settings.PlatformUrl,SoftwareVersion=settings.PlatformVersion,HasCredential=settings.TestSuiteCertificateUrl},AccessService=settings.OpenBookingAPIBaseUrl==null?null:newWebAPI{Name="Open Booking API",Description=$"API that allows for seamless booking experiences to be created for {dataFeedHumanisedList.ToLowerInvariant()} available from {settings.OrganisationName}",Documentation=settings.OpenBookingAPIDocumentationUrl??newUri("https://permalink.openactive.io/dataset-site/open-booking-api-documentation"),TermsOfService=settings.OpenBookingAPITermsOfServiceUrl,EndpointUrl=settings.OpenBookingAPIBaseUrl,AuthenticationAuthority=settings.OpenBookingAPIAuthenticationAuthorityUrl,ConformsTo=newList<Uri>{newUri("https://openactive.io/open-booking-api/EditorsDraft/")},EndpointDescription=newUri("https://www.openactive.io/open-booking-api/EditorsDraft/swagger.json"),LandingPage=settings.OpenBookingAPIRegistrationUrl}};returnContent(DatasetSiteGenerator.RenderDatasetSite(dataset),"text/html");}}

Total customisation

RenderDatasetSiteWithTemplate(dataset, mustacheTemplate, staticAssetsPathUrl)

Returns a string corresponding to the compiled HTML, based on the supplied version of datasetsite.mustache, and the provided dataset.

The dataset argument must be an object of type OpenActive.NET.Dataset, and must contain the properties required to render the dataset site.

The mustacheTemplate argument must be a string containing the contents of a potentially customised version of datasetsite.mustache.

If the staticAssetsPathUrl argument is provided, it is included in the data passed to the mustache template.

Please note that any customisations must maintain conformance with the Dataset API Discovery specification.

About

.NET helper functions to create an OpenActive Dataset Site

Topics

Resources

Stars

0 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages