The following code calls the Get Regions API method that retrieves all regions under which GlobalGiving projects are categorized.
The code example makes use of the Jakarta Commons HttpClient library which can be downloaded here.
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
def getResponseText(url) {
def get = new GetMethod(url)
new HttpClient().executeMethod(get)
BufferedInputStream bis = new BufferedInputStream(get.getResponseBodyAsStream())
return bis.getText('UTF-8')
}
def host = 'https://api.globalgiving.org'
def operation = '/api/public/projectservice/regions'
def api_key = 'YOUR_API_KEY'
def url = "${host}${operation}?api_key=${api_key}"
println getResponseText(url)
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<regions>
<region>
<name>Africa</name>
</region>
<region>
<name>Asia and Oceania</name>
</region>
<region>
<name>Europe and Russia</name>
</region>
<region>
<name>Middle East</name>
</region>
<region>
<name>North America</name>
</region>
<region>
<name>South/Central America and the Caribbean</name>
</region>
</regions>