public void Test_Tracks_Get_With_Bpm_And_Tag_Query() { const string expectedUri = @"https://api.soundcloud.com/tracks?limit=200&bpm[from]=100&tags=house&linked_partitioning=1&client_id=myClientId"; var trackList = new PagedResult <Track>(); trackList.collection = new List <Track> { new Track(), new Track() }; var response = new ApiResponse <PagedResult <Track> >(HttpStatusCode.OK, "OK"); response.Data = trackList; var gatewayMock = new Mock <ISoundCloudApiGateway>(MockBehavior.Strict); gatewayMock.Setup(x => x.InvokeGetRequest <PagedResult <Track> >(It.Is <Uri>(y => y.ToString() == expectedUri))).Returns(response); var trackEndpoint = new Tracks(gatewayMock.Object); trackEndpoint.Credentials.ClientId = ClientId; var query = new TrackQueryBuilder(); query.BpmFrom = 100; query.Tags.Add("house"); var result = trackEndpoint.Get(query).ToList(); Assert.That(result, Is.EqualTo(trackList.collection)); }
public async override Task <SearchResponse> Search(SearchRequest request, ServerCallContext context) { // Check if parameters fulfill our basic requirements if (string.IsNullOrWhiteSpace(request.Query)) { return(SearchFailure("query is empty")); } // Search for tracks var builder = new TrackQueryBuilder { SearchString = request.Query, Limit = 50, Sharing = Sharing.Public }; SoundCloudList <Track> tracks = await client.Tracks.GetAllAsync(builder); var response = new SearchResponse { Status = new ResponseStatus { Success = true } }; response.Items.AddRange( tracks.Select(track => new SearchResponseItem { Id = track.Id.ToString(), Title = track.Title, Duration = track.Duration / 1000, })); return(response); }
public Task <SoundCloudList <Track> > GetAllAsync(TrackQueryBuilder builder) { builder.Path = TrackPath; builder.Paged = true; return(GetPage <Track>(builder.BuildUri())); }
public async Task <Track> GetAsync(long trackId) { var builder = new TrackQueryBuilder { Path = string.Format(TrackByIdPath, trackId) }; return(await Gateway.SendGetRequestAsync <Track>(builder.BuildUri())); }
public void Test_Limit([Values(1, 2, 100, 199, 200)] int limit) { var builder = new TrackQueryBuilder { Limit = limit }; Assert.That(builder.Limit, Is.EqualTo(limit)); }
public void Test_Default() { var builder = new TrackQueryBuilder(); var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?")); }
public void Test_Limit_MaxValue([Values(201, 202, 300, 400)] int limit) { var builder = new TrackQueryBuilder { Limit = limit }; Assert.That(builder.Limit, Is.EqualTo(200)); }
public void Test_Limit_MinValue([Values(0, -1, -200, -300)] int limit) { var builder = new TrackQueryBuilder { Limit = limit }; Assert.That(builder.Limit, Is.EqualTo(1)); }
public void Test_SearchString() { var builder = new TrackQueryBuilder(); builder.SearchString = "major lazer"; var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?q=major lazer")); }
public async Task <Track> GetAsync(int trackId) { EnsureClientId(); var builder = new TrackQueryBuilder(); builder.Path = string.Format(TrackByIdPath, trackId); return(await GetByIdAsync <Track>(builder.BuildUri())); }
public Track Get(int trackId) { EnsureClientId(); var builder = new TrackQueryBuilder(); builder.Path = string.Format(TrackByIdPath, trackId); return(GetById <Track>(builder.BuildUri())); }
public void Test_Sharing() { var builder = new TrackQueryBuilder(); builder.Sharing = Sharing.Private; var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?filter=private")); }
public async Task <StatusResponse> DeleteAsync(Track track) { track.ValidateDelete(); var builder = new TrackQueryBuilder { Path = string.Format(TrackByIdPath, track.Id) }; return(await Gateway.SendDeleteRequestAsync <StatusResponse>(builder.BuildUri())); }
public void Test_License() { var builder = new TrackQueryBuilder(); builder.License = License.CcBy; var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?license=cc-by")); }
public Task <SoundCloudList <User> > GetFavoritersAsync(Track track, int limit = SoundCloudQueryBuilder.MaxLimit) { track.ValidateGet(); var builder = new TrackQueryBuilder { Path = string.Format(TrackFavoritersPath, track.Id), Paged = true, Limit = limit }; return(GetPage <User>(builder.BuildUri())); }
public async Task <SecretToken> GetSecretTokenAsync(Track track) { track.ValidateGet(); var builder = new TrackQueryBuilder { Path = string.Format(TrackSecretTokenPath, track.Id) }; return(await Gateway.SendGetRequestAsync <SecretToken>(builder.BuildUri())); }
public async Task <Track> UpdateAsync(Track track) { track.ValidateUpdate(); var builder = new TrackQueryBuilder { Path = string.Format(TrackByIdPath, track.Id) }; return(await Gateway.SendPutRequestAsync <Track>(builder.BuildUri(), track)); }
public void Test_Bpm() { var builder = new TrackQueryBuilder(); builder.BpmFrom = 100; builder.BpmTo = 120; var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?bpm[from]=100&bpm[to]=120")); }
public SecretToken GetSecretToken(Track track) { EnsureToken(); Validate(track.ValidateGet); var builder = new TrackQueryBuilder(); builder.Path = string.Format(TrackSecretTokenPath, track.id); return(GetById <SecretToken>(builder.BuildUri())); }
public async Task <SecretToken> GetSecretTokenAsync(Track track) { EnsureToken(); Validate(track.ValidateGet); var builder = new TrackQueryBuilder(); builder.Path = string.Format(TrackSecretTokenPath, track.id); return(await GetByIdAsync <SecretToken>(builder.BuildUri())); }
public IWebResult <Track> Update(Track track) { EnsureToken(); Validate(track.ValidateUpdate); var builder = new TrackQueryBuilder(); builder.Path = string.Format(TrackByIdPath, track.id); return(Update <Track>(builder.BuildUri(), track)); }
public async Task <IWebResult> DeleteAsync(Track track) { EnsureToken(); Validate(track.ValidateDelete); var builder = new TrackQueryBuilder(); builder.Path = string.Format(TrackByIdPath, track.id); return(await DeleteAsync(builder.BuildUri())); }
public void Test_Duration() { var builder = new TrackQueryBuilder(); builder.DurationFrom = 100; builder.DurationTo = 200; var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?duration[from]=100&duration[to]=200")); }
public void Test_CreatedFromTo() { var builder = new TrackQueryBuilder(); builder.CreatedAtFrom = new DateTime(2015, 01, 02, 03, 04, 05); builder.CreatedAtTo = new DateTime(2015, 06, 07, 08, 09, 10); var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?created_at[from]=2015-01-02 03:04:05&created_at[to]=2015-06-07 08:09:10")); }
public IEnumerable <User> GetFavoriters(Track track) { EnsureClientId(); Validate(track.ValidateGet); var builder = new TrackQueryBuilder(); builder.Path = string.Format(TrackFavoritersPath, track.id); builder.Paged = true; return(GetList <User>(builder.BuildUri())); }
public void Test_TrackTypes() { var builder = new TrackQueryBuilder(); builder.TrackTypes.Add(TrackType.Demo); builder.TrackTypes.Add(TrackType.InProgress); builder.TrackTypes.Add(TrackType.Live); var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?types=demo%2Cin progress%2Clive")); }
public async Task <IEnumerable <Comment> > GetCommentsAsync(Track track) { EnsureClientId(); Validate(track.ValidateGet); var builder = new TrackQueryBuilder(); builder.Path = string.Format(TrackCommentsPath, track.id); builder.Paged = true; return(await GetListAsync <Comment>(builder.BuildUri())); }
public void Test_Genres() { var builder = new TrackQueryBuilder(); builder.Genres.Add("pop"); builder.Genres.Add("rap"); builder.Genres.Add("house"); var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?genres=pop%2Crap%2Chouse")); }
public void Test_Ids() { var builder = new TrackQueryBuilder(); builder.Ids.Add(1); builder.Ids.Add(2); builder.Ids.Add(3); var query = builder.BuildUri(); Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?ids=1%2C2%2C3")); }
public async Task <Track> UploadArtworkAsync(Track track, Stream file) { track.ValidateUploadArtwork(); var parameters = new Dictionary <string, object> { { TrackArtworkDataKey, file } }; var builder = new TrackQueryBuilder { Path = string.Format(TrackByIdPath, track.Id) }; return(await Gateway.SendPutRequestAsync <Track>(builder.BuildUri(), parameters)); }