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

com.evotext.clever.CleverDistrictsClient 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.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import com.evotext.clever.model.District;
import com.evotext.clever.model.Paging;
import com.evotext.clever.model.School;
import com.evotext.clever.model.Section;
import com.evotext.clever.model.Student;
import com.evotext.clever.model.Teacher;
import com.evotext.clever.util.StringUtil;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * The CleverDistrictsClient class is used to execute Clever's "Districts" API end points.
 *  
 * @author brendanclemenzi
 */
public class CleverDistrictsClient extends CleverClient
{
    private String m_districtOAuthToken;
    
    /**
     * 
     */
    public CleverDistrictsClient(String districtOAuthToken)
    {
        this.m_districtOAuthToken = districtOAuthToken;
    }
    
    /**
     * 
     * @param districtOAuthToken
     * @return
     * @throws Exception
     */
    public District getDistrict() throws Exception
    {
        StringBuffer fullApiUrl = new StringBuffer();
        fullApiUrl.append(getBaseUrl());
        fullApiUrl.append("districts");
        
        Map parameters = new HashMap();
                
        JSONObject responseJSON = get(fullApiUrl.toString(), this.m_districtOAuthToken, parameters);
        JSONArray dataJSON = responseJSON.getJSONArray("data");
        
        ObjectMapper mapper = new ObjectMapper();
        List objectList = new ArrayList();
        
        for(int i=0; i  parameters = new HashMap();
        parameters.put("limit", 1);
        
        ObjectMapper mapper = new ObjectMapper();
        JSONObject responseJSON = get(fullApiUrl.toString(), this.m_districtOAuthToken, parameters);
        
        Paging pagingValue = mapper.readValue(responseJSON.getString("paging"),  Paging.class);
        
        BigInteger recordCount = new BigInteger(pagingValue.getTotal());
        return recordCount;
    }
    
    /**
     * 
     * @throws Exception
     */
    public List getDistrictSchools(String districtId, int limit, String startingAfter, String endingBefore) throws Exception
    {
        StringBuffer fullApiUrl = new StringBuffer();
        fullApiUrl.append(getBaseUrl());
        fullApiUrl.append("districts/");
        fullApiUrl.append(districtId);
        fullApiUrl.append("/schools");
        
        Map parameters = new HashMap();
        parameters.put("limit", limit);
        
        if(!StringUtil.isNullOrEmpty(startingAfter))
        {
            parameters.put("starting_after", startingAfter);
        }
        if(!StringUtil.isNullOrEmpty(endingBefore))
        {
            parameters.put("ending_before", endingBefore);
        }
                
        JSONObject responseJSON = get(fullApiUrl.toString(), this.m_districtOAuthToken, parameters);
        JSONArray dataJSON = responseJSON.getJSONArray("data");
        
        ObjectMapper mapper = new ObjectMapper();
        List objectList = new ArrayList();
        
        for(int i=0; i  parameters = new HashMap();
        parameters.put("limit", 1);
                
        JSONObject responseJSON = get(fullApiUrl.toString(), this.m_districtOAuthToken, parameters);
        
        ObjectMapper mapper = new ObjectMapper();
        Paging pagingValue = mapper.readValue(responseJSON.getString("paging"),  Paging.class);
        
        BigInteger recordCount = new BigInteger(pagingValue.getTotal());
        return recordCount;
    }
    
    /**
     * 
     * @throws Exception
     */
    public List getDistrictTeachers(String districtId, int limit, String startingAfter, String endingBefore) throws Exception
    {
        StringBuffer fullApiUrl = new StringBuffer();
        fullApiUrl.append(getBaseUrl());
        fullApiUrl.append("districts/");
        fullApiUrl.append(districtId);
        fullApiUrl.append("/teachers");
        
        Map parameters = new HashMap();
        parameters.put("limit", limit);
        
        if(!StringUtil.isNullOrEmpty(startingAfter))
        {
            parameters.put("starting_after", startingAfter);
        }
        if(!StringUtil.isNullOrEmpty(endingBefore))
        {
            parameters.put("ending_before", endingBefore);
        }
                
        JSONObject responseJSON = get(fullApiUrl.toString(), this.m_districtOAuthToken, parameters);
        JSONArray dataJSON = responseJSON.getJSONArray("data");
        
        ObjectMapper mapper = new ObjectMapper();
        List objectList = new ArrayList();
        
        for(int i=0; i  parameters = new HashMap();
        parameters.put("limit", 1);
                
        JSONObject responseJSON = get(fullApiUrl.toString(), this.m_districtOAuthToken, parameters);
        
        ObjectMapper mapper = new ObjectMapper();
        Paging pagingValue = mapper.readValue(responseJSON.getString("paging"),  Paging.class);
        
        BigInteger recordCount = new BigInteger(pagingValue.getTotal());
        return recordCount;
    }
    
    /**
     * 
     * @param districtOAuthToken
     * @param districtId
     * @param limit
     * @param startingAfter
     * @return
     * @throws Exception
     */
    public List getDistrictStudents(String districtId, int limit, String startingAfter, String endingBefore) throws Exception
    {
        StringBuffer fullApiUrl = new StringBuffer();
        fullApiUrl.append(getBaseUrl());
        fullApiUrl.append("districts/");
        fullApiUrl.append(districtId);
        fullApiUrl.append("/students");
        
        Map parameters = new HashMap();
        parameters.put("limit", limit);
        
        if(!StringUtil.isNullOrEmpty(startingAfter))
        {
            parameters.put("starting_after", startingAfter);
        }
        if(!StringUtil.isNullOrEmpty(endingBefore))
        {
            parameters.put("ending_before", endingBefore);
        }
                
        JSONObject responseJSON = get(fullApiUrl.toString(), this.m_districtOAuthToken, parameters);
        JSONArray dataJSON = responseJSON.getJSONArray("data");
        
        ObjectMapper mapper = new ObjectMapper();
        List objectList = new ArrayList();
        
        for(int i=0; i  parameters = new HashMap();
        parameters.put("limit", 1);
                
        JSONObject responseJSON = get(fullApiUrl.toString(), this.m_districtOAuthToken, parameters);
        
        ObjectMapper mapper = new ObjectMapper();
        Paging pagingValue = mapper.readValue(responseJSON.getString("paging"),  Paging.class);
        
        BigInteger recordCount = new BigInteger(pagingValue.getTotal());
        return recordCount;
    }
    
    /**
     * 
     * @param districtOAuthToken
     * @param districtId
     * @param limit
     * @param startingAfter
     * @return
     * @throws Exception
     */
    public List
getDistrictSections(String districtId, int limit, String startingAfter, String endingBefore) throws Exception { StringBuffer fullApiUrl = new StringBuffer(); fullApiUrl.append(getBaseUrl()); fullApiUrl.append("districts/"); fullApiUrl.append(districtId); fullApiUrl.append("/sections"); Map parameters = new HashMap(); parameters.put("limit", limit); if(!StringUtil.isNullOrEmpty(startingAfter)) { parameters.put("starting_after", startingAfter); } if(!StringUtil.isNullOrEmpty(endingBefore)) { parameters.put("ending_before", endingBefore); } JSONObject responseJSON = get(fullApiUrl.toString(), this.m_districtOAuthToken, parameters); JSONArray dataJSON = responseJSON.getJSONArray("data"); ObjectMapper mapper = new ObjectMapper(); List
objectList = new ArrayList
(); for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy