public async static Task <HttpResponseMessage> QueryByActorId( [QueryParameter(Name = ActorPropertyName)] Guid actorId, Context context, AzureApplication application, EastFive.Api.SessionToken security, UrlHelper urlHelper, ContentResponse onFound, MultipartResponseAsync onFounds, ReferencedDocumentNotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized, ServiceUnavailableResponse onServiceUnavailable) { return(await await context.PasswordCredentials.GetPasswordCredentialByActorAsync( actorId, security, application, (credentials) => { var credentialResources = credentials .Select( passwordCredential => { var resource = Convert(passwordCredential, urlHelper); var response = onFound(resource); return response; }) .ToArray(); return onFounds(credentialResources); }, () => onNotFound().AsTask(), () => onUnauthorized().AsTask(), (why) => onServiceUnavailable().AsTask())); }
public static HttpResponseMessage CredentialOptionsAsync(ContentResponse onContent) { var credentialProviders = new Resources.PasswordCredential[] { new Resources.PasswordCredential { UserId = "0123456789", Token = "ABC.123.MXC", }, new Resources.PasswordCredential { //Method = CredentialValidationMethodTypes.OpenIdConnect, //Provider = new Uri("urn:auth.gibbits.nc2media.com/AuthOpenIdConnect/"), UserId = Guid.NewGuid().ToString("N"), Token = "EDF.123.A3EF", }, new Resources.PasswordCredential { //Method = CredentialValidationMethodTypes.Implicit, //Provider = new Uri("http://www.example.com/ImplicitAuth"), UserId = Guid.NewGuid().ToString("N"), Token = Guid.NewGuid().ToString("N"), } }; var response = new BlackBarLabs.Api.Resources.Options() { Get = credentialProviders, }; var responseMessage = onContent(response); return(responseMessage); }
public IHttpResponse Handle(IHttpRequest request) { if (request.Path == "/favicon.ico") { return(null); } this.getParams = new Dictionary <string, string>(request.UrlParameters); this.postParams = new Dictionary <string, string>(request.FormData); this.requestMethod = request.Method.ToString().ToUpper(); this.PrepareControllerAndActionNames(request.Path); var controller = this.GetController(); var method = this.GetMethod(); if (method == null) { return(new NotFoundResponse()); } this.PrepareMethodParameters(method); IInvocable actionResult = (IInvocable)method.Invoke(controller, this.methodParams); string content = actionResult.Invoke(); IHttpResponse response = new ContentResponse(HttpStatusCode.Ok, content); return(response); }
public static async Task <IHttpResponse> FindByIdAsync( [QueryParameter(CheckFileName = true)] Guid processStageTypeId, EastFive.Api.Security security, ContentResponse onFound, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { return(await await ProcessStageTypes.FindAllAsync(security, types => types.First( async(stage, next) => { if (stage.processStageTypeId == processStageTypeId) { return onFound(stage); } return await next(); }, () => onNotFound().ToTask()), () => onUnauthorized().ToTask())); //return Connectors.FindByIdAsync(id, // security.performingAsActorId, security.claims, // (synchronization, destinationIntegrationId) => onFound(GetResource(synchronization, destinationIntegrationId, url)), // () => onNotFound(), // () => onUnauthorized()); }
public IHttpResponse Handle(IHttpRequest request) { this.request = request; this.getParams = request.UrlParameters; this.postParams = request.FormData; this.requestMethod = request.Method.ToString(); this.controllerName = GetControllerName(request.Path); this.actionName = GetActionName(request.Path); MethodInfo method = this.GetMethod(); if (method == null) { return(new NotFoundResponse()); } MapMethodParameters(method); IInvocable actionResult = (IInvocable)method.Invoke(this.GetController(), this.methodParams); string content = actionResult.Invoke(); IHttpResponse response = new ContentResponse(HttpStatusCode.Ok, content); return(response); }
private async void GetPlaylistsButton_Click(object sender, EventArgs e) { ContentResponse response = await _client.BrowseAsync(MediaNamespace.music, ContentSource.Collection, ItemType.Playlists); _playlists = response.Playlists.Items; _playlists.ForEach(p => PlaylistListBox.Items.Add(p)); }
public async Task Test_Lookup_Categories() { _content = await _client.LookupAllCategoriesAsync(); Assert.IsNotNull(_content.Categories); Assert.IsTrue(_content.Categories.Items.Count > 0); }
public async Task <ArticleContentResult> GetArticleContent(ContentResponse articleContentResponse) { var result = new ArticleContentResult { Article = articleContentResponse }; if (!articleContentResponse.Links.Any()) { return(result); } var blobUrl = articleContentResponse.Links.FirstOrDefault(li => li.Relation == LinkRelValueObject.CONTENT_BLOB_URL); if (blobUrl == null || string.IsNullOrWhiteSpace(blobUrl.Href)) { return(result); } var httpClient = new HttpClient(); var httRequest = new HttpRequestMessage(HttpMethod.Get, blobUrl.Href); var response = await httpClient.SendAsync(httRequest); if (!response.IsSuccessStatusCode) { throw new Exception($"Error retrieving article content {blobUrl.Href} : {response.StatusCode}"); } var base64EncodedContent = await response.Content.ReadAsStringAsync(); result.EncodedContent = base64EncodedContent; return(result); }
public async Task Test_Lookup_FeaturedPlaylists() { _content = await _client.LookupFeaturedPlaylistsAsync(); Assert.IsNotNull(_content.Playlists); Assert.IsTrue(_content.Playlists.Items.Count > 0); }
public static IEnumerable <Content> GetAllTopLevelContent(this ContentResponse response) { return(response .GetAllContentLists() .Where(c => c?.ReadOnlyItems != null) .SelectMany(x => x.ReadOnlyItems)); }
public async Task TestStream() { // Check that the user has an Xbox Music Pass subscription UserProfileResponse userProfileResponse = await AuthenticatedClient.GetUserProfileAsync(Namespace.music).Log(); // Beware: HasSubscription is bool?. You want != true instead of == false if (userProfileResponse.HasSubscription != true) { Assert.Inconclusive("The user doesn't have an Xbox Music Pass subscription. Cannot stream from catalog."); } // Get popular tracks in the user's country ContentResponse browseResults = await AuthenticatedClient.BrowseAsync(Namespace.music, ContentSource.Catalog, ItemType.Tracks).Log(); Assert.IsNotNull(browseResults, "The browse response should not be null"); AssertPaginatedListIsValid(browseResults.Tracks, 25, 100); // Stream the first streamable track Track track = browseResults.Tracks.Items.First(t => t.Rights.Contains("Stream")); StreamResponse streamResponse = await AuthenticatedClient.StreamAsync(track.Id, ClientInstanceId).Log(); Assert.IsNotNull(streamResponse, "The stream URL response should not be null"); Assert.IsNotNull(streamResponse.Url, "The stream URL should not be null"); Assert.IsNotNull(streamResponse.ContentType, "The stream content type should not be null"); Assert.IsNotNull(streamResponse.ExpiresOn, "The stream expiry date should not be null"); }
public static IHttpResponse Options(IHttpRequest request, IProvideUrl url, ContentResponse onOption) { var stage = // new Resources.ProcessStageType //{ // Id = Guid.NewGuid(), // Group = ProcessStagesGroups.group1Id, // Title = "Buyer Confirm", // ResourceType = "order", // ResourceKeys = new string[] { "ship_to" }, // ResourceTypes = new string[] { "fulfillment" }, //}; new Resources.ProcessStageType { Id = Guid.NewGuid(), Group = ProcessStagesGroups.group2Id, Title = "Seller Confirm", ResourceType = "order", ResourceKeys = new string[] { "ship_from" }, ResourceTypes = new string[] { "fulfillment" }, }; return(onOption(stage)); }
public IHttpResponse Handle(IHttpRequest request) { this.getParameters = new Dictionary <string, string>(request.UrlParameters); this.postParameters = new Dictionary <string, string>(request.FormData); this.requestMethod = request.Method.ToString().ToUpper(); bool areControllersAndActionValid = this.RetrieveControllerAndActionNames(request); if (!areControllersAndActionValid) { return(new NotFoundResponse()); } MethodInfo methodInfo = this.RetrieveActionForExecution(); if (methodInfo == null) { return(new NotFoundResponse()); } this.RetrieveMethodParameters(methodInfo); IInvocable actionResult = (IInvocable)methodInfo.Invoke(this.controllerInstance, this.methodParameters); string content = actionResult.Invoke(); IHttpResponse response = new ContentResponse(HttpStatusCode.Ok, content); return(response); }
public static IHttpResponse Get( ContentResponse onSuccess, NotFoundResponse onNotFound) { return(EastFive.Azure.AppSettings.Apple.AppleAppSiteAssociationId.ConfigurationString( (appId) => { var content = new { applinks = new { apps = new string[] { }, details = new object[] { new { appID = appId, paths = new string [] { "*" }, } } } }; return onSuccess(content); }, (why) => onNotFound().AddReason(why))); }
public async Task TestSearchAndLookup() { // Search for "Daft Punk" ContentResponse searchResults = await Client.SearchAsync(Namespace.music, "Daft Punk", country : "US").Log(); Assert.IsNotNull(searchResults, "The search response should not be null"); AssertPaginatedListIsValid(searchResults.Artists, 1, 1); AssertPaginatedListIsValid(searchResults.Albums, 10, 20); AssertPaginatedListIsValid(searchResults.Tracks, 25, 100); Assert.IsNotNull(searchResults.Tracks.ContinuationToken, "Search results should contain continuation for tracks"); // Get the 2nd page of track results ContentResponse continuedSearchResults = await Client.SearchContinuationAsync(Namespace.music, searchResults.Tracks.ContinuationToken).Log(); Assert.IsNotNull(continuedSearchResults, "The continued search response should not be null"); Assert.IsNull(continuedSearchResults.Artists, "The continued search response should not contain artists"); Assert.IsNull(continuedSearchResults.Albums, "The continued search response should not contain albums"); AssertPaginatedListIsValid(continuedSearchResults.Tracks, 25, 100); // List tracks in the first album Album firstAlbum = searchResults.Albums.Items.First(); ContentResponse albumTrackResults = await Client.LookupAsync(firstAlbum.Id, extras : ExtraDetails.Tracks, country : "US").Log(); AssertPaginatedListIsValid(albumTrackResults.Albums, 1); Album firstAlbumLookup = albumTrackResults.Albums.Items.First(); Assert.AreEqual(firstAlbum.Id, firstAlbumLookup.Id, "Album ids should be the same"); Assert.IsNotNull(firstAlbumLookup.Tracks, "Album should have tracks"); Assert.IsNotNull(firstAlbumLookup.Tracks.Items, "Album should have tracks"); }
public async Task <ContentResponse <TaskModel> > DeleteTaskById(string taskId) { if (CrossConnectivity.Current.IsConnected) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("ZUMO-API-VERSION", "2.0.0"); string url = $"https://eafit.azurewebsites.net/tables/tasks/{taskId}"; var response = await client.DeleteAsync(url); var json = await response.Content.ReadAsStringAsync(); var result = new ContentResponse <TaskModel>() { HttpResponse = response, Data = JsonConvert.DeserializeObject <TaskModel>(json) }; return(result); } } else { return(new ContentResponse <TaskModel>() { HttpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.RequestTimeout) }); } }
public async Task <ContentResponse <TaskModel> > Create(TaskModel taskModel) { if (CrossConnectivity.Current.IsConnected) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("ZUMO-API-VERSION", "2.0.0"); string url = $"https://eafit.azurewebsites.net/tables/tasks"; StringContent body = new StringContent(JsonConvert.SerializeObject(taskModel), Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, body); var json = await response.Content.ReadAsStringAsync(); var result = new ContentResponse <TaskModel>() { HttpResponse = response, Data = JsonConvert.DeserializeObject <TaskModel>(json) }; return(result); } } else { return(new ContentResponse <TaskModel>() { HttpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.RequestTimeout) }); } }
private ContentResponse MapContentResponse(Article article, string latestEntryContentLink, IEnumerable <string> metaTags) { var links = new List <Link>() { new Link { Relation = LinkRelValueObject.SELF, Href = Url.Action(nameof(GetArticle), new { articleId = article.Id }) } }; if (!string.IsNullOrWhiteSpace(latestEntryContentLink)) { links.Add(new Link { Relation = LinkRelValueObject.CONTENT_BLOB_URL, Href = latestEntryContentLink }); } var mapContentResponse = new ContentResponse { Id = article.Id, Author = article.Author, Title = article.Title, Description = article.Description, Created = article.Created, IsPublished = article.IsPublished, Updated = article.Updated, Deleted = article.Deleted, IsDeleted = article.IsDeleted, KeyWords = metaTags.ToArray(), Links = links.ToArray() }; return(mapContentResponse); }
public static Task <HttpResponseMessage> FindAsync( HttpApplication application, HttpRequestMessage request, UrlHelper url, ContentResponse onFound, ViewFileResponse onHtml) { if (request.Headers.Accept.Where(accept => accept.MediaType.ToLower().Contains("html")).Any()) { return(HtmlContent(application, request, url, onHtml)); } LocateControllers(); var endpoints = ManifestController.lookup .Select( type => { var endpoint = url.GetWebId(type, "x-com.orderowl:ordering"); return(endpoint); }) .ToArray(); var manifest = new Resources.Manifest() { Id = Guid.NewGuid(), Endpoints = endpoints, }; return(request.CreateResponse(System.Net.HttpStatusCode.OK, manifest).AsTask()); }
public async Task TestLookupPublicPlaylist() { // Tip: You get your own playlistId by opening your playlist on http://music.xbox.com // If the page is http://music.xbox.com/playlist/great-music/66cd8e9d-802a-00fe-364d-3ead4f82facf // the id is music.playlist.66cd8e9d-802a-00fe-364d-3ead4f82facf . const string playlistId = "music.playlist.0016e20b-80c0-00fe-fac0-1a47365516d1"; // Get playlist contents as viewed from the US ContentResponse playlistUsResponse = await Client.LookupAsync(playlistId, ContentSource.Collection, country : "US").Log(); foreach (var track in playlistUsResponse.Playlists.Items.First().Tracks.Items) { Console.WriteLine(" Track {0} can be {1} in the US", track.Id, String.Join(" and ", track.Rights)); } // Get playlist contents as viewed from Brasil // Note that rights (such as Stream, FreeStream and Purchase) and collection item ids can be country specific ContentResponse playlistBrResponse = await Client.LookupAsync(playlistId, ContentSource.Collection, country : "BR").Log(); foreach (var track in playlistBrResponse.Playlists.Items.First().Tracks.Items) { Console.WriteLine(" Track {0} can be {1} in Brasil", track.Id, String.Join(" and ", track.Rights)); } }
public async Task Test_Lookup_NewReleases() { _content = await _client.LookupNewReleasesAsync(); Assert.IsNotNull(_content.Albums); Assert.IsTrue(_content.Albums.Items.Count > 0); }
private async Task <List <Track> > GetAllTracks() { List <Track> collection = new List <Track>(); bool keepLooping = true; string continuationToken = null; do { ContentResponse response = await _client.BrowseContinuationAsync(MediaNamespace.music, ContentSource.Collection, ItemType.Tracks, continuationToken); if (response.Error == null || response.Error.ErrorCode == Enum.GetName(typeof(ErrorCode), ErrorCode.COLLECTION_INVALID_DATA)) { collection.AddRange(response.Tracks.Items); continuationToken = response.Tracks.ContinuationToken; keepLooping = continuationToken != null; } else { WriteOutputLine($"Error: {response.Error.Description}"); keepLooping = false; } } while (keepLooping); return(collection); }
public static IHttpResponse Options(IHttpRequest request, IProvideUrl url, AzureApplication application, ContentResponse onOption) { return(onOption( GetResource( new EastFive.Azure.Process() { processStageId = Guid.NewGuid(), createdOn = DateTime.UtcNow, processId = Guid.NewGuid(), resourceId = Guid.NewGuid(), resourceType = typeof(EastFive.Azure.ProcessStage), confirmedBy = Guid.NewGuid(), confirmedWhen = DateTime.UtcNow, previousStep = Guid.NewGuid(), resources = Enumerable .Range(0, 3) .Select( i => new EastFive.Azure.Process.ProcessStageResource() { key = $"key{i}", resourceId = Guid.NewGuid(), type = typeof(EastFive.Azure.Process), }) .ToArray(), }, application, url))); }
public async Task Test_Lookup_CategoryPlaylists() { _content = await _client.LookupAsync <ContentResponse>( "pop", LookupType.CategoriesPlaylists); Assert.IsNotNull(_content.Playlists); Assert.IsTrue(_content.Playlists.Count > 0); }
public async Task Test_Search_Album() { _content = await _client.SearchAsync( "Tubular Bells", new SearchType { Album = true }); Assert.IsNotNull(_content.Albums); Assert.IsTrue(_content.Albums.Count > 0); }
public async Task Test_Search_Playlist() { _content = await _client.SearchAsync( "Mike Oldfield", new SearchType { Playlist = true }); Assert.IsNotNull(_content.Playlists); Assert.IsTrue(_content.Playlists.Count > 0); }
private async void GetTracksButton_Click(object sender, EventArgs e) { ContentResponse response = await _client.BrowseAsync(MediaNamespace.music, ContentSource.Collection, ItemType.Tracks, maxItems : 100); _tracks = response.Tracks.Items; TrackListBox.Items.Clear(); _tracks.ForEach(t => TrackListBox.Items.Add(t)); }
private void DisplayMusicContent(ContentResponse contentResponse) { ResetMusicContent(); AddMusicContent(contentResponse?.Tracks?.Items, Tracks); AddMusicContent(contentResponse?.Albums?.Items, Albums); AddMusicContent(contentResponse?.Artists?.Items, Artists); AddMusicContent(contentResponse?.Playlists?.Items, Playlists); }
public async Task TestBrowsePlaylists() { // Get all the user's playlists ContentResponse browseResults = await AuthenticatedClient.BrowseAsync(Namespace.music, ContentSource.Collection, ItemType.Playlists).Log(); Assert.IsNotNull(browseResults, "The browse response should not be null"); AssertPaginatedListIsValid(browseResults.Playlists, 1); }
public async Task GetPageContent_ResultsTakeTwoPages_ShouldReturnAllAndSpecifyDateAlsoSpecifyNextUrl() { // Arrange var date = DateTime.MinValue; var expectedEncodedDate = WebUtility.UrlEncode(date.ToString(CqlDateFormat)); var pageContent = new List <ContentDto> { new ContentDto { Id = "id1", Title = "title1", Body = new ContentBodyDto { View = new ViewRepresentationDto { Value = "body goes here 1" } } }, new ContentDto { Id = "id2", Title = "title2", Body = new ContentBodyDto { View = new ViewRepresentationDto { Value = "body goes here 2" } } } }; var firstPage = new ContentResponse { Links = new LinksDto { Next = "next url request" }, Results = pageContent }; _httpClientMock.Setup(m => m.GetAsync(It.IsAny <string>())) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(firstPage)) }); // Act var result = await _client.GetLatestPagesAsync(new [] { "IH" }, date); // Assert Assert.Equal(result.Results.Count, pageContent.Count); _httpClientMock.Verify(m => m.GetAsync(It.Is <string>(q => q.Contains(expectedEncodedDate))), Times.Once); }
/// <summary> /// The populate response. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="response"> /// The response. /// </param> public override void PopulateResponse(ContentRequest request, ContentResponse response) { response.Content = ContentDao.GetContent(request.ContentId); }
/// <summary> /// The populate response. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="response"> /// The response. /// </param> public override void PopulateResponse(ContentRequest request, ContentResponse response) { response.ContentList = ContentDao.GetContentByCategory(request.CategoryId); }