Skip to content

Instantly share code, notes, and snippets.

@9SQ 9SQ/Sent.java
Created Aug 17, 2014

Embed
What would you like to do?
カンマ区切り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
You can’t perform that action at this time.