public HttpResponseMessage StartFollowing(string userId)
        {
            EnsureIsAuthorized();
            var request = new NameValueCollection {
                { "user", userId }, { "action", "follow" }
            };

            return(_restTemplate.PostForMessage("user/follow", request));
        }
示例#2
0
        public HttpResponseMessage UpdateBookmark(int bookmarkId, bool favorite = false, bool archive = false, double?readPercent = null, DateTime?dateOpened = null)
        {
            EnsureIsAuthorized();
            var parameters = new NameValueCollection();

            if (favorite)
            {
                parameters.Add("favorite", "1");
            }
            else
            {
                parameters.Add("favorite", "0");
            }
            if (archive)
            {
                parameters.Add("archive", "1");
            }
            else
            {
                parameters.Add("archive", "0");
            }
            if (readPercent.HasValue)
            {
                parameters.Add("read_percent", readPercent.ToString());
            }
            if (dateOpened.HasValue)
            {
                parameters.Add("date_opened", dateOpened.Value.ToString(CultureInfo.InvariantCulture));
            }
            return(_restTemplate.PostForMessage("bookmarks/" + bookmarkId, parameters));
        }
示例#3
0
        public HttpResponseMessage Highfive(HighfiveType type, string itemId)
        {
            EnsureIsAuthorized();
            var request = new NameValueCollection {
                { "type", type.ToString().ToLower() }, { "gfk", itemId }
            };

            return(_restTemplate.PostForMessage("highfive", request));
        }
示例#4
0
        public void PostForMessage()
        {
            Uri        requestUri    = new Uri("http://example.com");
            HttpMethod requestMethod = HttpMethod.POST;

            Expect.Call <bool>(converter.CanRead(typeof(Version), 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();
            string helloWorld = "Hello World";

            Expect.Call <bool>(converter.CanWrite(typeof(string), null)).Return(true);
            converter.Write(helloWorld, null, request);
            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);
            Version expected = new Version(1, 0);

            Expect.Call <bool>(converter.CanRead(typeof(Version), textPlain)).Return(true);
            Expect.Call <Version>(converter.Read <Version>(response)).Return(expected);
            Expect.Call <HttpStatusCode>(response.StatusCode).Return(HttpStatusCode.OK);
            Expect.Call <string>(response.StatusDescription).Return("OK");

            mocks.ReplayAll();

            HttpResponseMessage <Version> result = template.PostForMessage <Version>("http://example.com", helloWorld);

            Assert.AreEqual(expected, result.Body, "Invalid POST result");
            Assert.AreEqual(textPlain, result.Headers.ContentType, "Invalid Content-Type");
            Assert.AreEqual(textPlain.ToString(), requestHeaders.GetSingleValue("Accept"), "Invalid Accept header");
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode, "Invalid status code");
            Assert.AreEqual("OK", result.StatusDescription, "Invalid status description");
        }
示例#5
0
        public ActionResult CreateAppointment(AppointmenTO filtro)
        {
            var Datos = _proxy.PostForMessage <string>(ConstantesApi.getCreateAppointmentUri, filtro);

            return(Content(Datos.Body, "application/json"));
        }