com.google.api
Class GoogleAPI

java.lang.Object
  extended by com.google.api.GoogleAPI
Direct Known Subclasses:
Detect, Translate

public abstract class GoogleAPI
extends Object

Makes generic Google API functionality available to specific API classes.

Author:
Richard Midwinter, Kramar Tomas

Field Summary
protected static String ENCODING
           
protected static String referrer
          The HTTP referrer attribute.
 
Constructor Summary
GoogleAPI()
           
 
Method Summary
protected static JSONObject retrieveJSON(URL url)
          Forms an HTTP request, sends it using GET method and returns the result of the request as a JSONObject.
protected static JSONObject retrieveJSON(URL url, String parameters)
          Forms an HTTP request, sends it using POST method and returns the result of the request as a JSONObject.
static void setHttpReferrer(String pReferrer)
          Sets the HTTP Referrer.
static void validateReferrer()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING

protected static final String ENCODING
See Also:
Constant Field Values

referrer

protected static String referrer
The HTTP referrer attribute. This allows Google to distinguish between programs.

Constructor Detail

GoogleAPI

public GoogleAPI()
Method Detail

setHttpReferrer

public static void setHttpReferrer(String pReferrer)
Sets the HTTP Referrer.

Parameters:
pReferrer - The HTTP referrer parameter.

validateReferrer

public static void validateReferrer()
                             throws Exception
Throws:
Exception

retrieveJSON

protected static JSONObject retrieveJSON(URL url)
                                  throws Exception
Forms an HTTP request, sends it using GET method and returns the result of the request as a JSONObject.

Parameters:
url - The URL to query for a JSONObject.
Returns:
The translated String.
Throws:
Exception - on error.

retrieveJSON

protected static JSONObject retrieveJSON(URL url,
                                         String parameters)
                                  throws Exception
Forms an HTTP request, sends it using POST method and returns the result of the request as a JSONObject.

Parameters:
url - The URL to query for a JSONObject.
parameters - Additional POST parameters
Returns:
The translated String.
Throws:
Exception - on error.


Copyright © 2011. All Rights Reserved.