Ejemplo n.º 1
0
        /// <summary>
        /// Creates a record
        /// </summary>
        /// <param name="objectName">The name of the object in Salesforce.</param>
        /// <param name="record">The record to be created.</param>
        /// <param name="altUrl">The url to use without the instance url</param>
        /// <returns>The Id of created record.</returns>
        public string Create(string objectName, object record, string altUrl)
        {
            ExceptionHelper.ThrowIfNullOrEmpty("objectName", objectName);
            ExceptionHelper.ThrowIfNull("record", record);
            ExceptionHelper.ThrowIfNullOrEmpty("altUrl", altUrl);

            var response = Request <object>(GetAltUrl(altUrl), objectName, record, Method.POST);

            return(m_deserializer.Deserialize <dynamic>(response).id.Value);
        }
        /// <summary>
        /// Authenticate in the Salesforce REST's API.
        /// </summary>
        /// <returns>
        /// The authentication info with access token and instance url for futher API calls.
        /// </returns>
        /// <remarks>
        /// If authentiaction fails an SalesforceException will be throw.
        /// </remarks>
        public AuthenticationInfo Authenticate()
        {
            Uri uri = new Uri(TokenRequestEndpointUrl);

            m_restClient.BaseUrl = uri;

            var request = new RestRequest(Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddParameter("grant_type", "password");
            request.AddParameter("client_id", m_clientId);
            request.AddParameter("client_secret", m_clientSecret);
            request.AddParameter("username", m_username);
            request.AddParameter("password", m_password);

            var response        = m_restClient.Post(request);
            var isAuthenticated = response.StatusCode == HttpStatusCode.OK;

            var deserializer = new DynamicJsonDeserializer();
            var responseData = deserializer.Deserialize <dynamic>(response);

            if (isAuthenticated)
            {
                return(new AuthenticationInfo(responseData.access_token.Value, responseData.instance_url.Value));
            }
            else
            {
                throw new SalesforceException(responseData.error.Value, responseData.error_description.Value);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a Sugar dropdown list
        /// </summary>
        /// <param name="module">Module Name</param>
        /// <param name="field">field name</param>
        /// <returns> SugarList object </returns>
        public SugarList GetList(string module, string field)
        {
            var request = new RestRequest("{module}/enum/{field}", Method.GET);

            request.AddUrlSegment("module", module);
            request.AddUrlSegment("field", field);


            var response = Execute(request);
            var list     = dynamicSerializer.Deserialize <JObject>(response);

            return(new SugarList(list.ToObject <Dictionary <string, string> >()));
        }
        /// <summary>
        /// Authenticate in the Salesforce REST's API.
        /// </summary>
        /// <returns>
        /// The authentication info with access token and instance url for futher API calls.
        /// </returns>
        /// <remarks>
        /// If authentiaction fails an SalesforceException will be throw.
        /// </remarks>
        public AuthenticationInfo Authenticate()
        {
            Uri uri = new Uri(TokenRequestEndpointUrl);
            m_restClient.BaseUrl = uri;

            var request = new RestRequest(Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddParameter("grant_type", "password");
            request.AddParameter("client_id", m_clientId);
            request.AddParameter("client_secret", m_clientSecret);
            request.AddParameter("username", m_username);
            request.AddParameter("password", m_password);

            var response = m_restClient.Post(request);
            var isAuthenticated = response.StatusCode == HttpStatusCode.OK;

            var deserializer = new DynamicJsonDeserializer();
            var responseData = deserializer.Deserialize<dynamic>(response);

            if (isAuthenticated)
            {
                return new AuthenticationInfo(responseData["access_token"].Value, responseData["instance_url"].Value);
            }
            else
            {
                throw new SalesforceException(responseData.error.Value, responseData.error_description.Value);
            }
        }