public IEnumerable<ApiSearchHit> Search(string format, string code)
        {
            var result = new ApiSearchHit();
            var url = string.Format(baseUrl, ConfigurationManager.AppSettings["GOOGLE_SEARCH_API_KEY"], code);
            try
            {
                using (var webClient = new WebClient())
                {
                    var data = webClient.DownloadString(url);
                    dynamic x = DynamicJson.Parse(data);
                    if (x.IsDefined("items"))
                    {
                        foreach (dynamic item in x.items)
                        {
                            if (item.product())
                            {
                                var product = item.product;
                                if (product.title() && string.IsNullOrEmpty(result.Name))
                                    result.Name = product.title;
                                if (product.brand() && string.IsNullOrEmpty(result.Manufacturer))
                                    result.Manufacturer = product.brand;
                            }
                        }
                    }
                }
            }catch(Exception)
            {
                // pokemon!
            }

            if (result.IsEmpty) return Enumerable.Empty<ApiSearchHit>();

            return new[] {result};
        }
        public IEnumerable <ApiSearchHit> Search(string format, string code)
        {
            var result = new ApiSearchHit();
            var url    = string.Format(baseUrl, ConfigurationManager.AppSettings["GOOGLE_SEARCH_API_KEY"], code);

            try
            {
                using (var webClient = new WebClient())
                {
                    var     data = webClient.DownloadString(url);
                    dynamic x    = DynamicJson.Parse(data);
                    if (x.IsDefined("items"))
                    {
                        foreach (dynamic item in x.items)
                        {
                            if (item.product())
                            {
                                var product = item.product;
                                if (product.title() && string.IsNullOrEmpty(result.Name))
                                {
                                    result.Name = product.title;
                                }
                                if (product.brand() && string.IsNullOrEmpty(result.Manufacturer))
                                {
                                    result.Manufacturer = product.brand;
                                }
                            }
                        }
                    }
                }
            }catch (Exception)
            {
                // pokemon!
            }

            if (result.IsEmpty)
            {
                return(Enumerable.Empty <ApiSearchHit>());
            }

            return(new[] { result });
        }
        public void Should_pick_first_item_from_search_hits_and_use_to_update_barcode()
        {
            var barcode = new BarCode() { New = true };
            var searchHit = new ApiSearchHit() {Manufacturer = "lol", Name = "baz"};
            A.CallTo(() => this.barCodes.Get("", "", 0)).Returns(null);
            A.CallTo(() => this.barCodes.Create("", "", 0)).Returns(barcode);
            A.CallTo(() => this.apiSearchService.Search("", "")).Returns(new []{searchHit});

            barCodeController.Get("", "", 0);

            A.CallTo(() => this.barCodes.Update(A<BarCode>.That.Matches(x => x.Name=="baz" && x.Manufacturer== "lol"), 0)).MustHaveHappened();
        }