private static LtiRequest GetLtiContentItemSelectionResponse(string url, string data) { // Both links should pass the user's username as a custom parameter var custom = new Dictionary <string, string> { { "username", "$User.username" } }; // Create a graph with 2 LtiLinks var graph = new ContentItemSelectionGraph { Graph = new List <ContentItem> { new LtiLink { Custom = custom, Id = new Uri("https://www.company.com/tool/1"), MediaType = LtiConstants.LtiLtiLinkMediaType, Text = "Tool 1", Title = "Tool 1", PlacementAdvice = new ContentItemPlacement { PresentationDocumentTarget = DocumentTarget.window } }, new LtiLink { Custom = custom, Id = new Uri("https://www.company.com/tool/2"), MediaType = LtiConstants.LtiLtiLinkMediaType, Text = "Tool 2", Title = "Tool 2", PlacementAdvice = new ContentItemPlacement { PresentationDocumentTarget = DocumentTarget.iframe } } } }; // ReSharper disable once UseObjectOrCollectionInitializer var ltiRequest = new LtiRequest(LtiConstants.ContentItemSelectionLtiMessageType) { ConsumerKey = "12345", Url = new Uri(url) }; ltiRequest.ContentItems = graph.ToJsonLdString(); ltiRequest.Data = data; return(ltiRequest); }
/// <summary> /// Create an LtiRequestViewModel that contains a ContentItemPlacementResponse. /// </summary> /// <param name="url">The content_item_return_url from the content-item message.</param> /// <param name="consumerKey">The OAuth consumer key to use to sign the request.</param> /// <param name="consumerSecret">The OAuth consumer secret to use to sign the request.</param> /// <param name="contentItems">The ContentItemPlacementResponse to send.</param> /// <param name="data">The data received in the original content-item message.</param> /// <param name="ltiErrorLog">Optional plain text error message to be logged by the Tool Consumer.</param> /// <param name="ltiErrorMsg">Optional plain text error message to be displayed by the Tool Consumer.</param> /// <param name="ltiLog">Optional plain text message to be logged by the Tool Consumer.</param> /// <param name="ltiMsg">Optional plain text message to be displayed by the Tool Consumer.</param> /// <returns>The LtiRequestViewModel which contains a signed version of the response.</returns> public static LtiRequestViewModel CreateContentItemSelectionViewModel( string url, string consumerKey, string consumerSecret, ContentItemSelectionGraph contentItems, string data, string ltiErrorLog, string ltiErrorMsg, string ltiLog, string ltiMsg) { var ltiRequest = new LtiRequest(LtiConstants.ContentItemSelectionLtiMessageType) { Url = new Uri(url), ConsumerKey = consumerKey, ContentItems = contentItems.ToJsonLdString(), Data = data, LtiErrorLog = ltiErrorLog, LtiErrorMsg = ltiErrorMsg, LtiLog = ltiLog, LtiMsg = ltiMsg }; return(ltiRequest.GetViewModel(consumerSecret)); }