Beispiel #1
0
        public async Task <UploadTrackingApiResponse <ShopifyOrders> > GetOrders(int userId)
        {
            ////////var integration = await _storeIntRepo.GetIntegration(userId);


            ///////////////////TODO: DELETE THIS
            var integration = new StoreIntegrationDTO
            {
                StoreName = "uploadtrackingtest",
                Token     = ""
            };

            /////////////////////////////

            var request = new UploadTrackingApiRequest
            {
                Url    = $"https://{integration.StoreName}.myshopify.com/admin/orders",
                Header = new Dictionary <string, string>
                {
                    { "X-Shopify-Access-Token", integration.Token }
                }
            };

            return(await HttpClientHelper.Get <ShopifyOrders>(request));
        }
Beispiel #2
0
        public async Task <UploadTrackingApiRequest> IntegrateShopify(int userId)
        {
            var integration = await _storeIntRepo.GetIntegration(userId);

            //TODO: DELETE THIS
            integration.StoreName = "uploadtrackingtest";
            ///////////////TODO:

            var request = new UploadTrackingApiRequest
            {
                Url         = $"https://{integration.StoreName}.myshopify.com/admin/oauth/authorize?",
                QueryString = new Dictionary <string, string>
                {
                    { "client_id", $"{ShopifyConstants.apiKey}" },
                    { "scope", $"{ShopifyConstants.scopes}" },
                    { "redirect_uri", $"{ShopifyConstants.redirectUri}" },
                    //{"amp;state", $"{nonce}" }
                }
            };

            foreach (var qString in request.QueryString)
            {
                request.Url += qString.Key + "=" + qString.Value + "&";
            }

            return(request);
        }
Beispiel #3
0
        //public static async Task<T> Get<T>(UploadTrackingApiRequest request)
        //{
        //    try
        //    {
        //        HttpResponseMessage response;
        //        using (var http = new HttpClient())
        //        {
        //            string queryString = "?";

        //            http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        //            if (request.Header != null)
        //            {
        //                foreach (var header in request.Header)
        //                {
        //                    http.DefaultRequestHeaders.Add(header.Key, header.Value);
        //                }
        //            }

        //            if (request.QueryString != null)
        //            {
        //                foreach (var qString in request.QueryString)
        //                {
        //                    queryString += qString.Key + "=" + qString.Value + "&";
        //                }
        //            }

        //            response = await http.GetAsync(request.Url + queryString);
        //        }
        //        return JsonConvert.DeserializeObject<T>(await response.Content.ReadAsStringAsync());
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}

        public static async Task <UploadTrackingApiResponse <T> > Get <T>(UploadTrackingApiRequest request)
        {
            UploadTrackingApiResponse <T> response = new UploadTrackingApiResponse <T>();

            try
            {
                using (var http = new HttpClient())
                {
                    string queryString = "?";

                    http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    if (request.Header != null)
                    {
                        foreach (var header in request.Header)
                        {
                            http.DefaultRequestHeaders.Add(header.Key, header.Value);
                        }
                    }

                    if (request.QueryString != null)
                    {
                        foreach (var qString in request.QueryString)
                        {
                            queryString += qString.Key + "=" + qString.Value + "&";
                        }
                    }

                    var result = await http.GetAsync(request.Url + queryString);

                    try
                    {
                        T data = JsonConvert.DeserializeObject <T>(await result.Content.ReadAsStringAsync());

                        response.Data         = data;
                        response.StatusCode   = result.StatusCode;
                        response.ErrorMessage = result.ReasonPhrase;
                    }
                    catch (Exception ex)
                    {
                    }

                    //result.RequestMessage = response.ErrorMessage;

                    return(response);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }