예제 #1
0
  final <T extends ServerResponse> T doPost(CommandArguments args, Class<T> clazz, String url)
      throws FlickrException {
    try {
      OAuthRequest request = new OAuthRequest(Verb.POST, url);

      // check for proxy, use if available
      if (proxy != null) {
        request.setProxy(proxy);
      }

      for (Map.Entry<String, Object> param : args.getParameters().entrySet()) {
        if (param.getValue() instanceof String) {
          request.addQuerystringParameter(param.getKey(), (String) param.getValue());
        }
      }

      oauth.signRequest(request);

      MultipartEntity multipart = args.getBody(request.getOauthParameters());
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      multipart.writeTo(baos);

      request.addPayload(baos.toByteArray());
      request.addHeader("Content-type", multipart.getContentType().getValue());

      Response response = request.send();
      String body = response.getBody();

      return parseBody(args, clazz, body);

    } catch (IOException ex) {
      throw new UnsupportedOperationException("Error preparing multipart request", ex);
    }
  }
예제 #2
0
  final <T extends ServerResponse> T doGet(CommandArguments args, Class<T> clazz)
      throws FlickrException {
    OAuthRequest request = new OAuthRequest(Verb.GET, URL_PREFIX);

    // check for proxy, use if available
    if (proxy != null) {
      request.setProxy(proxy);
    }

    for (Map.Entry<String, Object> param : args.getParameters().entrySet()) {
      request.addQuerystringParameter(param.getKey(), String.valueOf(param.getValue()));
    }

    oauth.signRequest(request);
    Response response = request.send();
    String body = response.getBody();

    return parseBody(args, clazz, body);
  }