Skip to content

Commit

Permalink
[+] Encapsulate restoreSession()
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed Dec 6, 2019
1 parent 256ce4e commit b91698e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main/java/org/hydev/veracross/sdk/VeracrossHttpClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.hydev.veracross.sdk;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.hydev.veracross.sdk.model.*;
import org.hydev.veracross.sdk.model.VeraLegacyCourse.CourseListContainer;

Expand Down Expand Up @@ -36,8 +38,8 @@ public class VeracrossHttpClient extends GeneralHttpClient
public static final String API_DIRECTORY = "directory/entries.json";
public static final String API_ASSIGNMENT_MARK_READ = "enrollment/mark_notification_read";

public static String WEB_GRADING = "https://documents.veracross.com/" + SCHOOL_CODE + "/grade_detail/%s" +
"?grading_period=%s&key=_";
public static String WEB_GRADING =
"https://documents.veracross.com/" + SCHOOL_CODE + "/grade_detail/%s?grading_period=%s&key=_";
public static final String WEB_CSRF_TOKEN = "student/directory"; // Because it has the smallest html

public static String LEGACY_URL_BASE = "https://portals.veracross.com/" + SCHOOL_CODE + "/";
Expand All @@ -57,6 +59,19 @@ public void loginSJP(String username, String ssoToken) throws IOException
"token", ssoToken).close();
}

/**
* Restore cookie session
*
* @param session Session token
*/
public void restoreSession(String session)
{
restoreCookies(new Gson().fromJson("[{\"name\":\"_veracross_session\",\"attribs\":" +
"{\"path\":\"/\",\"domain\":\".veracross.com\"},\"value\":\"" + session +
"\",\"cookieDomain\":\"veracross.com\",\"cookiePath\":\"/\",\"isSecur" +
"e\":true,\"cookieVersion\":0}]", new TypeToken<List<BasicClientCookie>>(){}.getType()));
}

/**
* Get the list of courses.
*
Expand Down

0 comments on commit b91698e

Please sign in to comment.