Package com.google.api.explorer.client.base.rest

Examples of com.google.api.explorer.client.base.rest.RestApiRequest


    return body.isEmpty() ? null : Iterables.getLast(body);
  }

  public void submit() {
    Preconditions.checkState(method != null);
    final RestApiRequest req = new RestApiRequest(service, method);

    // If the user has declared a body, set it on the request.
    String body = display.getBodyText();
    if (!body.isEmpty()) {
      req.body = body;
      req.addHeader("Content-Type", "application/json");
    }

    Multimap<String, String> paramValues = display.getParameterValues();
    for (Map.Entry<String, String> entry : paramValues.entries()) {
      if (entry.getValue().isEmpty()) {
        continue;
      }
      req.getParamValues().put(entry.getKey(), entry.getValue());
    }

    // Do not send the API key if the service is a public-only API.
    req.setUseApiKey(
        !ExplorerConfig.PUBLIC_ONLY_APIS.contains(service.getName()));

    // Set the auth header if we have a token.
    AuthToken oauth2Token = authManager.getToken(service);
    if (oauth2Token != null) {
      req.addHeader("Authorization", "Bearer " + oauth2Token.getAuthToken());
    }

    display.setExecuting(true);

    final long start = System.currentTimeMillis();
    req.send(new AsyncCallback<ApiResponse>() {
      @Override
      public void onSuccess(ApiResponse response) {
        display.setExecuting(false);
        callback.finished(req, response, start, System.currentTimeMillis());
      }
View Full Code Here


   * @param callback to execute when the {@link ApiService} has been created.
   */
  public void createService(final String serviceName, final String version,
      final CallStyle callStyle, final AsyncCallback<ApiService> callback) {

    RestApiRequest request =
        new RestApiRequest(createDiscoveryPath(serviceName, version, callStyle));

    // If a Discovery Auth token is set, use it.
    if (Config.getDiscoveryAuthToken() != null) {
      request.addHeader("Authorization", "OAuth " + Config.getDiscoveryAuthToken());
    }

    request.send(new AsyncCallback<ApiResponse>() {
      @Override
      public void onSuccess(ApiResponse response) {
        // Determine if we got a 3XX or 4XX response and call failure if so.
        int responseClass = response.getStatus() / 100;
        if (responseClass > 3) {
View Full Code Here

   * the Discovery service.
   *
   * @param callback Callback to notify of success or failure.
   */
  public void loadApiDirectory(final AsyncCallback<Set<ServiceDefinition>> callback) {
    RestApiRequest request = new RestApiRequest(Config.DIRECTORY_REQUEST_PATH);
    request.send(new AsyncCallback<ApiResponse>() {
      @Override
      public void onSuccess(ApiResponse response) {
        ApiDirectory directory = ApiDirectory.Helper.fromString(response.getBodyAsString());
        callback.onSuccess(directory.getItems());
      }
View Full Code Here

TOP

Related Classes of com.google.api.explorer.client.base.rest.RestApiRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.