コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public Task <SoundCloudList <Track> > GetAllAsync(TrackQueryBuilder builder)
        {
            builder.Path  = TrackPath;
            builder.Paged = true;

            return(GetPage <Track>(builder.BuildUri()));
        }
コード例 #4
0
        public async Task <Track> GetAsync(long trackId)
        {
            var builder = new TrackQueryBuilder {
                Path = string.Format(TrackByIdPath, trackId)
            };

            return(await Gateway.SendGetRequestAsync <Track>(builder.BuildUri()));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public void Test_Default()
        {
            var builder = new TrackQueryBuilder();

            var query = builder.BuildUri();

            Assert.That(query.ToString(), Is.EqualTo("https://api.soundcloud.com/?"));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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"));
        }
コード例 #10
0
ファイル: Tracks.cs プロジェクト: rangsutu88/SoundCloud.Api
        public async Task <Track> GetAsync(int trackId)
        {
            EnsureClientId();

            var builder = new TrackQueryBuilder();

            builder.Path = string.Format(TrackByIdPath, trackId);

            return(await GetByIdAsync <Track>(builder.BuildUri()));
        }
コード例 #11
0
ファイル: Tracks.cs プロジェクト: rangsutu88/SoundCloud.Api
        public Track Get(int trackId)
        {
            EnsureClientId();

            var builder = new TrackQueryBuilder();

            builder.Path = string.Format(TrackByIdPath, trackId);

            return(GetById <Track>(builder.BuildUri()));
        }
コード例 #12
0
        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"));
        }
コード例 #13
0
        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()));
        }
コード例 #14
0
        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"));
        }
コード例 #15
0
        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()));
        }
コード例 #16
0
        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()));
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        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"));
        }
コード例 #19
0
ファイル: Tracks.cs プロジェクト: rangsutu88/SoundCloud.Api
        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()));
        }
コード例 #20
0
ファイル: Tracks.cs プロジェクト: rangsutu88/SoundCloud.Api
        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()));
        }
コード例 #21
0
ファイル: Tracks.cs プロジェクト: rangsutu88/SoundCloud.Api
        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));
        }
コード例 #22
0
ファイル: Tracks.cs プロジェクト: rangsutu88/SoundCloud.Api
        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()));
        }
コード例 #23
0
        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"));
        }
コード例 #24
0
        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"));
        }
コード例 #25
0
ファイル: Tracks.cs プロジェクト: rangsutu88/SoundCloud.Api
        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()));
        }
コード例 #26
0
        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"));
        }
コード例 #27
0
ファイル: Tracks.cs プロジェクト: rangsutu88/SoundCloud.Api
        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()));
        }
コード例 #28
0
        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"));
        }
コード例 #29
0
        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"));
        }
コード例 #30
0
        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));
        }