public async void Post_UserInfo()
        {
            const string userAgent = "common-libraries-dotnet";

            var auth = new AuthenticationClient();
            await auth.UsernamePasswordAsync(_consumerKey, _consumerSecret, _username, _password, userAgent, _tokenRequestEndpointUrl);

            var serviceHttpClient = new ServiceHttpClient(auth.InstanceUrl, auth.ApiVersion, auth.AccessToken, userAgent, new HttpClient());
            var objectName = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("access_token", auth.AccessToken)
                });

            var response = await serviceHttpClient.HttpPostAsync<UserInfo>(objectName, new Uri(auth.Id));

            Assert.IsNotNull(response);
        }
        public Task <T> PostFeedItemAsync <T>(FeedItemInput feedItemInput, string userId)
        {
            // Feed items not available post v30.0
            if (float.Parse(_serviceHttpClient.ApiVersion.Substring(1)) > 30.0)
            {
                return(_serviceHttpClient.HttpPostAsync <T>(feedItemInput, "chatter/feed-elements"));
            }

            return(_serviceHttpClient.HttpPostAsync <T>(feedItemInput, string.Format("chatter/feeds/news/{0}/{1}", userId, _itemsOrElements)));
        }
        public async Task <string> CreateAsync(string objectName, object record)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException("objectName");
            }
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            //TODO: implement try/catch and throw auth exception if appropriate

            var response = await _serviceHttpClient.HttpPostAsync <SuccessResponse>(record, string.Format("sobjects/{0}", objectName)).ConfigureAwait(false);

            return(response.id);
        }
        public async void Post_UserInfo()
        {
            var objectName = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("access_token", _auth.AccessToken)
            });

            var response = await _serviceHttpClient.HttpPostAsync <UserInfo>(objectName, new Uri(_auth.Id));

            Assert.IsNotNull(response);
        }
Example #5
0
        public async Task <SuccessResponse> CreateAsync(string objectName, object record)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException("objectName");
            }
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            return(await _serviceHttpClient.HttpPostAsync <SuccessResponse>(record, string.Format("sobjects/{0}", objectName)).ConfigureAwait(false));
        }
        public async void Post_UserInfo()
        {
            const string userAgent = "common-libraries-dotnet";

            var auth = new AuthenticationClient();
            await auth.UsernamePasswordAsync(_consumerKey, _consumerSecret, _username, _password, userAgent, _tokenRequestEndpointUrl);

            var serviceHttpClient = new ServiceHttpClient(auth.InstanceUrl, auth.ApiVersion, auth.AccessToken, userAgent, new HttpClient());
            var objectName        = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("access_token", auth.AccessToken)
            });

            var response = await serviceHttpClient.HttpPostAsync <UserInfo>(objectName, new Uri(auth.Id));

            Assert.IsNotNull(response);
        }
Example #7
0
        public async void Requests_CheckHttpRequestMessage_HttpPost()
        {
            var client = new HttpClient(new ServiceClientRouteHandler(r =>
            {
                Assert.AreEqual(r.RequestUri.ToString(), "http://localhost:1899/services/data/v30/wade");

                Assert.IsNotNull(r.Headers.UserAgent);
                Assert.AreEqual(r.Headers.UserAgent.ToString(), "common-libraries-dotnet/v30");

                Assert.IsNotNull(r.Headers.Authorization);
                Assert.AreEqual(r.Headers.Authorization.ToString(), "Bearer accessToken");
            }));

            using (var httpClient = new ServiceHttpClient("http://localhost:1899", "v30", "accessToken", client))
            {
                await httpClient.HttpPostAsync <object>(null, "wade");
            }
        }
Example #8
0
        public async Task <T> PostFeedItemAsync <T>(FeedItemInput feedItemInput, string userId)
        {
            var feedItem = await _serviceHttpClient.HttpPostAsync <T>(feedItemInput, string.Format("chatter/feeds/news/{0}/feed-items", userId));

            return(feedItem);
        }
        public async void Requests_CheckHttpRequestMessage_HttpPost()
        {
            var client = new HttpClient(new ServiceClientRouteHandler(r =>
            {
                Assert.AreEqual(r.RequestUri.ToString(), "http://localhost:1899/services/data/v30/wade");

                Assert.IsNotNull(r.Headers.UserAgent);
                Assert.AreEqual(r.Headers.UserAgent.ToString(), "common-libraries-dotnet/v30");

                Assert.IsNotNull(r.Headers.Authorization);
                Assert.AreEqual(r.Headers.Authorization.ToString(), "Bearer accessToken");
            }));

            using (var httpClient = new ServiceHttpClient("http://localhost:1899", "v30", "accessToken", client))
            {
                await httpClient.HttpPostAsync<object>(null, "wade");
            }
        }