This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticipant.pde
63 lines (53 loc) · 1.9 KB
/
Participant.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Participant {
String name;
long time;
Participant() {
}
void saveScore() {
String url = "http://lego.wunderkraut.com/services/node.xml";
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
// Build the parameters.
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("node[type]", "score"));
formparams.add(new BasicNameValuePair("node[title]", this.name));
formparams.add(new BasicNameValuePair("node[field_time][und][0][value]", Long.toString(this.time)));
UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
httpPost.setEntity(postEntity);
println( "executing request: " + httpPost.getRequestLine() );
HttpResponse response = httpClient.execute( httpPost );
HttpEntity entity = response.getEntity();
//
//
// println("----------------------------------------");
// println( response.getStatusLine() );
// println("----------------------------------------");
//
// if ( entity != null ) entity.writeTo( System.out );
// if ( entity != null ) entity.consumeContent();
//
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpClient.getConnectionManager().shutdown();
}
catch( Exception e ) {
e.printStackTrace();
}
// Also save scores locally.
PrintWriter pw = null;
try {
pw = new PrintWriter(new BufferedWriter(new FileWriter("scores.txt", true)));
pw.println(this.name + "," + this.time);
}
catch (IOException e) {
// Report problem or handle it
}
finally {
if (pw != null) {
pw.close();
}
}
}
}