private static NameValueCollection GetExtraAttributes(String json)
        {
            var result = new NameValueCollection();

            var skip = new List<String> {"key", "name", "type", "updated_at", "dimensions"};

            var material = new Deserializer().Deserialize(json);

            foreach (var attribute in material.Properties())
            {
                un.less(() => skip.Contains(attribute.Name), () =>
                {
                    try
                    {
                        result.Add(attribute.Name, material.Value<String>(attribute.Name));
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Failed to get the values for the '" + attribute.Name + "' attribute", e);
                    }
                });
            }

            return result;
        }
Пример #2
0
        public static Error Deserialize(String json)
        {
            var settings = new JsonSerializerSettings {
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            var payload = new Deserializer().Deserialize(json);
            return JsonConvert.DeserializeObject<Error>(payload["error"].ToString(), settings);
        }
Пример #3
0
        protected Product Deserialize(Response response)
        {
            if (response.StatusCode != HttpStatusCode.OK)
                throw Error("Unexpected status returned.", response);

            var json = ReadAll(response);

            var productJson = new Deserializer().Deserialize(json)["product"];
            return ProductDeserializer.Deserialize(productJson.ToString());
        }
Пример #4
0
        public Product Delete(String productKey, String designKey)
        {
            var uri = Map("/products/{0}/delete-design/{1}", productKey, designKey);

            using (var response = Post(uri, Payload.Empty)) {
                un.less(() => response.StatusCode == HttpStatusCode.OK, () => {
                    throw Error("Delete failed", response);
                });

                var json = new Deserializer().Deserialize(ReadAll(response))["product"].ToString();
                return ProductDeserializer.Deserialize(json);
            }
        }
Пример #5
0
        public Product[] FindAll()
        {
            var response = Get(Map("/products"));

            var theList = new Deserializer().Deserialize(ReadAll(response));

            var result = new List<Product>();

            foreach (var productJson in theList["products"].Children()) {
                result.Add(Deserialize(productJson));
            }

            return result.ToArray();
        }
Пример #6
0
        public Product Find(String id)
        {
            var response = Get(Map("/products/{0}", id));

            Product aProductThatDoesNotExist = null;

            if (response.StatusCode == HttpStatusCode.NotFound)
                return aProductThatDoesNotExist;

            var json = ReadAll(response);

            var productJson = new Deserializer().Deserialize(json)["product"];

            return Deserialize(productJson);
        }
Пример #7
0
        public void for_example_you_can_deserialize_to_a_hash()
        {
            var json = "{" +
            "	'nodes': [" +
            "		{" +
            "			'materials_updated_at': '2011/06/27 20:23:16 +0000'," +
            "			'key': '2e9d8c90326e012e359f404062cdb04a'," +
            "			'name': 'Ponoko - United States'" +
            "		}" +
             			"	]" +
            "}";

            var result = new Deserializer().Deserialize(json);

            Assert.AreEqual("Ponoko - United States", result["nodes"].First.Value<String>("name"));
        }
        private void Verify(Response response)
        {
            var json = new Deserializer().Deserialize(ReadAll(response));

            Ensure(json);

            var deleted = json.Value<String>("deleted").ToLower();
            var wasDeletedOkay = (deleted == "true");

            un.less(wasDeletedOkay, () => {
                throw new Exception(String.Format(
                    "Delete failed. Expected the deleted flag to be true. but it was \"{0}\".",
                    deleted
                ));
            });
        }
Пример #9
0
        public Order Create(String reference, Option shippingOption, NameAndAddress shipTo, ProductShippingInfo product)
        {
            var uri = Map("/orders");

            var payload = new Payload {
                new Field { Name = "ref", Value = reference },
                new Field { Name = "shipping_option_code", Value = shippingOption.Code },
            };

            payload.AddRange(Format(product));
            payload.AddRange(Format(shipTo));

            var response = Post(uri, payload);

            if (response.StatusCode != HttpStatusCode.OK)
                throw Error("Failed to create order", response);

            var json = ReadAll(response);

            var theOrderNode = new Deserializer().Deserialize(json)["order"];

            return OrderDeserializer.Deserialize(theOrderNode.ToString());
        }
Пример #10
0
 private Product Deserialize(Response response)
 {
     var json = new Deserializer().Deserialize(ReadAll(response))["product"].ToString();
     return ProductDeserializer.Deserialize(json);
 }
Пример #11
0
        private Order GetAndDeserialize(Uri uri)
        {
            var response = _internet.Get(uri);

            var json = ReadAll(response);

            var theNode = new Deserializer().Deserialize(json)["order"].ToString();

            return OrderDeserializer.Deserialize(theNode);
        }