/*
* Copyright 2015 Google Inc. All rights reserved.
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.google.maps;
import com.google.gson.FieldNamingPolicy;
import com.google.maps.errors.ApiException;
import com.google.maps.internal.ApiConfig;
import com.google.maps.internal.ApiResponse;
import com.google.maps.model.PlaceDetails;
/**
* A <a href="https://developers.google.com/places/web-service/details#PlaceDetailsRequests">Place
* Details</a> request.
*/
public class PlaceDetailsRequest
extends PendingResultBase<PlaceDetails, PlaceDetailsRequest, PlaceDetailsRequest.Response> {
static final ApiConfig API_CONFIG = new ApiConfig("/maps/api/place/details/json")
.fieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
public PlaceDetailsRequest(GeoApiContext context) {
super(context, API_CONFIG, Response.class);
}
/**
* Get the Place Details for the specified Place ID. Required.
*/
public PlaceDetailsRequest placeId(String placeId) {
return param("placeid", placeId);
}
@Override
protected void validateRequest() {
if (!params().containsKey("placeid")) {
throw new IllegalArgumentException("Request must contain 'placeId'.");
}
}
static class Response implements ApiResponse<PlaceDetails> {
public String status;
public PlaceDetails result;
public String[] htmlAttributions;
public String errorMessage;
@Override
public boolean successful() {
return "OK".equals(status) || "ZERO_RESULTS".equals(status);
}
@Override
public PlaceDetails getResult() {
if (result != null) {
result.htmlAttributions = htmlAttributions;
}
return result;
}
@Override
public ApiException getError() {
if (successful()) {
return null;
}
return ApiException.from(status, errorMessage);
}
}
}