Пример #1
0
        /// <summary>
        /// </summary>
        /// <param name="userCredentials">
        /// </param>
        /// <returns>
        /// </returns>
        public IObservable <UserLoginResponseContract> AuthenticateAsync(UserCredentialsContract userCredentials)
        {
            if (userCredentials == null || string.IsNullOrWhiteSpace(userCredentials.UserName) ||
                string.IsNullOrWhiteSpace(userCredentials.Password))
            {
                return(Observable.Empty <UserLoginResponseContract>());
            }

            // downloader.UserCredentials = null;
            this.downloader.UserToken = null;
            string postData = string.Format(
                "login={0}&password={1}",
                ApiUrl.Escape(userCredentials.UserName),
                ApiUrl.Escape(userCredentials.Password));
            IObservable <UserLoginResponseContract> userLogin =
                from response in this.downloader.PostAndGetStringAsync(ApiUrl.Authenticate(), postData)
                let user = Json <UserLoginResponseContract> .Instance.DeserializeFromString(response)
                               where !string.IsNullOrWhiteSpace(user.UserToken)
                           select user;

            return((from loginResponse in userLogin
                    from _ in this.SaveCredentialsAsync(userCredentials)
                    from __ in this.SaveUserTokenAsync(loginResponse)
                    select loginResponse).Do(
                       response =>
            {
                PlayerService.DeletePlayToken();
                this.downloader.UserToken = response.UserToken;

                // downloader.UserCredentials = userCredentials;
            }));
        }
Пример #2
0
        public static Uri SearchMixes(string query, string sort, int pageNumber, int perPage)
        {
            var urlFormat = string.Format(
                "http://8tracks.com/mixes.json?q={0}&sort={1}&page={2}&per_page={3}&api_version={4}",
                ApiUrl.Escape(query),
                sort,
                pageNumber,
                perPage,
                ApiVersion);

            return(new Uri(urlFormat, UriKind.Absolute));
        }
Пример #3
0
        /// <summary>
        /// </summary>
        /// <param name="mixId">
        /// </param>
        /// <param name="review">
        /// </param>
        /// <returns>
        /// </returns>
        public IObservable <ReviewResponseContract> AddMixReviewAsync(string mixId, string review)
        {
            var    url  = new Uri("http://8tracks.com/reviews", UriKind.Absolute);
            string body = string.Format(
                "review%5Bbody%5D={0}&review%5Bmix_id%5D={1}&format=json", ApiUrl.Escape(review), mixId);

            return(from response in this.downloader.PostStringAndGetDeserializedAsync <ReviewResponseContract>(url, body)
                   from responseWithUser in this.GetUserProfileAsync(response.Review.UserId).Select(
                       userResponse =>
            {
                if (response.Review.User == null)
                {
                    response.Review.User = userResponse.User;
                }

                return response;
            })
                   select responseWithUser);
        }