Ejemplo n.º 1
0
		static void Main(string[] args)
		{
			string firstArg;
			if (args.Length < 1)
			{
				firstArg = "1";
			}
			else
			{
				firstArg = args[0];
			}
			var artistId = Convert.ToInt32(firstArg);

			var appSettingsCredentials = new AppSettingsCredentials();
			var apiUri = new ApiUri();

			var api = new ApiFactory(apiUri, appSettingsCredentials);
			Console.WriteLine("Using creds: {0} - {1}", appSettingsCredentials.ConsumerKey, appSettingsCredentials.ConsumerSecret);

			// console apps can't have an async main method, so we have to call an async method 
			var task = Use7DigitalApi(api, artistId);
			task.Wait();

			Console.ReadKey();
		}
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var s        = args[0];
            var artistId = Convert.ToInt32(s);

            var appSettingsCredentials = new AppSettingsCredentials();

            Console.WriteLine("Using creds: {0} - {1}", appSettingsCredentials.ConsumerKey, appSettingsCredentials.ConsumerSecret);

            // console apps can't have an async main, so we have to deal with that
            var task = Use7DigitalApi(artistId);

            task.Wait();

            Console.ReadKey();
        }
		static void Main(string[] args)
		{
			string s = args[0];

			var appSettingsCredentials = new AppSettingsCredentials();
			Console.WriteLine("Using creds: {0} - {1}", appSettingsCredentials.ConsumerKey, appSettingsCredentials.ConsumerSecret);

			// -- artist/details
			var artist = Api<Artist>.Create
				.WithArtistId(Convert.ToInt32(s))
				.Please();

			Console.WriteLine("Artist \"{0}\" selected", artist.Name);
			Console.WriteLine("Website url is {0}", artist.Url);
			Console.WriteLine();


			// -- artist/toptracks
			var artistTopTracks = Api<ArtistTopTracks>
				.Create
				.WithArtistId(Convert.ToInt32(s))
				.Please();

			Console.WriteLine("Top Track: {0}", artistTopTracks.Tracks.FirstOrDefault().Title);
			Console.WriteLine();

			// -- artist/browse
			const string searchValue = "Radio";
			var artistBrowse = Api<ArtistBrowse>
				.Create
				.WithLetter(searchValue)
				.Please();

			Console.WriteLine("Browse on \"{0}\" returns: {1}", searchValue, artistBrowse.Artists.FirstOrDefault().Name);
			Console.WriteLine();

			// -- artist/search
			var artistSearch = Api<ArtistSearch>.Create
				.WithQuery(searchValue)
				.WithPageNumber(1)
				.WithPageSize(10)
				.Please();

			Console.WriteLine("Artist Search on \"{0}\" returns: {1} items", searchValue, artistSearch.TotalItems);
			Console.WriteLine();

			// -- artist/search parallel 

			var requestor = new FluentApiRequestor<ArtistSearch>(() => new FluentApi<ArtistSearch>(new RequestCoordinator(new GzipHttpClient(), new UrlSigner(), new AppSettingsCredentials(), new ApiUri())));

			Parallel.For(1, 10, i =>
			{
				var result = requestor.Request(x =>
				{
					x.WithQuery("keane");
					x.WithPageNumber(i);
					x.WithPageSize(1);
				});
				Console.WriteLine(i + " >> " + result.Results.First().Artist.Name);
			});

			// -- release/search
			var releaseSearch = Api<ReleaseSearch>.Create
				.WithQuery(searchValue)
				.WithPageNumber(1)
				.WithPageSize(10)
				.Please();

			Console.WriteLine("Release search on \"{0}\" returns: {1} items", searchValue, releaseSearch.TotalItems);
			Console.WriteLine();

			// -- Debug uri
			string currentUri = Api<ReleaseSearch>.Create.WithQuery("Test").EndpointUrl;
			Console.WriteLine("Release search hits: {0}", currentUri);

			// -- async get (async post not implemented yet)
			Api<ReleaseSearch>.Create
				.WithQuery(searchValue)
				.WithPageNumber(1)
				.WithPageSize(10)
				.PleaseAsync(x =>
				{
					Console.WriteLine("Async Release search on \"{0}\" returns: {1} items", "Radio", x.TotalItems);
					Console.WriteLine();
				});

			try
			{
				// -- Deliberate error response
				Console.WriteLine("Trying artist/details without artistId parameter...");
				Api<Artist>.Create.Please();
			}
			catch (ApiException ex)
			{
				Console.WriteLine("{0} : {1}", ex, ex.Message);
			}

			try
			{
				// -- Deliberate unauthorized response
				Console.WriteLine("Trying user/locker without any credentials...");
				Api<Locker>.Create.Please();
			}
			catch (ApiException ex)
			{
				Console.WriteLine("{0} : {1}", ex, ex.Message);
			}

			Console.ReadKey();
		}
Ejemplo n.º 4
0
		static void Main(string[] args) {
			string s = args[0];

			var appSettingsCredentials = new AppSettingsCredentials();
			Console.WriteLine("Using creds: {0} - {1}", appSettingsCredentials.ConsumerKey, appSettingsCredentials.ConsumerSecret);

			// -- artist/details
			var artist = Api<Artist>.Get
				.WithArtistId(Convert.ToInt32(s))
				.Please();

			Console.WriteLine("Artist \"{0}\" selected", artist.Name);
			Console.WriteLine("Website url is {0}", artist.Url);
			Console.WriteLine();


			// -- artist/toptracks
			var artistTopTracks = Api<ArtistTopTracks>
				.Get
				.WithArtistId(Convert.ToInt32(s))
				.Please();

			Console.WriteLine("Top Track: {0}", artistTopTracks.Tracks.FirstOrDefault().Title);
			Console.WriteLine();
			
			// -- artist/browse
			const string searchValue = "Radio";
			var artistBrowse = Api<ArtistBrowse>
				.Get
				.WithLetter(searchValue)
				.Please();

			Console.WriteLine("Browse on \"{0}\" returns: {1}", searchValue, artistBrowse.Artists.FirstOrDefault().Name);
			Console.WriteLine();

			// -- artist/search
			var artistSearch = Api<ArtistSearch>.Get
				.WithQuery(searchValue)
				.WithPageNumber(1)
				.WithPageSize(10)
				.Please();

			Console.WriteLine("Artist Search on \"{0}\" returns: {1} items", searchValue, artistSearch.TotalItems);
			Console.WriteLine();

			// -- release/search
			var releaseSearch = Api<ReleaseSearch>.Get
				.WithQuery(searchValue)
				.WithPageNumber(1)
				.WithPageSize(10)
				.Please();

			Console.WriteLine("Release search on \"{0}\" returns: {1} items", searchValue, releaseSearch.TotalItems);
			Console.WriteLine();

			// -- Debug uri
			string currentUri = Api<ReleaseSearch>.Get.WithQuery("Test").GetCurrentUri();
			Console.WriteLine("Release search hits: {0}", currentUri);

			// -- async get (async post not implemented yet)
			Api<ReleaseSearch>.Get
				.WithQuery(searchValue)
				.WithPageNumber(1)
				.WithPageSize(10)
				.PleaseAsync(x => {
					Console.WriteLine("Async Release search on \"{0}\" returns: {1} items", "Radio", x.TotalItems);
					Console.WriteLine();
				 });

			try {
				// -- Deliberate error response
				Console.WriteLine("Trying artist/details without artistId parameter...");
				Api<Artist>.Get.Please();
			} catch (ApiXmlException ex) {
				Console.WriteLine("{0} : {1}", ex.Error.Code, ex.Error.ErrorMessage);
			}

			try {
				// -- Deliberate unauthorized response
				Console.WriteLine("Trying user/locker without any credentials...");
				Api<Locker>.Get.Please();
			} catch (ApiXmlException ex) {
				Console.WriteLine("{0} : {1}", ex.Error.Code, ex.Error.ErrorMessage);
			}

			Console.ReadKey();
		}
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            string s = args[0];

            var appSettingsCredentials = new AppSettingsCredentials();

            Console.WriteLine("Using creds: {0} - {1}", appSettingsCredentials.ConsumerKey, appSettingsCredentials.ConsumerSecret);

            // -- artist/details
            var artist = Api <Artist> .Create
                         .WithArtistId(Convert.ToInt32(s))
                         .Please();

            Console.WriteLine("Artist \"{0}\" selected", artist.Name);
            Console.WriteLine("Website url is {0}", artist.Url);
            Console.WriteLine();


            // -- artist/toptracks
            var artistTopTracks = Api <ArtistTopTracks>
                                  .Create
                                  .WithArtistId(Convert.ToInt32(s))
                                  .Please();

            Console.WriteLine("Top Track: {0}", artistTopTracks.Tracks.FirstOrDefault().Title);
            Console.WriteLine();

            // -- artist/browse
            const string searchValue  = "Radio";
            var          artistBrowse = Api <ArtistBrowse>
                                        .Create
                                        .WithLetter(searchValue)
                                        .Please();

            Console.WriteLine("Browse on \"{0}\" returns: {1}", searchValue, artistBrowse.Artists.FirstOrDefault().Name);
            Console.WriteLine();

            // -- artist/search
            var artistSearch = Api <ArtistSearch> .Create
                               .WithQuery(searchValue)
                               .WithPageNumber(1)
                               .WithPageSize(10)
                               .Please();

            Console.WriteLine("Artist Search on \"{0}\" returns: {1} items", searchValue, artistSearch.TotalItems);
            Console.WriteLine();

            // -- release/search
            var releaseSearch = Api <ReleaseSearch> .Create
                                .WithQuery(searchValue)
                                .WithPageNumber(1)
                                .WithPageSize(10)
                                .Please();

            Console.WriteLine("Release search on \"{0}\" returns: {1} items", searchValue, releaseSearch.TotalItems);
            Console.WriteLine();

            // -- Debug uri
            string currentUri = Api <ReleaseSearch> .Create.WithQuery("Test").EndpointUrl;

            Console.WriteLine("Release search hits: {0}", currentUri);

            // -- async get (async post not implemented yet)
            Api <ReleaseSearch> .Create
            .WithQuery(searchValue)
            .WithPageNumber(1)
            .WithPageSize(10)
            .PleaseAsync(x => {
                Console.WriteLine("Async Release search on \"{0}\" returns: {1} items", "Radio", x.TotalItems);
                Console.WriteLine();
            });

            try
            {
                // -- Deliberate error response
                Console.WriteLine("Trying artist/details without artistId parameter...");
                Api <Artist> .Create.Please();
            }
            catch (ApiException ex)
            {
                Console.WriteLine("{0} : {1}", ex, ex.Message);
            }

            try
            {
                // -- Deliberate unauthorized response
                Console.WriteLine("Trying user/locker without any credentials...");
                Api <Locker> .Create.Please();
            }
            catch (ApiException ex)
            {
                Console.WriteLine("{0} : {1}", ex, ex.Message);
            }

            Console.ReadKey();
        }