public CardsResponse GetUserContributions(int page, int count)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            return(_restTemplate.GetForObject <CardsResponse>(BuildUrl("user/contribs", parameters)));
        }
예제 #2
0
        public void GetForObject()
        {
            Uri        requestUri    = new Uri("http://example.com");
            HttpMethod requestMethod = HttpMethod.GET;

            Expect.Call <bool>(converter.CanRead(typeof(string), null)).Return(true);
            MediaType         textPlain  = new MediaType("text", "plain");
            IList <MediaType> mediaTypes = new List <MediaType>(1);

            mediaTypes.Add(textPlain);
            Expect.Call <IList <MediaType> >(converter.SupportedMediaTypes).Return(mediaTypes);
            Expect.Call <IClientHttpRequest>(requestFactory.CreateRequest(requestUri, requestMethod)).Return(request);
            HttpHeaders requestHeaders = new HttpHeaders();

            Expect.Call <HttpHeaders>(request.Headers).Return(requestHeaders).Repeat.Any();
            ExpectGetResponse();
            Expect.Call <bool>(errorHandler.HasError(requestUri, requestMethod, response)).Return(false);
            HttpHeaders responseHeaders = new HttpHeaders();

            responseHeaders.ContentType = textPlain;
            Expect.Call <HttpHeaders>(response.Headers).Return(responseHeaders).Repeat.Any();
            ExpectHasMessageBody(responseHeaders);
            Expect.Call <bool>(converter.CanRead(typeof(string), textPlain)).Return(true);
            String expected = "Hello World";

            Expect.Call <string>(converter.Read <string>(response)).Return(expected);

            mocks.ReplayAll();

            string result = template.GetForObject <string>("http://example.com");

            Assert.AreEqual(expected, result, "Invalid GET result");
            Assert.AreEqual(textPlain.ToString(), requestHeaders.GetSingleValue("Accept"), "Invalid Accept header");
        }
예제 #3
0
        public LinksResponse GetUserLinks(int page, int count)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            return(_restTemplate.GetForObject <LinksResponse>(BuildUrl("user/links", parameters)));
        }
예제 #4
0
        public FollowingResponse GetUserFollowing(int page, int count)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            return(_restTemplate.GetForObject <FollowingResponse>(BuildUrl("user/following", parameters)));
        }
예제 #5
0
        public ActivitiesResponse GetUserActivities(int page, int count)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            return(_restTemplate.GetForObject <ActivitiesResponse>(BuildUrl("user/activity", parameters)));
        }
예제 #6
0
        public ActivitiesResponse GetUserActivities(int page, int count, ActivityType type)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            if (type != ActivityType.All)
            {
                parameters.Add("type", type.ToString().ToLower());
            }
            return(_restTemplate.GetForObject <ActivitiesResponse>(BuildUrl("user/activity", parameters)));
        }
예제 #7
0
        public CardsResponse GetUserCards(int page, int count, bool featured = false)
        {
            EnsureIsAuthorized();
            var parameters = BuildPagingParametersWithCount(page, count);

            if (featured)
            {
                parameters.Add(new NameValueCollection {
                    { "featured", featured.ToString() }
                });
            }
            return(_restTemplate.GetForObject <CardsResponse>(BuildUrl("user/cards", parameters)));
        }
예제 #8
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();
			}
        }
예제 #9
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();
            }
        }
예제 #10
0
        public bool CreateNewTaskForEmptyPalletStack(string positionName)
        {
            var restReturn = restTemplate.GetForObject <RestReturn>("CreateNewTaskForEmptyPalletStack/?positionName={p}", positionName);

            if (restReturn != null && restReturn.IsSuccess)
            {
                if (restReturn.Message != string.Empty)
                {
                    Logger.Info(restReturn.Message);
                }
                return(true);
            }
            else if (restReturn != null && !restReturn.IsSuccess)
            {
                Logger.Error("生成空托盘回收任务失败,详情:" + restReturn.Message);
                return(false);
            }
            else
            {
                return(false);
            }
        }
예제 #11
0
        public ContributionCollection GetContributions(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.GetForObject <ContributionCollection>(BuildUrl("contributions", parameters)));
        }
예제 #12
0
        public IList<IStreamableTrack> Search(string searchTerm)
        {
            RestTemplate template = new RestTemplate("http://api.soundcloud.com");
            template.MessageConverters.Add(new DataContractJsonHttpMessageConverter());

            IDictionary<string,object> vars = new Dictionary<string, object>();
            vars.Add("client_id", playerID);
            vars.Add("term", searchTerm);

            var tracks = template.GetForObject<List<Track>>("/tracks.json?client_id={client_id}&order=hotness&q={term}", vars);

            // Remove any tracks that aren't streamable
            tracks.RemoveAll(track => !track.Streamable);

            foreach (var track in tracks)
            {
                // Dodgy hack for now
                track.StreamURL = track.StreamURL + "?client_id=" + playerID;
            }

            return tracks.ConvertAll(input => (IStreamableTrack) input);
        }
예제 #13
0
        public MR_auth_logout auth_logout(string session_token)
        {
            MR_auth_logout _ret;

            session_token = HttpUtility.UrlEncode(session_token);

            try
            {
                string _url = BaseURL + "/auth/logout";

                _url += "?" +
                        "apikey" + "=" + APIKEY + "&" +
                        "session_token" + "=" + session_token;

                string _r = m_rest.GetForObject <string>(_url);
                _r = StringUtility.UTF8ToISO_8859_1(_r);

                _ret = JsonConvert.DeserializeObject <MR_auth_logout>(_r);
            }
            catch (Exception _e)
            {
                // MessageBox.Show(_e.Message);
                return(null);
            }

            return(_ret);
        }
        public List <T> FetchConnections <T>(String objectId, String connectionType, NameValueCollection queryParameters) where T : class
        {
            String connectionPath = connectionType != null && connectionType.Length > 0 ? "/" + connectionType : "";

            return(restTemplate.GetForObject <List <T> >(this.BuildUrl(objectId + connectionPath, queryParameters)));
        }
예제 #15
0
 public Root GetRoot()
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObject <Root>(""));
 }
예제 #16
0
        /// <summary>
        /// Get all info about employees
        /// </summary>
        public JsonResult GetInfoEmployees(int?IdEmployee)
        {
            var EmployeesInfo = _proxy.GetForObject <ICollection <EmployeeTO> >($"{ConstantesApi.getEmployeesUri}?IdEmployee={IdEmployee}");

            return(Json(EmployeesInfo));
        }
예제 #17
0
 public BookmarkDetails GetBookmark(int bookmarkId)
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObject <BookmarkDetails>("bookmarks/" + bookmarkId));
 }
예제 #18
0
		public MicrosResponse GetUserMicros(int page, int count)
		{
			EnsureIsAuthorized();
			var parameters = BuildPagingParametersWithCount(page, count);
			return _restTemplate.GetForObject<MicrosResponse>(BuildUrl("user/micros", parameters));
		}
예제 #19
0
 public Order GetOrder(Uri orderUri)
 {
     return(restTemplate.GetForObject <Order>(orderUri));
 }
 public Article GetArticle(string articleId)
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObject <Article>("articles/" + articleId));
 }
예제 #21
0
 public User GetUser()
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObject <User>("users/_current"));
 }
예제 #22
0
 public UserResponse GetUser()
 {
     EnsureIsAuthorized();
     return(_restTemplate.GetForObject <UserResponse>("user"));
 }