public DisneyPostRequest(String url, AuthToken token, String partySize, String mealPeriod, String searchDate)
        {
            String parameters = "grant_type=assertion&assertion_type=public&client_id=WDPRO-MOBILE.CLIENT-PROD&partySize=" + partySize + "&mealPeriod=" + mealPeriod + "&searchDate=" + searchDate;

            IDisneyReservationRequest disneyRequest = this;
            HttpWebRequest request = disneyRequest.setHeadersWithAuthorization(url, token);
            HttpWebResponse response = disneyRequest.makeReservationRequest(request, parameters);
            try
            {
                _response = response;
                String responseMessage = disneyRequest.returnResponse(response);
                ResponseMessage = responseMessage;
                WebHeaderCollection responseHeaders = response.Headers;
                _reservationUrl = responseHeaders.Get("Location");

            }
            catch (NullReferenceException err)
            {
                Console.WriteLine(err.Message);

            }

            DisneyGetRequest reservationRequest = new DisneyGetRequest(_reservationUrl, token);
            ResponseMessage = reservationRequest.ResponseMessage;
        }
        HttpWebRequest IDisneyAuthorizedRequest.setHeadersWithAuthorization(string url, AuthToken token)
        {
            token = token.returnNewTokenWhenExpired();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Headers.Add("Authorization", "Bearer " + token.Token);
            request.Accept = "application/json";
            request.Headers.Add("X-Conversation-Id", "WDPRO-MOBILE.CLIENT-PROD");

            return request;
        }
        public DisneyTableReservationList(AuthToken token, String partySize, String mealPeriod, String searchDate)
        {
            checkDateRange(checkDateFormat(searchDate));
            _searchDate = searchDate;
            _mealPeriod = mealPeriod;
            _partySize = partySize;

            String docPath = searchDate + "_" +  mealPeriod;

            token = token.returnNewTokenWhenExpired();
            DisneyPostRequest reservationRequest = new DisneyPostRequest(_url, token, _partySize, _mealPeriod, _searchDate);
            this.parseRestaurantIdsFromServerResponse(reservationRequest.ResponseMessage, docPath);
        }
 public DisneyPostRequest(String url, AuthToken token)
 {
     IDisneyAuthorizedRequest disneyRequest = this;
     HttpWebRequest request = disneyRequest.setHeadersWithAuthorization(url, token);
     HttpWebResponse response = disneyRequest.makeRequest(request);
     try
     {
         _response = response;
         String responseMessage = disneyRequest.returnResponse(response);
         ResponseMessage = responseMessage;
     }
     catch (NullReferenceException err)
     {
         Console.WriteLine(err.Message);
     }
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Starting...");
            String mealPeriod;
            String searchDate;

            Console.Write("Enter your meal period (breakfast, lunch, or dinner): ");
            mealPeriod = Console.ReadLine();
            Console.Write("Enter your search date: yyyy-MM-dd: ");
            searchDate = Console.ReadLine();
            AuthToken token = new AuthToken();
            DisneyTableReservationList reservationList = new DisneyTableReservationList(token, "2", mealPeriod, searchDate);

            Console.WriteLine("Press Enter to exit.");
            Console.Read();
        }
        public void populateDisneyRestaurants(AuthToken token)
        {
            this.DisneyRestaurants = new List<DisneyRestaurant>();

            foreach (String url in this._restaurantUrls)
            {

                DisneyRestaurant restaurant = new DisneyRestaurant();

                restaurant.RestaurantUrl = url;

                DisneyGetRequest restaurantRequest = new DisneyGetRequest(url, token);

                try
                {
                    //Location
                    JObject response = JObject.Parse(restaurantRequest.ResponseMessage);

                    JObject links = (JObject)response.SelectToken("links");
                    JObject ancestorPark = (JObject)links.SelectToken("ancestorThemePark") ?? (JObject)links.SelectToken("ancestorEntertainmentVenue") ?? (JObject)links.SelectToken("ancestorResort");
                    restaurant.Location = (String)ancestorPark.SelectToken("title");
                    Console.WriteLine(restaurant.Location);

                    //ID
                    String id = (String)response.SelectToken("id");
                    String[] words = id.Split(';');
                    restaurant.Id = Convert.ToInt32(words[0]);
                    Console.WriteLine(restaurant.Id);

                    //Name
                    restaurant.RestaurantName = (String)response.SelectToken("name");
                    Console.WriteLine(restaurant.RestaurantName);

                    //Price Range
                    JObject facets = (JObject)response.SelectToken("facets");
                    JArray priceRange = (JArray)facets.SelectToken("priceRange");
                    restaurant.PriceRange = (String)priceRange[0].SelectToken("urlFriendlyId");
                    Console.WriteLine(restaurant.PriceRange);

                    // Type of restaurant -- Table or Quick
                    JArray service = (JArray)facets.SelectToken("tableService");
                    String diningType = null;
                    if (service != null)
                    {
                        JArray tableDiningMealTimesArray = (JArray)facets.SelectToken("dining");

                        diningType = "Table Service";
                    }
                    else
                    {
                        service = (JArray)facets.SelectToken("quickService");
                        if (service != null)
                        {
                            diningType = "Quick Service";
                        }
                    }
                    restaurant.RestaurantType = diningType;
                    Console.WriteLine(restaurant.RestaurantType);
                }
                catch(NullReferenceException err)
                {
                    Console.WriteLine(err.Message);
                }
                if (restaurant.Id != 0)
                {
                    this.DisneyRestaurants.Add(restaurant);
                    Console.WriteLine("Added restaurant!");
                }

            }
        }
 public FullRestaurantList(AuthToken token)
 {
     populateRestaurantUrls(token);
 }
        private void populateRestaurantUrls(AuthToken token)
        {
            List<String> urls = new List<String>();
            DisneyGetRequest request = new DisneyGetRequest(_fullRestaurantListUrl, token);
            JObject response = JObject.Parse(request.ResponseMessage);

            String total = (String)response.SelectToken("total");
            _totalNumberOfRestaurants = Convert.ToInt32(total);

            JArray entries = (JArray)response.SelectToken("entries");
            foreach(var entry in entries)
            {
                JObject links = (JObject)entry.SelectToken("links");
                JObject self = (JObject)links.SelectToken("self");
                string url = (String)self.SelectToken("href");
                urls.Add(url);
            }

            _restaurantUrls = urls;
        }
        HttpWebRequest IDisneyAuthorizedRequest.setHeadersWithAuthorization(string url, AuthToken token)
        {
            token = token.returnNewTokenWhenExpired();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Headers.Add("Authorization", "Bearer" + " " + token.Token);
            request.ContentType = "application/x-www-form-urlencoded";

            return request;
        }