Beispiel #1
0
        public HttpResponseMessage GetPopularPlaceDetails([FromBody] PopularPlacesModel aPopularPlace)
        {
            PopularPlaceDetailModel popularPlaceDetail = null;

            if (aPopularPlace != null)
            {
                popularPlaceDetail = HereService.GetPopularPlaceDetail(aPopularPlace);
            }

            //return null when detecting invalid
            return(Request.CreateResponse(HttpStatusCode.OK, popularPlaceDetail));
        }
Beispiel #2
0
        public static List <PopularPlacesModel> GetPopularPlaces(HereApiQuery queryParams)
        {
            //double lat = queryParams.Lat;
            //double lon = queryParams.Lon;
            //make request
            //string query = "?";
            //query += String.Format("at={0}%2C{1}", lat, lon);
            ////            query += "at=" + "-36.8623%2C174.7494";//TODO use location value
            //query += "&app_id=" + KEY.ID;
            //query += "&app_code=" + KEY.CODE;
            ////string fullUrl = HereUrl.BASE + HereUrl.Explore + query;

            string    fullUrl = HereUrl.GetExplore(queryParams);
            WebClient client  = new WebClient();
            string    result  = client.DownloadString(fullUrl);

            var placesExploreJsonObj = JsonConvert.DeserializeObject <PlacesExplore>(result);

            List <PopularPlacesModel> popularPlacesList = new List <PopularPlacesModel>();

            //turn into  model
            foreach (var item in placesExploreJsonObj.results.items)
            {
                if (item != null)
                {
                    PopularPlacesModel popularPlace = new PopularPlacesModel()
                    {
                        Id       = item.id,
                        Title    = item.title,
                        Distance = item.distance,
                        Category = new CategoryModel {
                            Name = item.category.title, Value = item.category.id
                        },
                        AverageRating = item.averageRating,
                        DetailHref    = ParseDetailHref(item.href)
                    };

                    popularPlacesList.Add(popularPlace);
                }
            }

            return(popularPlacesList);
        }
Beispiel #3
0
        public static PopularPlaceDetailModel GetPopularPlaceDetail(PopularPlacesModel aPopularPlace)
        {
            string detailHref = aPopularPlace.DetailHref;
            bool   validHref  = IsValidPlaceDetailHref(detailHref);

            if (!validHref)
            {
                return(null);
            }

            //using the href with credentials
            detailHref = AppendCredentialsDetailHref(detailHref);

            var activityHref = detailHref; //use for making another http request
            PopularPlaceDetailModel placeDetail = null;

            if (activityHref != null)
            {
                WebClient client       = new WebClient();
                var       itemHrefJson = client.DownloadString(activityHref);
                var       itemHref     = JsonConvert.DeserializeObject <ItemsHref>(itemHrefJson);

                placeDetail = new PopularPlaceDetailModel()
                {
                    Name            = itemHref.name,
                    PlaceId         = itemHref.placeId,
                    FullTextAddress = itemHref.location.address.text,
                };

                placeDetail.Category   = aPopularPlace.Category;
                placeDetail.MapViewUrl = itemHref.view;
                placeDetail.PlaceId    = itemHref.placeId;


                var allContacts = new List <Contact>();
                //add website
                foreach (var site in itemHref.contacts.website)
                {
                    if (site != null)
                    {
                        Contact contact = new Contact()
                        {
                            Value = site.value,
                            Label = site.label
                        };

                        allContacts.Add(contact);
                    }
                }

                //add phone contact
                foreach (var phone in itemHref.contacts.phone)
                {
                    if (phone != null)
                    {
                        Contact phoneContact = new Contact()
                        {
                            Value = phone.value,
                            Label = phone.label
                        };

                        allContacts.Add(phoneContact);
                    }
                }

                placeDetail.Contacts = allContacts;
            }

            return(placeDetail);
        }