Exemplo n.º 1
0
        public Models.Shared.ResponseEnvelope Get(string url)
        {
            if (this.Authenticate())
            {
                var entry  = new YotpoLogEntry("GET");
                var client = this.GetHttpClient(entry);
                if (client != null)
                {
                    entry.url = this.ApplyParameters(url);

                    var result = client.GetAsync(entry.url).Result;
                    if (result != null)
                    {
                        entry.code     = (int)result.StatusCode;
                        entry.response = result.Content.ReadAsStringAsync().Result;
                        this.Log_Request(entry);

                        var envelope = ResponseEnvelope.from(entry.response);
                        if (envelope.status.code == 200)
                        {
                            return(envelope);
                        }
                        else
                        {
                            throw new EnvelopeException(envelope.status);
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        //this probably doesnt work - by definition the DELETE method does not support a content value...
        public ResponseEnvelope Delete(string url, object body)
        {
            if (this.Authenticate())
            {
                var entry  = new YotpoLogEntry("DELETE");
                var client = this.GetHttpClient(entry);
                if (client != null)
                {
                    if (body is iAuthorizedRequest)
                    {
                        ((iAuthorizedRequest)body).utoken = this.UToken;
                    }
                    entry.url  = this.ApplyParameters(url);
                    entry.body = ToJsonPayload(body);
                    var httpReq = new HttpRequestMessage(HttpMethod.Delete, entry.url);
                    httpReq.Content = entry.body;

                    var result = client.SendAsync(httpReq).Result;
                    if (result != null)
                    {
                        entry.code     = (int)result.StatusCode;
                        entry.response = result.Content.ReadAsStringAsync().Result;
                        this.Log_Request(entry);

                        var envelope = ResponseEnvelope.from(entry.response);
                        if (envelope.status.code == 200)
                        {
                            return(envelope);
                        }
                        else
                        {
                            throw new EnvelopeException(envelope.status);
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        public Models.Shared.ResponseEnvelope Post(string url, object body)
        {
            if (this.Authenticate())
            {
                var entry  = new YotpoLogEntry("POST");
                var client = this.GetHttpClient(entry);
                if (client != null)
                {
                    if (body is iAuthorizedRequest)
                    {
                        ((iAuthorizedRequest)body).utoken = this.UToken;
                    }
                    entry.url  = this.ApplyParameters(url);
                    entry.body = ToJsonPayload(body);
                    var result = client.PostAsync(entry.url, entry.body).Result;
                    if (result != null)
                    {
                        entry.code     = (int)result.StatusCode;
                        entry.response = result.Content.ReadAsStringAsync().Result;
                        this.Log_Request(entry);

                        var envelope = ResponseEnvelope.from(entry.response);
                        if (envelope.status.code == 200)
                        {
                            return(envelope);
                        }
                        else
                        {
                            throw new EnvelopeException(envelope.status);
                        }
                    }
                    else
                    {
                    }
                }
            }
            return(null);
        }