public Task <CardsResponse> GetUserContributionsAsync(int page, int count)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            return(_restTemplate.GetForObjectAsync <CardsResponse>(BuildUrl("user/contribs", parameters)));
        }
Example #2
0
        private void RefreshMovies()
        {
            MovieToCreate = new MovieModel();

#if SILVERLIGHT_4
            template.GetForObjectAsync <IEnumerable <MovieModel> >("movies",
                                                                   r =>
            {
                if (r.Error == null)
                {
                    Movies = new ObservableCollection <MovieModel>(r.Response);
                }
            });
#else
            // Using Task Parallel Library (TPL)
            template.GetForObjectAsync <IEnumerable <MovieModel> >("movies")
            .ContinueWith(task =>
            {
                if (!task.IsFaulted)
                {
                    Movies = new ObservableCollection <MovieModel>(task.Result);
                }
            }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());     // execute on UI thread
#endif
        }
        public Task <FollowingResponse> GetUserFollowingAsync(int page, int count)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            return(_restTemplate.GetForObjectAsync <FollowingResponse>(BuildUrl("user/following", parameters)));
        }
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            // Note that you can also use the NJsonHttpMessageConverter based on Json.NET library
            // that supports getting/setting values from JSON directly,
            // without the need to deserialize/serialize to a .NET class.

            IHttpMessageConverter jsonConverter = new DataContractJsonHttpMessageConverter();
            jsonConverter.SupportedMediaTypes.Add(new MediaType("text", "javascript"));

            RestTemplate template = new RestTemplate();
            template.MessageConverters.Add(jsonConverter);

            #if NET_3_5
            template.GetForObjectAsync<GImagesResponse>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}",
                r =>
                {
                    if (r.Error == null)
                    {
                        this.ResultsItemsControl.ItemsSource = r.Response.Data.Items;
                    }
                }, this.SearchTextBox.Text);
            #else
            // Using Task Parallel Library (TPL)
            var uiScheduler = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();
            template.GetForObjectAsync<GImagesResponse>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}", this.SearchTextBox.Text)
                .ContinueWith(task =>
                {
                    if (!task.IsFaulted)
                    {
                        this.ResultsItemsControl.ItemsSource = task.Result.Data.Items;
                    }
                }, uiScheduler); // execute on UI thread
            #endif
        }
Example #5
0
        public Task <ActivitiesResponse> GetUserActivitiesAsync(int page, int count)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            return(_restTemplate.GetForObjectAsync <ActivitiesResponse>(BuildUrl("user/activity", parameters)));
        }
Example #6
0
 public void GetPublicTimelineAsync(Action <IList <Tweet> > operationCompleted)
 {
     restTemplate.GetForObjectAsync <JsonValue>(PUBLIC_TIMELINE_URL,
                                                r =>
     {
         IList <Tweet> tweets = ExtractTimelineTweetsFromResponse(r.Response);
         operationCompleted(tweets);
     });
 }
Example #7
0
        public Task <ActivitiesResponse> GetUserActivitiesAsync(int page, int count, ActivityType type)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            if (type != ActivityType.All)
            {
                parameters.Add("type", type.ToString().ToLower());
            }
            return(_restTemplate.GetForObjectAsync <ActivitiesResponse>(BuildUrl("user/activity", parameters)));
        }
        public Task <CardsResponse> GetUserCardsAsync(int page, int count, bool featured = false)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            if (featured)
            {
                parameters.Add(new NameValueCollection {
                    { "featured", featured.ToString() }
                });
            }
            return(_restTemplate.GetForObjectAsync <CardsResponse>(BuildUrl("user/cards", parameters)));
        }
Example #9
0
        /// <summary>
        /// 获取反面模板列表
        /// </summary>
        /// <param name="success"></param>
        /// <param name="failure"></param>
        public static void GetBackStyleTemplateList(Success <List <BackStyleResponse> > success, Failure failure = null)
        {
            var restTemplate = new RestTemplate();

            restTemplate.MessageConverters.Add(new NJsonHttpMessageConverter());

            restTemplate.GetForObjectAsync <BodyResponse <Page <BackStyleResponse> > >(Resources.backStyleListUrl, response =>
            {
                if (response.Error != null)
                {
                    failure?.Invoke(response.Error.Message);
                }
                else
                {
                    if (response.Response.Code > 0)
                    {
                        success?.Invoke(response.Response.Data.Detail);
                    }
                    else
                    {
                        failure?.Invoke(response.Response.Message);
                    }
                }
            });
        }
Example #10
0
        public static void GetOrderInfo(string orderId, Success <OrderResponse> success, Failure failure = null)
        {
            var restTemplate = new RestTemplate();

            restTemplate.MessageConverters.Add(new NJsonHttpMessageConverter());
            var nameValueCollection = new Dictionary <string, object>
            {
                { "orderId", orderId }
            };

            restTemplate.GetForObjectAsync <BodyResponse <OrderResponse> >(Resources.getOrderInfoUrl, nameValueCollection, respon =>
            {
                if (respon.Error != null)
                {
                    failure?.Invoke(respon.Error.Message);
                }
                else if (respon.Response.Code > 0)
                {
                    success?.Invoke(respon.Response.Data);
                }
                else
                {
                    failure?.Invoke(respon.Response.Message);
                }
            });
        }
Example #11
0
        /// <summary>
        /// 根据ID获取明信片集合详细信息
        /// </summary>
        /// <param name="envelopeId">明信片集合ID</param>
        /// <param name="success">成功回调函数</param>
        /// <param name="failure">失败回调函数</param>
        public static void GetEnvelopeInfoById(string envelopeId, Success <EnvelopeResponse> success, Failure failure = null)
        {
            var restTemplate = new RestTemplate();

            restTemplate.MessageConverters.Add(new NJsonHttpMessageConverter());

            var nameValueCollection = new Dictionary <string, object>
            {
                { "envelopeId", envelopeId }
            };

            restTemplate.GetForObjectAsync <BodyResponse <EnvelopeResponse> >(
                Resources.envelopeInfoUrl, nameValueCollection, headCompleted =>
            {
                if (headCompleted.Error != null)
                {
                    failure?.Invoke(headCompleted.Error.Message);
                }
                else
                {
                    if (headCompleted.Response.Code < 0)
                    {
                        failure?.Invoke(headCompleted.Response.Message);
                        return;
                    }
                    success?.Invoke(headCompleted.Response.Data);
                }
            });
        }
Example #12
0
        /// <summary>
        /// 根据明信片集合ID获取明信片集合中的所有明信片
        /// </summary>
        /// <param name="envelopeId">明信片集合ID</param>
        /// <param name="success">成功回调函数</param>
        /// <param name="failure">失败回调函数</param>
        public static void GetPostCardByEnvelopeId(string envelopeId, Success <List <PostCardResponse> > success, Failure failure = null)
        {
            var restTemplate = new RestTemplate();

            restTemplate.MessageConverters.Add(new NJsonHttpMessageConverter());

            var nameValueCollection = new Dictionary <string, object>
            {
                { "envelopeId", envelopeId }
            };

            restTemplate.GetForObjectAsync <BodyResponse <Page <PostCardResponse> > >(
                Resources.getPostCardByEnvelopeIdUrl, nameValueCollection,
                resp =>
            {
                if (resp.Error != null)
                {
                    failure?.Invoke(resp.Error.Message);
                    return;
                }
                if (resp.Response.Code < 0)
                {
                    failure?.Invoke(resp.Response.Message);
                    return;
                }
                success?.Invoke(resp.Response.Data.Detail);
            });
        }
Example #13
0
        /// <summary>
        /// 根据订单ID获取所有明信片集合
        /// </summary>
        /// <param name="orderId">订单ID</param>
        /// <param name="success">获取成功的响应结果</param>
        /// <param name="failure">获取失败的响应结果</param>
        public static void GetAllEnvelopeByOrderId(string orderId, Success <List <EnvelopeResponse> > success, Failure failure = null)
        {
            var restTemplate = new RestTemplate();

            restTemplate.MessageConverters.Add(new NJsonHttpMessageConverter());

            var nameValueCollection = new Dictionary <string, object>
            {
                { "orderId", orderId }
            };

            restTemplate.GetForObjectAsync <BodyResponse <Page <EnvelopeResponse> > >(Resources.getAllEnvelopeByOrderIdUrl, nameValueCollection,
                                                                                      resp =>
            {
                if (resp.Error != null)
                {
                    failure?.Invoke(resp.Error.Message);
                }
                else
                {
                    if (resp.Response.Code > 0)
                    {
                        success?.Invoke(resp.Response.Data.Detail);
                    }
                    else
                    {
                        failure?.Invoke(resp.Response.Message);
                    }
                }
            });
        }
Example #14
0
        public string SearchEmployees()
        {
            RestTemplate _RestTemplate = StartTemplate();

            string response = _RestTemplate.GetForObjectAsync <string>(ClientHelper.UrlSearchEmployeess).Result;

            return(response);
        }
Example #15
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            this.ResultsFlowLayoutPanel.Controls.Clear();

            IHttpMessageConverter njsonConverter = new NJsonHttpMessageConverter();

            njsonConverter.SupportedMediaTypes.Add(new MediaType("text", "javascript"));

            RestTemplate template = new RestTemplate();

            template.MessageConverters.Add(njsonConverter);

            template.GetForObjectAsync <JToken>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}",
                                                delegate(RestOperationCompletedEventArgs <JToken> r)
            {
                if (r.Error == null)
                {
                    foreach (JToken jToken in r.Response.Value <JToken>("responseData").Value <JArray>("results"))
                    {
                        PictureBox pBox    = new PictureBox();
                        pBox.ImageLocation = jToken.Value <string>("tbUrl");
                        pBox.Height        = jToken.Value <int>("tbHeight");
                        pBox.Width         = jToken.Value <int>("tbWidth");

                        ToolTip tt = new ToolTip();
                        tt.SetToolTip(pBox, jToken.Value <string>("visibleUrl"));

                        this.ResultsFlowLayoutPanel.Controls.Add(pBox);
                    }
                }
            }, this.SearchTextBox.Text);

            /*
             * template.GetForObjectAsync<GImagesResponse>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}",
             *  delegate(RestOperationCompletedEventArgs<GImagesResponse> r)
             *  {
             *      if (r.Error == null)
             *      {
             *          foreach (GImage gImage in r.Response.Data.Items)
             *          {
             *              PictureBox pBox = new PictureBox();
             *              pBox.ImageLocation = gImage.ThumbnailUrl;
             *              pBox.Height = gImage.ThumbnailHeight;
             *              pBox.Width = gImage.ThumbnailWidth;
             *
             *              ToolTip tt = new ToolTip();
             *              tt.SetToolTip(pBox, gImage.SiteUrl);
             *
             *              this.ResultsFlowLayoutPanel.Controls.Add(pBox);
             *          }
             *      }
             *  }, this.SearchTextBox.Text);
             */
        }
Example #16
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            this.ResultsFlowLayoutPanel.Controls.Clear();

            IHttpMessageConverter njsonConverter = new NJsonHttpMessageConverter();
            njsonConverter.SupportedMediaTypes.Add(new MediaType("text", "javascript"));

            RestTemplate template = new RestTemplate();
            template.MessageConverters.Add(njsonConverter);

            template.GetForObjectAsync<JToken>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}",
                delegate(RestOperationCompletedEventArgs<JToken> r)
                {
                    if (r.Error == null)
                    {
                        foreach (JToken jToken in r.Response.Value<JToken>("responseData").Value<JArray>("results"))
                        {
                            PictureBox pBox = new PictureBox();
                            pBox.ImageLocation = jToken.Value<string>("tbUrl");
                            pBox.Height = jToken.Value<int>("tbHeight");
                            pBox.Width = jToken.Value<int>("tbWidth");

                            ToolTip tt = new ToolTip();
                            tt.SetToolTip(pBox, jToken.Value<string>("visibleUrl"));

                            this.ResultsFlowLayoutPanel.Controls.Add(pBox);
                        }
                    }
                }, this.SearchTextBox.Text);

            /*
            template.GetForObjectAsync<GImagesResponse>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}",
                delegate(RestOperationCompletedEventArgs<GImagesResponse> r)
                {
                    if (r.Error == null)
                    {
                        foreach (GImage gImage in r.Response.Data.Items)
                        {
                            PictureBox pBox = new PictureBox();
                            pBox.ImageLocation = gImage.ThumbnailUrl;
                            pBox.Height = gImage.ThumbnailHeight;
                            pBox.Width = gImage.ThumbnailWidth;

                            ToolTip tt = new ToolTip();
                            tt.SetToolTip(pBox, gImage.SiteUrl);

                            this.ResultsFlowLayoutPanel.Controls.Add(pBox);
                        }
                    }
                }, this.SearchTextBox.Text);
            */
        }
Example #17
0
        static void Main(string[] args)
        {
            try
            {
                // Configure RestTemplate by adding the new converter to the default list
                RestTemplate template = new RestTemplate();
                template.MessageConverters.Add(new ImageHttpMessageConverter());

                // Get image from url
#if NET_4_0
                Bitmap nuGetLogo = template.GetForObjectAsync<Bitmap>("http://nuget.org/Content/Images/nugetlogo.png").Result;
#else
                Bitmap nuGetLogo = template.GetForObject<Bitmap>("http://nuget.org/Content/Images/nugetlogo.png");
#endif

                // Save image to disk
                string filename = Path.Combine(Environment.CurrentDirectory, "NuGetLogo.png");
                nuGetLogo.Save(filename);
                Console.WriteLine(String.Format("Saved NuGet logo to '{0}'", filename));
            }
#if NET_4_0
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                {
                    if (ex is HttpResponseException)
                    {
                        Console.WriteLine(((HttpResponseException)ex).GetResponseBodyAsString());
                        return true;
                    }
                    return false;
                });
            }
#else
            catch (HttpResponseException ex)
            {
                Console.WriteLine(ex.GetResponseBodyAsString());
            }
#endif
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
			finally
			{
				Console.WriteLine("--- hit <return> to quit ---");
				Console.ReadLine();
			}
        }
Example #18
0
        static void Main(string[] args)
        {
            try
            {
                // Configure RestTemplate by adding the new converter to the default list
                RestTemplate template = new RestTemplate();
                template.MessageConverters.Add(new ImageHttpMessageConverter());

                // Get image from url
#if NET_4_0
                Bitmap nuGetLogo = template.GetForObjectAsync <Bitmap>("http://nuget.org/Content/Images/nugetlogo.png").Result;
#else
                Bitmap nuGetLogo = template.GetForObject <Bitmap>("http://nuget.org/Content/Images/nugetlogo.png");
#endif

                // Save image to disk
                string filename = Path.Combine(Environment.CurrentDirectory, "NuGetLogo.png");
                nuGetLogo.Save(filename);
                Console.WriteLine(String.Format("Saved NuGet logo to '{0}'", filename));
            }
#if NET_4_0
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                {
                    if (ex is HttpResponseException)
                    {
                        Console.WriteLine(((HttpResponseException)ex).GetResponseBodyAsString());
                        return(true);
                    }
                    return(false);
                });
            }
#else
            catch (HttpResponseException ex)
            {
                Console.WriteLine(ex.GetResponseBodyAsString());
            }
#endif
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine("--- hit <return> to quit ---");
                Console.ReadLine();
            }
        }
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            // Note that you can also use the NJsonHttpMessageConverter based on Json.NET library
            // that supports getting/setting values from JSON directly,
            // without the need to deserialize/serialize to a .NET class.

            IHttpMessageConverter jsonConverter = new DataContractJsonHttpMessageConverter();

            jsonConverter.SupportedMediaTypes.Add(new MediaType("text", "javascript"));

            RestTemplate template = new RestTemplate();

            template.MessageConverters.Add(jsonConverter);

#if NET_3_5
            template.GetForObjectAsync <GImagesResponse>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}",
                                                         r =>
            {
                if (r.Error == null)
                {
                    this.ResultsItemsControl.ItemsSource = r.Response.Data.Items;
                }
            }, this.SearchTextBox.Text);
#else
            // Using Task Parallel Library (TPL)
            var uiScheduler = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();
            template.GetForObjectAsync <GImagesResponse>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}", this.SearchTextBox.Text)
            .ContinueWith(task =>
            {
                if (!task.IsFaulted)
                {
                    this.ResultsItemsControl.ItemsSource = task.Result.Data.Items;
                }
            }, uiScheduler);     // execute on UI thread
#endif
        }
Example #20
0
        public Task <ContributionCollection> GetContributionsAsync(int page = 1, int perPage = 20, string domain = "", DateTime?since = null, DateTime?until = null)
        {
            EnsureIsAuthorized();
            var parameters = new NameValueCollection();

            if (since.HasValue)
            {
                parameters.Add("since", since.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (until.HasValue)
            {
                parameters.Add("until", until.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (!String.IsNullOrEmpty(domain))
            {
                parameters.Add("domain", domain);
            }
            parameters.Add("page", page.ToString(CultureInfo.InvariantCulture));
            parameters.Add("per_page", perPage.ToString(CultureInfo.InvariantCulture));
            return(_restTemplate.GetForObjectAsync <ContributionCollection>(BuildUrl("contributions", parameters)));
        }
        protected override void OnActivate()
        {
            base.OnActivate();

            RestTemplate template = new RestTemplate(Api.Host);
            template.MessageConverters.Add(new NJsonHttpMessageConverter());

            var body = new GetRiddlesRequest();
            HttpEntity entity = new HttpEntity(body);
            entity.Headers.Add("X-Auth-Token", _registrationService.GetToken());

            template.GetForObjectAsync<GetRiddlesResponse>("/riddles", r =>
            {
                if(r.Error == null)
                {
                    Execute.OnUIThread( () =>
                    {
                        RiddleListView view = (RiddleListView)GetView();
                        ListBox riddlesList = view.riddles;
                        foreach (var riddle in r.Response.riddles)
                        {
                            StackPanel panel = new StackPanel();
                            panel.Children.Add(new TextBlock() {Text = riddle.author});

                            Image img = new Image();
                            panel.Children.Add(img);
                            panel.Tap += OnRiddleTap;
                            panel.Tag = riddle;

                            riddlesList.Items.Add(panel);

                            DownloadImage(img, riddle.photo_url);

                        }
                    } );
                }
            });
        }
Example #22
0
 public Task <User> GetUserAsync()
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObjectAsync <User>("users/_current"));
 }
		public Task<MicrosResponse> GetUserMicrosAsync(int page, int count)
		{
			EnsureIsAuthorized();
			var parameters = BuildPagingParametersWithCount(page, count);
			return _restTemplate.GetForObjectAsync<MicrosResponse>(BuildUrl("user/micros", parameters));
		}
Example #24
0
 public Task <UserResponse> GetUserAsync()
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObjectAsync <UserResponse>("user"));
 }
Example #25
0
 public Task <Root> GetRootAsync()
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObjectAsync <Root>(""));
 }
Example #26
0
 public Task <BookmarkDetails> GetBookmarkAsync(int bookmarkId)
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObjectAsync <BookmarkDetails>("bookmarks/" + bookmarkId));
 }
 public Task <Group> GetGroupDetailsAsync(int groupId)
 {
     return(restTemplate.GetForObjectAsync <Group>(GroupDetailsUrl, groupId));
 }
 public Task <Article> GetArticleAsync(string articleId)
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObjectAsync <Article>("articles/" + articleId));
 }