Skip to content

Instantly share code, notes, and snippets.

@9SQ
Created August 17, 2014 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9SQ/1f9b66b15c1cd2457286 to your computer and use it in GitHub Desktop.
Save 9SQ/1f9b66b15c1cd2457286 to your computer and use it in GitHub Desktop.
カンマ区切りusername宛にYoを送信
package sent_yo;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
public class Sent {
private static final String server = "http://api.justyo.co/yo/";
private static final String token = "YOUR_API_TOKEN_HERE";
private static final HttpClient client = HttpClientBuilder.create().build();
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.out.println("Usage: java -jar sent_yo.jar [username(comma separated username)]");
System.exit(-1);
}
String[] split = args[0].split(",");
for (int i = 0; i < split.length; i++) {
if (yo(split[i]))
System.out.println("ok - " + split[i]);
else
System.out.println("failure - " + split[i]);
}
}
public static boolean yo(String username) throws ClientProtocolException, IOException {
HttpPost post = new HttpPost(server);
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("api_token", token));
params.add(new BasicNameValuePair("username", username));
post.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = client.execute(post);
if (response.getStatusLine().getStatusCode() == 200)
return true;
else
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment