Ejemplo n.º 1
0
        public void Test_http_client_status_after_request()
        {
            var oauthProperties = new OAuthProperties();
            var client          = new HttpClient(new OAuthMessageHandler(new HttpClientHandler(), oauthProperties));

            IApiService service = new ApiService(client);

            string url = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&screen_name=pay_by_phone";

            var result = service.GetTwitterTimelines(url);

            Assert.NotNull(result);
        }
Ejemplo n.º 2
0
 public OAuthMessageHandler(HttpMessageHandler innerHandler, OAuthProperties oAuthProperties)
     : base(innerHandler)
 {
     this._oauthProperties = oAuthProperties;
     this._oAuthBase       = new OAuthBase();
 }
Ejemplo n.º 3
0
 public ApiService()
 {
     this._oauthProperties = new OAuthProperties();
     this._client          = new HttpClient(new OAuthMessageHandler(new HttpClientHandler(), this._oauthProperties));
 }
Ejemplo n.º 4
0
        static void updateMultiItemInventory(int listingId)
        {
            var client = new RestClient();

            client.BaseUrl = new Uri("https://openapi.etsy.com/v2/listings/" + listingId + "/inventory?write_missing_inventory=true");
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", "OAuth " + OAuthSignatureGenerator.GetAuthorizationHeaderValue(client.BaseUrl, "", "GET"));
            IRestResponse response = client.Execute(request);

            try
            {
                string  sku = "";
                var     inventoryVariations = JsonConvert.DeserializeObject <GetInventory>(response.Content);
                dynamic data = JObject.Parse(response.Content);

                foreach (var item in data.results.price_on_property.Children())
                {
                    inventoryVariations.price_on_property = item.Value;
                }
                foreach (var item in data.results.quantity_on_property.Children())
                {
                    inventoryVariations.quantity_on_property = item.Value;
                }
                foreach (var item in data.results.sku_on_property.Children())
                {
                    inventoryVariations.sku_on_property = item.Value;
                }

                UpdateInventory1 updateInventoryList = new UpdateInventory1();
                foreach (Product p in inventoryVariations.results.products)
                {
                    ItemData latestProductData = getItemDataFromPanel(p.sku);

                    if (!String.IsNullOrEmpty(latestProductData.itemNo))
                    {
                        if (double.Parse(latestProductData.sellPrice) > 0)
                        {
                            p.offerings[0].price = (Convert.ToDouble(latestProductData.sellPrice) * 1.15).ToString();
                        }

                        if (int.Parse(latestProductData.curStock) > 0)
                        {
                            p.offerings[0].quantity = int.Parse(latestProductData.curStock);
                        }
                        else
                        {
                            p.offerings[0].quantity = 0;
                        }
                    }

                    sku += p.sku + ",";
                    updateInventoryList.Products.Add(p);
                }

                var client1  = new RestClient("https://openapi.etsy.com/v2/listings/" + listingId + "/inventory");
                var request1 = new RestRequest(Method.PUT);
                request1.AddHeader("Content-Type", "application/x-www-form-urlencoded");
                OAuthProperties properties = OAuthSignatureGenerator.GetMultiProductAuthorizationHeaderValue(client1.BaseUrl, JsonConvert.SerializeObject(updateInventoryList.Products), JsonConvert.SerializeObject(inventoryVariations.price_on_property), JsonConvert.SerializeObject(inventoryVariations.quantity_on_property), JsonConvert.SerializeObject(inventoryVariations.sku_on_property), "PUT");
                request1.AddParameter("oauth_consumer_key", properties.oauth_consumer_key);
                request1.AddParameter("oauth_token", properties.oauth_token);
                request1.AddParameter("oauth_signature_method", properties.oauth_signature_method);
                request1.AddParameter("oauth_timestamp", properties.oauth_timestamp);
                request1.AddParameter("oauth_nonce", properties.oauth_nonce);
                request1.AddParameter("oauth_version", properties.oauth_version);
                request1.AddParameter("oauth_signature", properties.oauth_signature);

                request1.AddParameter("products", JsonConvert.SerializeObject(updateInventoryList.Products));
                request1.AddParameter("price_on_property", JsonConvert.SerializeObject(inventoryVariations.price_on_property));
                request1.AddParameter("quantity_on_property", JsonConvert.SerializeObject(inventoryVariations.quantity_on_property));
                request1.AddParameter("sku_on_property", JsonConvert.SerializeObject(inventoryVariations.sku_on_property));

                IRestResponse response1 = client1.Execute(request1);
                CheckRequestThrottleLimit();
                WriteToFile("Stock Item is Updated with Listing ID: " + listingId + " (" + sku + ")");
                Listings = Listings + sku + ", ";
            }
            catch (Exception e)
            {
                WriteToFile("Error for " + listingId + "-----" + e.StackTrace);
            }
        }