예제 #1
0
        public void SObjectUrlBuilderShouldReturnSObjectUrlWithNoId()
        {
            var url = new SObjectUrlBuilder("v45.0")
                      .ForSObject("Account")
                      .ToString();

            Assert.AreEqual("/services/data/v45.0/sobjects/Account", url);
        }
예제 #2
0
        public async Task <bool> Delete(string sObjectName, string id)
        {
            var url = new SObjectUrlBuilder(apiVersion)
                      .ForSObject(sObjectName)
                      .WithId(id)
                      .ToString();

            var response = await httpClient.DeleteAsync(url);

            return(response.IsSuccessStatusCode);
        }
예제 #3
0
        public async Task <ObjectDescribeResponse> DescribeObject(string objectName)
        {
            var url = new SObjectUrlBuilder(apiVersion)
                      .ForSObject(objectName)
                      .Describe()
                      .ToString();

            var response = await httpClient.GetAsync(url);

            var content = await response.Content.ReadAsStringAsync();

            return(serializer.Deserialize <ObjectDescribeResponse>(content));
        }
예제 #4
0
        public async Task <T> GetById <T>(string sObjectName, string id)
        {
            var url = new SObjectUrlBuilder(apiVersion)
                      .ForSObject(sObjectName)
                      .WithId(id)
                      .ToString();

            var response = await httpClient.GetAsync(url);

            var content = await response.Content.ReadAsStringAsync();

            return(serializer.Deserialize <T>(content));
        }
예제 #5
0
        public async Task <bool> Update <T>(string sObjectName, string id, T record)
        {
            var url = new SObjectUrlBuilder(apiVersion)
                      .ForSObject(sObjectName)
                      .WithId(id)
                      .ToString();

            //var body = new StringContent(serializer.Serialize(record));
            var content  = new StringContent(serializer.Serialize(record), Encoding.UTF8, serializer.ContentType);
            var response = await httpClient.PatchAsync(url, content);

            return(response.IsSuccessStatusCode);
        }
예제 #6
0
        public async Task <string> Create <T>(string objectName, T record)
        {
            var url = new SObjectUrlBuilder(apiVersion)
                      .ForSObject(objectName)
                      .ToString();

            var body     = new StringContent(serializer.Serialize(record), Encoding.UTF8, serializer.ContentType);
            var response = await httpClient.PostAsync(url, body);

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                var success = serializer.Deserialize <CreatedResponse>(content);

                if (success.Success)
                {
                    return(success.Id);
                }
            }

            return(null);
        }