public String getFriends(String streamId, long userId, int cursor) throws IOException, ControlStreamException { Endpoint endpoint = SitestreamEndpoint.friendsEndpoint(streamId); endpoint.addPostParameter(Constants.USER_ID_PARAM, Long.toString(userId)); endpoint.addPostParameter(Constants.CURSOR_PARAM, Integer.toString(cursor)); HttpUriRequest request = HttpConstants.constructRequest(hosts.nextHost(), endpoint, auth); HttpResponse response = makeControlStreamRequest(request); return consumeHttpEntityContent(response); }
public static HttpUriRequest constructRequest(String host, Endpoint endpoint, Authentication auth) { String url = host + endpoint.getURI(); if (endpoint.getHttpMethod().equalsIgnoreCase(HttpGet.METHOD_NAME)) { HttpGet get = new HttpGet(url); if (auth != null) auth.signRequest(get, null); return get; } else if (endpoint.getHttpMethod().equalsIgnoreCase(HttpPost.METHOD_NAME) ) { HttpPost post = new HttpPost(url); post.setEntity(new StringEntity(endpoint.getPostParamString(), Constants.DEFAULT_CHARSET)); post.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); if (auth != null) auth.signRequest(post, endpoint.getPostParamString()); return post; } else { throw new IllegalArgumentException("Bad http method: " + endpoint.getHttpMethod()); } } }
public void removeUsers(String streamId, Collection<Long> userIds) throws IOException, ControlStreamException { Preconditions.checkArgument(userIds.size() >= 1 && userIds.size() <= 100, "The userId parameter can be supplied with up to 100 user IDs."); Endpoint endpoint = SitestreamEndpoint.removeUserEndpoint(streamId); endpoint.addPostParameter(Constants.USER_ID_PARAM, Joiner.on(',').join(userIds)); HttpUriRequest request = HttpConstants.constructRequest(hosts.nextHost(), endpoint, auth); consumeHttpEntityContent(makeControlStreamRequest(request)); }
public void addUsers(String streamId, Collection<Long> userIds) throws IOException, ControlStreamException { Preconditions.checkArgument(userIds.size() >= 1 && userIds.size() <= 100, "The userId parameter can be supplied with up to 100 user IDs."); Endpoint endpoint = SitestreamEndpoint.addUserEndpoint(streamId); endpoint.addPostParameter(Constants.USER_ID_PARAM, Joiner.on(',').join(userIds)); HttpUriRequest request = HttpConstants.constructRequest(hosts.nextHost(), endpoint, auth); consumeHttpEntityContent(makeControlStreamRequest(request)); }
/** * TODO: This must be limited to 25 adds per seconds */ public void addUser(String streamId, long userId) throws IOException, ControlStreamException { Endpoint endpoint = SitestreamEndpoint.addUserEndpoint(streamId); endpoint.addPostParameter(Constants.USER_ID_PARAM, Long.toString(userId)); HttpUriRequest request = HttpConstants.constructRequest(hosts.nextHost(), endpoint, auth); consumeHttpEntityContent(makeControlStreamRequest(request)); }
public void removeUser(String streamId, long userId) throws IOException, ControlStreamException { Endpoint endpoint = SitestreamEndpoint.removeUserEndpoint(streamId); endpoint.addPostParameter(Constants.USER_ID_PARAM, Long.toString(userId)); HttpUriRequest request = HttpConstants.constructRequest(hosts.nextHost(), endpoint, auth); consumeHttpEntityContent(makeControlStreamRequest(request)); }