예제 #1
0
        public MicroResponse CreateMicro(string status)
        {
            EnsureIsAuthorized();
            var request = new NameValueCollection {
                { "status", status }
            };

            return(_restTemplate.PostForObject <MicroResponse>("micros", request));
        }
예제 #2
0
        protected AccessGrant PostForAccessGrant(string accessTokenUrl, NameValueCollection parameters)
        {
            var response = RestTemplate.PostForObject <NameValueCollection>(accessTokenUrl, parameters);
            var expires  = response["expires"];

            return(new AccessGrant(response["access_token"], null, null, expires != null ? new int?(Int32.Parse(expires)) : null));
        }
예제 #3
0
        public LinkResponse CreateLink(string url, string title, string category = null, string description = null, string communities = null)
        {
            EnsureIsAuthorized();
            var request = new NameValueCollection {
                { "url", url }, { "title", title }
            };

            if (!string.IsNullOrEmpty(category))
            {
                request.Add(new NameValueCollection {
                    { "category", category }
                });
            }
            if (!string.IsNullOrEmpty(description))
            {
                request.Add(new NameValueCollection {
                    { "description", description }
                });
            }
            if (!string.IsNullOrEmpty(communities))
            {
                request.Add(new NameValueCollection {
                    { "communities", communities }
                });
            }
            return(_restTemplate.PostForObject <LinkResponse>("links", request));
        }
예제 #4
0
        public CardResponse CreateCard(string headline)
        {
            EnsureIsAuthorized();
            var request = new NameValueCollection {
                { "headline", headline }
            };

            return(_restTemplate.PostForObject <CardResponse>("cards", request));
        }
예제 #5
0
        public void PostForObject()
        {
            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);

            mocks.ReplayAll();

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

            Assert.AreEqual(expected, result, "Invalid POST result");
            Assert.AreEqual(textPlain.ToString(), requestHeaders.GetSingleValue("Accept"), "Invalid Accept header");
        }
        public String Publish(String objectId, String connectionType, Dictionary <string, object> data)
        {
            JsonValue response = restTemplate.PostForObject <JsonValue>(objectId + "/" + connectionType, data);

            return(response.GetValue <string>("id"));
        }