All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.evotext.clever.CleverClient Maven / Gradle / Ivy

Go to download

The Clever-Java project is a Java wrapper for the Clever.com API for keeping educational applications rostered and up-to-date.

There is a newer version: 2.0.0
Show newest version
package com.evotext.clever;

import java.util.Map;

import org.json.JSONObject;

import com.goebl.david.Webb;
import com.goebl.david.WebbException;

/**
 * The CleverClient is used as our base client abstraction to cover a number of our common methods 
 *  
 * @author brendanclemenzi
 */
abstract class CleverClient
{
    private String m_apiUrl = "https://api.clever.com";
    private String m_version = "v1.1";
    
    /**
     * 
     * @param apiUrl
     * @param oAuthToken
     * @param parameters
     * @return
     */
    protected JSONObject get(String apiUrl, String oAuthToken, Map parameters)
    {
        Webb webb = Webb.create();
        webb.setDefaultHeader(Webb.HDR_AUTHORIZATION, "Bearer " + oAuthToken);
        
        JSONObject jsonObject = null;
        
        try 
        {
            jsonObject = webb.get(apiUrl)
                .params(parameters)
                .ensureSuccess()
                .asJsonObject()
                .getBody();
        }
        catch (WebbException we)
        {
            System.out.println(we);
            jsonObject = new JSONObject();
        }
        
        return jsonObject;
    }
    
    /**
     * 
     * @return
     */
    protected String getBaseUrl()
    {
        return this.m_apiUrl + "/" + this.m_version + "/";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy