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

Examples of com.google.api.explorer.client.base.dynamicjso.DynamicJso



  public void testRequestParameters() {
    ApiRequest req = generateRequest(path, body, headers, method);

    DynamicJso obj = (DynamicJso) CrossDomainRequest.convertRequest(req);

    assertEquals(path, obj.getString("url"));
    assertEquals(body, obj.getString("body"));
    assertEquals(method.name(), obj.getString("httpMethod"));

    String ctHeaderVal = ((DynamicJso) obj.get("headers")).getString("Content-Type");
    assertEquals("application/json", ctHeaderVal);
  }
View Full Code Here


  public void testAlternateBase() {
    Config.setBaseUrl("https://www.googleapis.com/alternate/base/path");

    ApiRequest req = generateRequest(path, body, headers, method);

    DynamicJso obj = (DynamicJso) CrossDomainRequest.convertRequest(req);

    assertEquals(path, obj.getString("url"));
    assertEquals(body, obj.getString("body"));
    assertEquals(method.name(), obj.getString("httpMethod"));

    String ctHeaderVal = ((DynamicJso) obj.get("headers")).getString("Content-Type");
    assertEquals("application/json", ctHeaderVal);
  }
View Full Code Here

    }
    canceled = true;
  }

  static JavaScriptObject convertRequest(ApiRequest request) {
    DynamicJso headers = DynamicJso.createObject().cast();
    for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) {
      headers.set(entry.getKey(), entry.getValue());
    }

    return DynamicJso
        .createObject()
        .<DynamicJso>cast()
View Full Code Here

  private static ErrorCase getErrorMessage(ApiResponse response) {
    // This requires a try-catch because there is no way to proactively check
    // that the JSON is both present and valid without just trying to parse it.
    try {
      DynamicJso jso = JsonUtils.safeEval(response.getBodyAsString());
      if (jso.get("error") != null) {
        return ErrorCase.forJsonString(response.getBodyAsString());
      }
    } catch (IllegalArgumentException e) {
      // Not valid json, definitely not an error payload.
    }
View Full Code Here

      // sake of my sanity, syntax highlighting is disabled in Development
      destination.add(new InlineLabel(jsonString));
    } else {

      try {
        DynamicJso root = JsonUtils.<DynamicJso>safeEval(jsonString);
        Collection<ApiMethod> compatibleMethods = computeCompatibleMethods(root, service);
        Widget menuForMethods = createRequestMenu(compatibleMethods, service, root, linkFactory);
        JsObjectIterable rootObject = new JsObjectIterable(service, root, 1, linkFactory);
        Widget object = formatGroup(rootObject, "", 0, "{", "}", false, menuForMethods);
        destination.add(object);
View Full Code Here

        return formatGroup(
            new JsArrayIterable(service, obj.<DynamicJsArray>get(index), depth + 1, linkFactory),
            title, depth, "[", "]", hasSeparator, null);

      case OBJECT:
        DynamicJso subObject = obj.<DynamicJso>get(index);

        // Determine if this object can be used as the request parameter for another method.
        Collection<ApiMethod> compatibleMethods = computeCompatibleMethods(subObject, service);
        Widget menuFromMethods =
            createRequestMenu(compatibleMethods, service, subObject, linkFactory);
View Full Code Here

        return formatGroup(
            new JsArrayIterable(service, obj.<DynamicJsArray>get(key), depth + 1, linkFactory),
            title, depth, "[", "]", hasSeparator, null);

      case OBJECT:
        DynamicJso subObject = obj.<DynamicJso>get(key);

        // Determine if this object can be used as the request parameter for another method.
        Collection<ApiMethod> compatibleMethods = computeCompatibleMethods(subObject, service);
        JsObjectIterable objIter = new JsObjectIterable(service, subObject, depth + 1, linkFactory);
        return formatGroup(objIter, title, depth, "{", "}", hasSeparator, null);
View Full Code Here

    return headers;
  }

  /** Instantiates a response from the JS object representation of a response. */
  public static ApiResponse fromData(JavaScriptObject data) {
    DynamicJso jso = data.cast();

    return new ApiResponse(jso);
  }
View Full Code Here

  /**
   * Inspects the headers object of the given JS object and constructs a
   * {@link Map} of its keys and values.
   */
  private static Map<String, HeaderValue> createHeadersMap(DynamicJso data) {
    DynamicJso headers = data.get("headers");
    JsArrayString keys = headers.keys();
    Map<String, HeaderValue> headersMap = Maps.newHashMapWithExpectedSize(keys.length());

    for (int i = 0; i < keys.length(); i++) {
      String key = keys.get(i);
      String value = "";
      switch (headers.typeofKey(key)) {
        case STRING:
          value = headers.getString(key);
          break;

        case BOOLEAN:
          value = String.valueOf(headers.getBoolean(key));
          break;

        case NUMBER:
          value = String.valueOf(headers.getInteger(key));
          break;

        case INTEGER:
          value = String.valueOf(headers.getDouble(key));
          break;
      }
      headersMap.put(key.toLowerCase(), new HeaderValue(key, value));

    }
View Full Code Here

TOP

Related Classes of com.google.api.explorer.client.base.dynamicjso.DynamicJso

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.