Esempio n. 1
0
  @NonNull
  private static JSONResult request(
      final OCApiConnector connector, final OkapiService service, final Parameters params) {
    if (connector == null) {
      return new JSONResult("unknown OKAPI connector");
    }

    final String host = connector.getHost();
    if (StringUtils.isBlank(host)) {
      return new JSONResult("unknown OKAPI connector host");
    }

    params.add("langpref", getPreferredLanguage());

    if (connector.getSupportedAuthLevel() == OAuthLevel.Level3) {
      final OAuthTokens tokens = new OAuthTokens(connector);
      if (!tokens.isValid()) {
        return new JSONResult("invalid oauth tokens");
      }
      OAuth.signOAuth(
          host,
          service.methodName,
          "GET",
          false,
          params,
          tokens,
          connector.getCK(),
          connector.getCS());
    } else {
      connector.addAuthentication(params);
    }

    final String uri = "http://" + host + service.methodName;
    return new JSONResult(Network.getRequest(uri, params));
  }
Esempio n. 2
0
  private static JSONObject request(
      final OCApiConnector connector, final OkapiService service, final Parameters params) {
    if (connector == null) {
      return null;
    }

    final String host = connector.getHost();
    if (StringUtils.isBlank(host)) {
      return null;
    }

    params.add("langpref", getPreferredLanguage());

    if (connector.getSupportedAuthLevel() == OAuthLevel.Level3) {
      OAuth.signOAuth(
          host,
          service.methodName,
          "GET",
          false,
          params,
          Settings.getOCDETokenPublic(),
          Settings.getOCDETokenSecret(),
          connector.getCK(),
          connector.getCS());
    } else {
      connector.addAuthentication(params);
    }

    final String uri = "http://" + host + service.methodName;
    return Network.requestJSON(uri, params);
  }