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

edu.ksu.canvas.impl.SisImportImpl Maven / Gradle / Ivy

The newest version!
package edu.ksu.canvas.impl;

import com.google.gson.reflect.TypeToken;
import edu.ksu.canvas.interfaces.SisImportReader;
import edu.ksu.canvas.interfaces.SisImportWriter;
import edu.ksu.canvas.model.SisImport;
import edu.ksu.canvas.net.Response;
import edu.ksu.canvas.net.RestClient;
import edu.ksu.canvas.oauth.OauthToken;
import edu.ksu.canvas.requestOptions.CreateSisImportOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

public class SisImportImpl extends BaseImpl implements SisImportReader, SisImportWriter {

    private static final Logger LOG = LoggerFactory.getLogger(SisImportImpl.class);

    public SisImportImpl(String canvasBaseUrl, Integer apiVersion, OauthToken oauthToken, RestClient restClient,
                      int connectTimeout, int readTimeout, Integer paginationPageSize, Boolean serializeNulls) {
        super(canvasBaseUrl, apiVersion, oauthToken, restClient, connectTimeout, readTimeout,
                paginationPageSize, serializeNulls);
    }

    @Override
    public  Optional getSisImport(String accountId, Long id) throws IOException {
        LOG.debug("getting sis import");
        String url = buildCanvasUrl("accounts/" + accountId + "/sis_imports/" + id.toString(), Collections.emptyMap());
        Response response = canvasMessenger.getSingleResponseFromCanvas(oauthToken, url);
        return responseParser.parseToObject(SisImport.class, response);
    }

    @Override
    public Optional createSisImport(CreateSisImportOptions options) throws IOException {
        LOG.debug("creating sis import");
        String url = buildCanvasUrl("accounts/" + options.getAccountId() + "/sis_imports", Collections.emptyMap());
        Response response = canvasMessenger.sendFileToCanvas(oauthToken, url, options.getOptionsMap(), CreateSisImportOptions.ATTACHMENT, options.getFilePath(), options.getInputStream());
        return responseParser.parseToObject(SisImport.class, response);
    }

    @Override
    protected Type listType() {
        return new TypeToken>(){}.getType();
    }

    @Override
    protected Class objectType() {
        return SisImport.class;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy