<commit_before>/**
 * Copyright 2013 Twitter, Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

package com.twitter.hbc;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.io.CharStreams;
import com.google.common.primitives.Longs;
import com.twitter.hbc.core.Constants;
import com.twitter.hbc.core.Hosts;
import com.twitter.hbc.core.HttpConstants;
import com.twitter.hbc.core.endpoint.Endpoint;
import com.twitter.hbc.core.endpoint.SitestreamEndpoint;
import com.twitter.hbc.httpclient.ControlStreamException;
import com.twitter.hbc.httpclient.auth.Authentication;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;

import static com.twitter.hbc.core.Constants.DEFAULT_CHARSET;

public class SitestreamController {

  private static final Logger logger = LoggerFactory.getLogger(SitestreamController.class);

  private final HttpClient client;
  private final Hosts hosts;
  private final Authentication auth;

  public SitestreamController(HttpClient client, Hosts hosts, Authentication auth) {
    this.client = Preconditions.checkNotNull(client);
    this.hosts = Preconditions.checkNotNull(hosts);
    this.auth = Preconditions.checkNotNull(auth);
  }

  /**
   * TODO: This must be limited to 25 adds per seconds
   */
  public void addUser(String streamId, long userId) throws IOException, ControlStreamException {
    addUsers(streamId, Longs.asList(userId));
  }

  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));
  }

  public void removeUser(String streamId, long userId) throws IOException, ControlStreamException {
    removeUsers(streamId, Longs.asList(userId));
  }

  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 String getFriends(String streamId, long userId) throws IOException, ControlStreamException {
    return getFriends(streamId, userId, 0);
  }

  public String getFriends(String streamId, long userId, int cursor) throws IOException, ControlStreamException {<commit_msg>Updated addUser and removeUser so they do not proxy to addUsers, removeUsers in order to minimize merge issues.<commit_after>/**
 * Copyright 2013 Twitter, Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

package com.twitter.hbc;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.io.CharStreams;
import com.twitter.hbc.core.Constants;
import com.twitter.hbc.core.Hosts;
import com.twitter.hbc.core.HttpConstants;
import com.twitter.hbc.core.endpoint.Endpoint;
import com.twitter.hbc.core.endpoint.SitestreamEndpoint;
import com.twitter.hbc.httpclient.ControlStreamException;
import com.twitter.hbc.httpclient.auth.Authentication;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;

import static com.twitter.hbc.core.Constants.DEFAULT_CHARSET;

public class SitestreamController {

  private static final Logger logger = LoggerFactory.getLogger(SitestreamController.class);

  private final HttpClient client;
  private final Hosts hosts;
  private final Authentication auth;

  public SitestreamController(HttpClient client, Hosts hosts, Authentication auth) {
    this.client = Preconditions.checkNotNull(client);
    this.hosts = Preconditions.checkNotNull(hosts);
    this.auth = Preconditions.checkNotNull(auth);
  }

  /**
   * 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));
  }

  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));
  }

  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 String getFriends(String streamId, long userId) throws IOException, ControlStreamException {
    return getFriends(streamId, userId, 0);
  }

  public String getFriends(String streamId, long userId, int cursor) throws IOException, ControlStreamException {
{'fraction_non_alphanumeric': 0.09250208606508523, 'fraction_numerical': 0.006437000834426034, 'mean_word_length': 5.539360872954014, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6614087', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2236, 'n_words': 623}