View Javadoc

1   package net.sf.gaeappmanager.google.appengine;
2   
3   import net.sf.gaeappmanager.google.LogonHelper;
4   
5   import org.apache.http.HttpResponse;
6   import org.apache.http.client.methods.HttpGet;
7   import org.apache.http.impl.client.DefaultHttpClient;
8   
9   /**
10   * Google App Engine application manager.
11   * 
12   * @author Alois Belaska
13   */
14  public class Manager {
15  
16  	/**
17  	 * Retrieve quota details of application deployed in Google App Engine.
18  	 * 
19  	 * @param userid
20  	 *            full gmail address for user
21  	 * @param password
22  	 *            gmail account password
23  	 * @param source
24  	 *            name of application requesting quota details
25  	 * @param application
26  	 *            appspot application name
27  	 * @return quota details of application
28  	 * @throws Exception
29  	 *             in case of failure
30  	 */
31  	public static QuotaDetails retrieveAppQuotaDetails(String userid,
32  			String password, String source, String application)
33  			throws Exception {
34  		String authCookie = LogonHelper.loginToGoogleAppEngine(userid,
35  				password, source);
36  
37  		DefaultHttpClient client = new DefaultHttpClient();
38  
39  		try {
40  			HttpGet get = new HttpGet(
41  					"https://appengine.google.com/dashboard/quotadetails?&app_id="
42  							+ application);
43  			get.setHeader("Cookie", "ACSID=" + authCookie);
44  
45  			HttpResponse response = client.execute(get);
46  
47  			return new QuotaDetailsParser().parse(response.getEntity()
48  					.getContent());
49  		} finally {
50  			client.getConnectionManager().shutdown();
51  		}
52  	}
53  }