Пример #1
0
        public MagentoServiceResponse <string> GetToken(string siteUrl, string username, string password)
        {
            var client  = CreateRestClient(siteUrl);
            var request = CreateRequest("/rest/default/V1/integration/admin/token", Method.POST);

            request.AddBody(new { username = username, password = password });
            var serviceResponse = new MagentoServiceResponse <string>();

            try
            {
                var response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    serviceResponse.Result = SimpleJson.DeserializeObject <string>(response.Content);
                }
                else
                {
                    serviceResponse.Error = response.Content;
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Error = ex.Message;
            }
            return(serviceResponse);
        }
Пример #2
0
        public MagentoServiceResponse <bool> UpdateMessage(string siteUrl, string token, UpdateMessageRequest updateMessageRequest)
        {
            var client          = CreateRestClient(siteUrl, token);
            var serviceResponse = new MagentoServiceResponse <bool>();
            var request         = CreateRequest("/rest/aheadworks/helpdesk/updatemessage", Method.POST);

            request.AddBody(updateMessageRequest);

            try
            {
                var response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var content = SimpleJson.DeserializeObject <JsonArray>(response.Content);
                    if (content == null)
                    {
                        serviceResponse.Error = "Can not deserialize content";
                    }
                    else
                    {
                        serviceResponse.Result = (bool)content[0];
                    }
                }
                else
                {
                    serviceResponse.Error = response.Content;
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Error = ex.Message;
            }

            return(serviceResponse);
        }
Пример #3
0
        public MagentoServiceResponse <IList <MessageResponse> > GetMessages(string siteUrl, string token, GetMessagesRequest getMessagesRequest)
        {
            var client          = CreateRestClient(siteUrl, token);
            var serviceResponse = new MagentoServiceResponse <IList <MessageResponse> >();
            var request         = CreateRequest("/rest/aheadworks/helpdesk/getmessages", Method.POST);

            request.AddBody(getMessagesRequest);

            try
            {
                var response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var content = SimpleJson.DeserializeObject <JsonArray>(response.Content);
                    if (content == null)
                    {
                        serviceResponse.Error = "Can not deserialize content";
                    }
                    else
                    {
                        if (content[1].ToString() == string.Empty)
                        {
                            serviceResponse.Result = SimpleJson.DeserializeObject <IList <MessageResponse> >(content[0].ToString());
                        }
                        else
                        {
                            serviceResponse.Error = content[1].ToString();
                        }
                    }
                }
                else
                {
                    serviceResponse.Error = response.Content;
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Error = ex.Message;
            }

            return(serviceResponse);
        }
Пример #4
0
        public MagentoServiceResponse <IList <StoreViewResponse> > GetStoreViews(string siteUrl, string token)
        {
            var client          = CreateRestClient(siteUrl, token);
            var serviceResponse = new MagentoServiceResponse <IList <StoreViewResponse> >();
            var request         = CreateRequest("/rest/V1/store/storeViews", Method.GET);

            try
            {
                var response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var content = SimpleJson.DeserializeObject <IList <StoreViewResponse> >(response.Content);
                    if (content == null)
                    {
                        serviceResponse.Error = "Can not deserialize content";
                    }
                    else
                    {
                        if (content[1].ToString() == string.Empty)
                        {
                            serviceResponse.Result = SimpleJson.DeserializeObject <IList <StoreViewResponse> >(content[0].ToString());
                        }
                        else
                        {
                            serviceResponse.Error = content[1].ToString();
                        }
                    }
                }
                else
                {
                    serviceResponse.Error = response.Content;
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Error = ex.Message;
            }

            return(serviceResponse);
        }