public void PlacesDetailWithOptions_ValidRequestWithWebsite() { FIELDS_LIST.Add(Places.PlacesDetailFields.WEBSITE); Task <Tuple <Places.PlacesDetailResponse, ResponseStatus> > details = placesDetail.GetPlaceDetailsWithOptions(PLACE_ID_NYC, fields: FIELDS_LIST); details.Wait(); Places.PlacesDetailResponse response = details.Result.Item1; Places.PlacesDetailResult detailResult = response.Result; ResponseStatus status = details.Result.Item2; // Verify that the result list is of expected size Assert.IsNotNull(response); Assert.IsNotNull(detailResult); Assert.IsNotNull(detailResult.Website); Assert.IsNotEmpty(detailResult.Website); // Verify that the Status returned for the request is OK Assert.AreSame(status, Places.PlacesStatus.OK); FIELDS_LIST.Clear(); }
public void PlacesDetailWithOptions_ValidRequestWithAddressComponent() { FIELDS_LIST.Add(Places.PlacesDetailFields.ADDRESS_COMPONENT); Task <Tuple <Places.PlacesDetailResponse, ResponseStatus> > details = placesDetail.GetPlaceDetailsWithOptions(PLACE_ID_WL, fields: FIELDS_LIST); details.Wait(); Places.PlacesDetailResponse response = details.Result.Item1; Places.PlacesDetailResult detailResult = response.Result; ResponseStatus status = details.Result.Item2; // Verify that the result list is of expected size Assert.IsNotNull(response); Assert.IsNotNull(detailResult); Assert.IsNotNull(detailResult.AddressComponents); Assert.GreaterOrEqual(detailResult.AddressComponents.Count, 1); // Verify that the Status returned for the request is OK Assert.AreSame(status, Places.PlacesStatus.OK); FIELDS_LIST.Clear(); }
public void PlacesDetailWithOptions_ValidRequestWithUTCOffset() { FIELDS_LIST.Add(Places.PlacesDetailFields.UTC_OFFSET); Task <Tuple <Places.PlacesDetailResponse, ResponseStatus> > details = placesDetail.GetPlaceDetailsWithOptions(PLACE_ID_NYC, fields: FIELDS_LIST); details.Wait(); Places.PlacesDetailResponse response = details.Result.Item1; Places.PlacesDetailResult detailResult = response.Result; ResponseStatus status = details.Result.Item2; // Verify that the result list is of expected size Assert.IsNotNull(response); Assert.IsNotNull(detailResult); Assert.IsNotNull(detailResult.UtcOffset); Assert.GreaterOrEqual(detailResult.UtcOffset, -12 * 60); Assert.LessOrEqual(detailResult.UtcOffset, 12 * 60); // Verify that the Status returned for the request is OK Assert.AreSame(status, Places.PlacesStatus.OK); FIELDS_LIST.Clear(); }
public void PlacesDetailWithOptions_ValidRequestWithOpeningHours() { FIELDS_LIST.Add(Places.PlacesDetailFields.OPENING_HOURS); Task <Tuple <Places.PlacesDetailResponse, ResponseStatus> > details = placesDetail.GetPlaceDetailsWithOptions(PLACE_ID_NYC, fields: FIELDS_LIST); details.Wait(); Places.PlacesDetailResponse response = details.Result.Item1; Places.PlacesDetailResult detailResult = response.Result; ResponseStatus status = details.Result.Item2; // Verify that the result list is of expected size Assert.IsNotNull(response); Assert.IsNotNull(detailResult); Assert.IsNotNull(detailResult.OpeningHours); Assert.IsNotNull(detailResult.OpeningHours.Periods); Assert.GreaterOrEqual(detailResult.OpeningHours.Periods.Count, 1); Assert.IsNotNull(detailResult.OpeningHours.WeekdayText); Assert.GreaterOrEqual(detailResult.OpeningHours.WeekdayText.Count, 1); // Verify that the Status returned for the request is OK Assert.AreSame(status, Places.PlacesStatus.OK); FIELDS_LIST.Clear(); }
public void PlacesDetailWithOptions_ValidRequestWithGeometry() { FIELDS_LIST.Add(Places.PlacesDetailFields.GEOMETRY); Task <Tuple <Places.PlacesDetailResponse, ResponseStatus> > details = placesDetail.GetPlaceDetailsWithOptions(PLACE_ID_WL, fields: FIELDS_LIST); details.Wait(); Places.PlacesDetailResponse response = details.Result.Item1; Places.PlacesDetailResult detailResult = response.Result; ResponseStatus status = details.Result.Item2; // Verify that the result list is of expected size Assert.IsNotNull(response); Assert.IsNotNull(detailResult); Assert.IsNotNull(detailResult.Geometry); Assert.IsNotNull(detailResult.Geometry.Location); Assert.IsNotNull(detailResult.Geometry.Viewport); // Verify that the Status returned for the request is OK Assert.AreSame(status, Places.PlacesStatus.OK); FIELDS_LIST.Clear(); }
public void PlacesDetailWithOptions_ValidRequest() { Task <Tuple <Places.PlacesDetailResponse, ResponseStatus> > details = placesDetail.GetPlaceDetailsWithOptions(PLACE_ID_WL); details.Wait(); Places.PlacesDetailResponse response = details.Result.Item1; Places.PlacesDetailResult detailResult = response.Result; ResponseStatus status = details.Result.Item2; // Verify that the result list is of expected size Assert.IsNotNull(response); Assert.IsNotNull(detailResult); // Verify that the place result result is as expected Assert.IsNotNull(detailResult.AddressComponents); Assert.GreaterOrEqual(detailResult.AddressComponents.Count, 1); Assert.IsNotNull(detailResult.AdrAddress); Assert.IsNotEmpty(detailResult.AdrAddress); Assert.IsNotNull(detailResult.FormattedAddress); Assert.IsNotEmpty(detailResult.FormattedAddress); Assert.IsNotNull(detailResult.Geometry); Assert.IsNotNull(detailResult.Icon); Assert.IsNotEmpty(detailResult.Icon); Assert.IsNotNull(detailResult.Name); Assert.IsNotEmpty(detailResult.Name); Assert.IsNotNull(detailResult.PlaceId); Assert.IsNotEmpty(detailResult.PlaceId); Assert.IsNotNull(detailResult.PlusCode); Assert.IsNotNull(detailResult.Reference); Assert.IsNotEmpty(detailResult.Reference); Assert.IsNotNull(detailResult.Types); Assert.GreaterOrEqual(detailResult.Types.Count, 1); Assert.IsNotNull(detailResult.Url); Assert.IsNotEmpty(detailResult.Url); Assert.IsNotNull(detailResult.Vicinity); Assert.IsNotEmpty(detailResult.Vicinity); // Verify that the Status returned for the request is OK Assert.AreSame(status, Places.PlacesStatus.OK); }
public void PlacesDetailWithOptions_ValidRequestWithReviews() { FIELDS_LIST.Add(Places.PlacesDetailFields.REVIEW); Task <Tuple <Places.PlacesDetailResponse, ResponseStatus> > details = placesDetail.GetPlaceDetailsWithOptions(PLACE_ID_NYC, fields: FIELDS_LIST); details.Wait(); Places.PlacesDetailResponse response = details.Result.Item1; Places.PlacesDetailResult detailResult = response.Result; ResponseStatus status = details.Result.Item2; // Verify that the result list is of expected size Assert.IsNotNull(response); Assert.IsNotNull(detailResult); Assert.IsNotNull(detailResult.Reviews); Assert.GreaterOrEqual(detailResult.Reviews.Count, 1); Assert.IsNotNull(detailResult.Reviews[0].AuthorName); Assert.IsNotEmpty(detailResult.Reviews[0].AuthorName); Assert.IsNotNull(detailResult.Reviews[0].AuthorUrl); Assert.IsNotEmpty(detailResult.Reviews[0].AuthorUrl); Assert.IsNotNull(detailResult.Reviews[0].Language); Assert.IsNotEmpty(detailResult.Reviews[0].Language); Assert.IsNotNull(detailResult.Reviews[0].ProfilePhotoUrl); Assert.IsNotEmpty(detailResult.Reviews[0].ProfilePhotoUrl); Assert.GreaterOrEqual(detailResult.Reviews[0].Rating, 1); Assert.IsNotNull(detailResult.Reviews[0].RelativeTimeDescription); Assert.IsNotEmpty(detailResult.Reviews[0].RelativeTimeDescription); Assert.IsNotNull(detailResult.Reviews[0].Text); Assert.IsNotEmpty(detailResult.Reviews[0].Text); // Verify that the Status returned for the request is OK Assert.AreSame(status, Places.PlacesStatus.OK); FIELDS_LIST.Clear(); }
public void PlacesDetailWithOptions_ValidRequestWithAllOptions() { FIELDS_LIST.Add(Places.PlacesDetailFields.ADDRESS_COMPONENT); FIELDS_LIST.Add(Places.PlacesDetailFields.ADR_ADDRESS); FIELDS_LIST.Add(Places.PlacesDetailFields.FORMATTED_ADDRESS); FIELDS_LIST.Add(Places.PlacesDetailFields.FORMATTED_PHONE_NUMBER); FIELDS_LIST.Add(Places.PlacesDetailFields.GEOMETRY); FIELDS_LIST.Add(Places.PlacesDetailFields.ICON); FIELDS_LIST.Add(Places.PlacesDetailFields.ID); FIELDS_LIST.Add(Places.PlacesDetailFields.INTERNATIONAL_PHONE_NUMBER); FIELDS_LIST.Add(Places.PlacesDetailFields.NAME); FIELDS_LIST.Add(Places.PlacesDetailFields.OPENING_HOURS); FIELDS_LIST.Add(Places.PlacesDetailFields.PHOTOS); FIELDS_LIST.Add(Places.PlacesDetailFields.PLACE_ID); FIELDS_LIST.Add(Places.PlacesDetailFields.PLUS_CODE); FIELDS_LIST.Add(Places.PlacesDetailFields.PRICE_LEVEL); FIELDS_LIST.Add(Places.PlacesDetailFields.RATING); FIELDS_LIST.Add(Places.PlacesDetailFields.REVIEW); FIELDS_LIST.Add(Places.PlacesDetailFields.SCOPE); FIELDS_LIST.Add(Places.PlacesDetailFields.TYPES); FIELDS_LIST.Add(Places.PlacesDetailFields.URL); FIELDS_LIST.Add(Places.PlacesDetailFields.UTC_OFFSET); FIELDS_LIST.Add(Places.PlacesDetailFields.VICINITY); FIELDS_LIST.Add(Places.PlacesDetailFields.WEBSITE); Task <Tuple <Places.PlacesDetailResponse, ResponseStatus> > details = placesDetail.GetPlaceDetailsWithOptions(PLACE_ID_NYC, fields: FIELDS_LIST); details.Wait(); Places.PlacesDetailResponse response = details.Result.Item1; Places.PlacesDetailResult detailResult = response.Result; ResponseStatus status = details.Result.Item2; // Verify that theresult list is of expected size Assert.IsNotNull(response); Assert.IsNotNull(detailResult); // Verifying AddressComponents Assert.IsNotNull(detailResult.AddressComponents); Assert.GreaterOrEqual(detailResult.AddressComponents.Count, 1); // Verifying AdrAddress Assert.IsNotNull(detailResult.AdrAddress); Assert.IsNotEmpty(detailResult.AdrAddress); // Verifying FormattedAddress Assert.IsNotNull(detailResult.FormattedAddress); Assert.IsNotEmpty(detailResult.FormattedAddress); // Verifying FormattedPhoneNumber Assert.IsNotNull(detailResult.FormattedPhoneNumber); Assert.IsNotEmpty(detailResult.FormattedPhoneNumber); // Verifying Geometry Assert.IsNotNull(detailResult.Geometry); Assert.IsNotNull(detailResult.Geometry.Location); Assert.IsNotNull(detailResult.Geometry.Viewport); // Verifying Icon Assert.IsNotNull(detailResult.Icon); Assert.IsNotEmpty(detailResult.Icon); // Verifying InternationalPhoneNumber Assert.IsNotNull(detailResult.InternationalPhoneNumber); Assert.IsNotEmpty(detailResult.InternationalPhoneNumber); // Verifying Name Assert.IsNotNull(detailResult.Name); Assert.IsNotEmpty(detailResult.Name); // Verifying OpeningHours Assert.IsNotNull(detailResult.OpeningHours); Assert.IsNotNull(detailResult.OpeningHours.Periods); Assert.GreaterOrEqual(detailResult.OpeningHours.Periods.Count, 1); Assert.IsNotNull(detailResult.OpeningHours.WeekdayText); Assert.GreaterOrEqual(detailResult.OpeningHours.WeekdayText.Count, 1); // Verifying PlaceId Assert.IsNotNull(detailResult.PlaceId); Assert.IsNotEmpty(detailResult.PlaceId); Assert.AreEqual(detailResult.PlaceId, PLACE_ID_NYC); // Verifying PlusCode Assert.IsNotNull(detailResult.PlusCode); Assert.IsNotNull(detailResult.PlusCode.CompoundCode); Assert.IsNotEmpty(detailResult.PlusCode.CompoundCode); Assert.IsNotNull(detailResult.PlusCode.GlobalCode); Assert.IsNotEmpty(detailResult.PlusCode.GlobalCode); // Verifying Photos Assert.IsNotNull(detailResult.Photos); Assert.GreaterOrEqual(detailResult.Photos.Count, 1); // Verifying Reviews Assert.IsNotNull(detailResult.Reviews); Assert.GreaterOrEqual(detailResult.Reviews.Count, 1); Assert.IsNotNull(detailResult.Reviews[0].AuthorName); Assert.IsNotEmpty(detailResult.Reviews[0].AuthorName); Assert.IsNotNull(detailResult.Reviews[0].AuthorUrl); Assert.IsNotEmpty(detailResult.Reviews[0].AuthorUrl); Assert.IsNotNull(detailResult.Reviews[0].Language); Assert.IsNotEmpty(detailResult.Reviews[0].Language); Assert.IsNotNull(detailResult.Reviews[0].ProfilePhotoUrl); Assert.IsNotEmpty(detailResult.Reviews[0].ProfilePhotoUrl); Assert.GreaterOrEqual(detailResult.Reviews[0].Rating, 1); Assert.IsNotNull(detailResult.Reviews[0].RelativeTimeDescription); Assert.IsNotEmpty(detailResult.Reviews[0].RelativeTimeDescription); Assert.IsNotNull(detailResult.Reviews[0].Text); Assert.IsNotEmpty(detailResult.Reviews[0].Text); // Verifying Scope Assert.IsNotNull(detailResult.Scope); Assert.IsNotEmpty(detailResult.Scope); // Verifying Types Assert.IsNotNull(detailResult.Types); Assert.GreaterOrEqual(detailResult.Types.Count, 1); // Verifying Url Assert.IsNotNull(detailResult.Url); Assert.IsNotEmpty(detailResult.Url); // Verifying UTC_Offset Assert.IsNotNull(detailResult.UtcOffset); Assert.GreaterOrEqual(detailResult.UtcOffset, -12 * 60); Assert.LessOrEqual(detailResult.UtcOffset, 12 * 60); // Verifying Vicinity Assert.IsNotNull(detailResult.Vicinity); Assert.IsNotEmpty(detailResult.Vicinity); // Verifying Website Assert.IsNotNull(detailResult.Website); Assert.IsNotEmpty(detailResult.Website); // Verify that the Status returned for the request is OK Assert.AreSame(status, Places.PlacesStatus.OK); FIELDS_LIST.Clear(); }
/* * Method: GetPlacesDetail * * Description: This method can be used to query the Places API for details regarding places with a * specific place_id. The place_id is usually obtained from the response of a Place Search function. * * Parameters: * - place_id (String): A String identifier that uniquely identifies a place. This is returned as part * of the response from the Place Search functions. For more details about place_id: * https://developers.google.com/places/web-service/place-id * * - APIKey (String): Implicity required paramter which should be set through the constructor when * creating an object of this class. For more details about the Google API Key please see: * https://developers.google.com/places/web-service/get-api-key * * Return: The method returns a tuple of two items. The first is an object of PlacesDetailResponse * which contains all available details for the place. The second element is a ResponseStatus object * indicating the status of the query along with the appropiate HTTP code. The tuple wrapped in a Task<> * because the method makes Asynchronous HTTP requests to the Places API. */ public async Task <Tuple <PlacesDetailResponse, ResponseStatus> > GetPlaceDetails(String place_id) { if (BasicFunctions.isEmpty(APIKey)) { return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, PlacesStatus.MISSING_API_KEY)); } if (BasicFunctions.isEmpty(place_id)) { return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, PlacesStatus.MISSING_PLACE_ID)); } // Creating the HTTP query url String HTTP_query = $"details/json?placeid={place_id}&key={APIKey}"; // Setting up the request header to indicate that the request body will be in json httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Making an asynchronous HTTP GET request to the Places API and collecting the output HttpResponseMessage response = await httpClient.GetAsync(HTTP_query); Stream stream = await response.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(stream); String response_str = streamReader.ReadToEnd(); Console.WriteLine(response_str); /* * Here we do a two-step hop again to achieve the appropriate return value: * We use the response string (response_str) from above and attempt to convert it back from json to * NearbySearchResultList, the expected return object for a successful query. This produces one of * two possibilities: * 1. If the response string is not a json of the NearbySearchResultList class, then we either get * a JsonSerializationException or an empty list. In this case we print out the response and * return null (Will improve this to return an appropriate error code). * 2. If the response string is as expected a json of NearbySearchResultList, then things go * smoothly and we return that. */ if (response.IsSuccessStatusCode) { try { PlacesDetailResponse resultList = JsonConvert.DeserializeObject <PlacesDetailResponse>(response_str); if (!resultList.Status.Equals("OK")) { // If the response status from the API is not OK, then we try to return the most appropriate Error ResponseStatus status = PlacesStatus.ProcessErrorMessage(resultList.Status, resultList.Error_message); return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, status)); } else if (resultList.Result == null) { // If the response provides an empty response set, then we return the ZERO_RESULTS (204) error return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, PlacesStatus.ZERO_RESULTS)); } else { return(new Tuple <PlacesDetailResponse, ResponseStatus>(resultList, PlacesStatus.OK)); } } catch (JsonSerializationException e) { // If the deserialization of the response fails, then we return an error Console.WriteLine("Exception: " + e.StackTrace); return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, PlacesStatus.DESERIALIZATION_ERROR)); } } else { // If the response status from the API is not a success, then we return an error using the data returned return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, new ResponseStatus((int)response.StatusCode, response.ReasonPhrase))); } }
/* * Method: GetPlacesDetailWithOptions * * Description: This method can be used to query the Places API for details regarding places with a * specific place_id. The optional parameters can be used to determine the language of the response * as well as what infromation is returned. If no fields are provided, then the query returns all * available fields. * * Parameters: * - place_id (String): A String identifier that uniquely identifies a place. This is returned as part * of the response from the Place Search functions. For more details about place_id: * https://developers.google.com/places/web-service/place-id * * - region_code (String): This is an OPTIONAL parameter, that indicates the region code, specified as a * ccTLD format. This is used to influence the query's results but relevant results outside the * region may also be included. * - fields (List<PlacesDetailFields>): OPTIONAL parameter. This is a list of details you wish to get * about the places that match the query. If the list is empty or null, then the Places API will * return all available details by default. * - language_code (String): OPTIONAL parameter indicating the language in which results will be returned. * By default this is set to English. List of supported languages and their codes: * https://developers.google.com/maps/faq#languagesupport * * - APIKey (String): Implicity required paramter which should be set through the constructor when * creating an object of this class. For more details about the Google API Key please see: * https://developers.google.com/places/web-service/get-api-key * * Return: The method returns a tuple of two items. The first is an object of PlacesDetailResponse * which contains all available details for the place. The second element is a ResponseStatus object * indicating the status of the query along with the appropiate HTTP code. The tuple wrapped in a Task<> * because the method makes Asynchronous HTTP requests to the Places API. */ public async Task <Tuple <PlacesDetailResponse, ResponseStatus> > GetPlaceDetailsWithOptions(String place_id, String region_code = "", String language_code = "", String session_token = "", List <PlacesDetailFields> fields = null) { if (BasicFunctions.isEmpty(APIKey)) { return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, PlacesStatus.MISSING_API_KEY)); } if (BasicFunctions.isEmpty(place_id)) { return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, PlacesStatus.MISSING_PLACE_ID)); } // Creating the HTTP query url String HTTP_query = $"details/json?placeid={place_id}"; // Appending any optional fields that are set if (!BasicFunctions.isEmpty(region_code)) { HTTP_query += $"®ion={region_code}"; } if (!BasicFunctions.isEmpty(language_code)) { HTTP_query += $"&language={language_code}"; } if (!BasicFunctions.isEmpty(session_token)) { HTTP_query += $"&sessiontoken={session_token}"; } if (fields != null && fields.Count != 0) { HTTP_query += $"&fields={BasicFunctions.getPlacesDetailFieldsListString(fields)}"; } HTTP_query += $"&key={APIKey}"; // Setting up the request header to indicate that the request body will be in json httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Making an asynchronous HTTP GET request to the Places API and collecting the output HttpResponseMessage response = await httpClient.GetAsync(HTTP_query); Stream stream = await response.Content.ReadAsStreamAsync(); StreamReader streamReader = new StreamReader(stream); String response_str = streamReader.ReadToEnd(); // Similar two-step hop as in prior functions if (response.IsSuccessStatusCode) { try { PlacesDetailResponse resultList = JsonConvert.DeserializeObject <PlacesDetailResponse>(response_str); if (!resultList.Status.Equals("OK")) { // If the response status from the API is not OK, then we try to return the most appropriate Error ResponseStatus status = PlacesStatus.ProcessErrorMessage(resultList.Status, resultList.Error_message); return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, status)); } else if (resultList.Result == null) { // If the response provides an empty response set, then we return the ZERO_RESULTS (204) error return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, PlacesStatus.ZERO_RESULTS)); } else { return(new Tuple <PlacesDetailResponse, ResponseStatus>(resultList, PlacesStatus.OK)); } } catch (JsonSerializationException e) { // If the deserialization of the response fails, then we return an error Debug.WriteLine("Exception: " + e.StackTrace); return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, PlacesStatus.DESERIALIZATION_ERROR)); } } else { // If the response status from the API is not a success, then we return an error using the data returned return(new Tuple <PlacesDetailResponse, ResponseStatus>(null, new ResponseStatus((int)response.StatusCode, response.ReasonPhrase))); } }