1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//! Enums containing types of information which can be used for various API calls

/// Service handles
#[derive(Debug)]
pub enum WebServiceHandle {
    PXPWebServices,
    HDInfoServices,
}

/// Various methods necessary to retrieve different types of API data
#[derive(Debug)]
pub enum Method {
    Attendance,
    StudentHealthInfo,
    GetStudentDocumentInitialData,
    GradeBook,
    StudentCalendar,
    TestWebServiceURL,
    ChildList,
    GetSupportedLanguages,
    GetContentOfAttachedDoc,
    StudentCalendarAssignmentDetails,
    SaveSoundFileData,
    UploadGBDocDataForStudentAssignment,
    StudentHWNotes,
    UpdateStudentHWNotes,
    StudentInfo,
    UpdatePXPMessage,
    StudentSchoolInfo,
    UpdateDeviceToken,
    StudentDisciplineInfo,
    GenerateAuthToken,
    StudentConference,
    GetMatchingDistrictList,
    StudentFee,
    PXPContentClassWebSiteGetFileXML,
    GetPXPMessages,
    GetContentUserDefinedModule,
    GetSoundFileData,
    GetAttachedDocToAssignment,
    GetClassWebSiteData,
    GetContentOfGBAttachedDoc,
    GetReportCardInitialData,
    GetReportCardDocumentData,
    GetSpecialEdData,
    StudentClassList,
}

/// Language codes for xml responses
#[derive(Debug, PartialEq, PartialOrd)]
pub enum Language {
    English = 0,
    Spanish = 1,
}

/// Different types of parameters needed for certain methods
#[derive(Debug, PartialEq)]
pub enum ParamType<'a> {
    ChildIntID(u64),
    HealthConditions(u64),
    HealthVisits(bool),
    HealthImmunizations(bool),
    ReportPeriod(u64),
    ConcurrentSchOrgYearGU(&'a str),
    LoadAllTerms,
    RequestDate(&'a str),
    AssignmentID(&'a str),
    LanguageCode(u64),
    ClassGU(&'a str),
    StudentClassList(&'a str),
    SoundFileListing(&'a str),
    GBDocumentData(&'a str),
    Key,
    MatchToDistrictZipCode(&'a str),
}

impl<'p> ToString for ParamType<'p> {
    fn to_string(&self) -> String {
        match self {
            ParamType::ChildIntID(id) => format!("<ChildIntID>{}</ChildIntID>", id),
            ParamType::HealthConditions(c) => format!("<HealthConditions>{}</HealthConditions>", c),
            ParamType::HealthVisits(v) => format!("<HealthVisits>{}</HealthVisits>", v),
            ParamType::HealthImmunizations(imm) => format!("<HealthImmunizations>{}</HealthImmunizations>", imm),
            ParamType::ConcurrentSchOrgYearGU(gu) => format!("<ConcurrentSchOrgYearGU>{}</ConcurrentSchOrgYearGU>", gu),
            ParamType::ReportPeriod(period) => format!("<ReportPeriod>{}</ReportPeriod>", period),
            ParamType::StudentClassList(list) => format!("<StudentClassList>{}</StudentClassList>", list),
            ParamType::RequestDate(date) => format!("<RequestDate>{}</RequestDate>", date),
            ParamType::LanguageCode(lang_id) => format!("<LanguageCode>{}</LanguageCode>", lang_id),
            ParamType::ClassGU(class_gu) => format!("<ClassGU>{}</ClassGU>", class_gu),
            ParamType::AssignmentID(id) => format!("<AssignmentID>{}</AssignmentID>", id),
            ParamType::SoundFileListing(listing) => format!("<SoundFileListing>{}</SoundFileListing>", listing),
            ParamType::GBDocumentData(data) => format!("<GBDocumentData>{}</GBDocumentData>", data),
            ParamType::Key => String::from("<Key>5E4B7859-B805-474B-A833-FDB15D205D40</Key>"),
            ParamType::MatchToDistrictZipCode(zip) => format!("<MatchToDistrictZipCode>{}</MatchToDistrictZipCode>", zip),
            ParamType::LoadAllTerms => String::from("<LoadAllTerms>true</LoadAllTerms>")
        }
    }
}

impl<'w> Into<&'w str> for WebServiceHandle {
    fn into(self) -> &'w str {
        match self {
            WebServiceHandle::PXPWebServices => "PXPWebServices",
            WebServiceHandle::HDInfoServices => "HDInfoServices",
        }
    }
}

impl<'m> Into<&'m str> for Method {
    fn into(self) -> &'m str {
        match self {
            Method::Attendance => "Attendance",
            Method::StudentHealthInfo => "StudentHealthInfo",
            Method::GetStudentDocumentInitialData => "GetStudentDocumentInitialData",
            Method::GradeBook => "Gradebook",
            Method::StudentCalendar => "StudentCalendar",
            Method::TestWebServiceURL => "TestWebServiceURL",
            Method::ChildList => "ChildList",
            Method::GetSupportedLanguages => "GetSupportedLanguages",
            Method::GetContentOfAttachedDoc => "GetContentOfAttachedDoc",
            Method::StudentCalendarAssignmentDetails => "StudentCalendarAssignmentDetails",
            Method::SaveSoundFileData => "SaveSoundFileData",
            Method::UploadGBDocDataForStudentAssignment => "UploadGBDocumentDataForStudentAssigment",
            Method::StudentHWNotes => "StudentHWNotes",
            Method::UpdateStudentHWNotes => "UpdateStudentHWNotes",
            Method::StudentInfo => "StudentInfo",
            Method::UpdatePXPMessage => "UpdatePXPMessage",
            Method::StudentSchoolInfo => "StudentSchoolInfo",
            Method::UpdateDeviceToken => "UpdateDeviceToken",
            Method::StudentDisciplineInfo => "StudentDisciplineInfo",
            Method::GenerateAuthToken => "GenerateAuthToken",
            Method::StudentConference => "StudentConference",
            Method::GetMatchingDistrictList => "GetMatchingDistrictList",
            Method::StudentFee => "StudentFee",
            Method::PXPContentClassWebSiteGetFileXML => "PXPContentCLassWebSiteGetFileXML",
            Method::GetPXPMessages => "GetPXPMessages",
            Method::GetContentUserDefinedModule => "GetContentUserDefinedModule",
            Method::GetSoundFileData => "GetSoundFileData",
            Method::GetAttachedDocToAssignment => "GetAttachedDocToAssignment",
            Method::GetClassWebSiteData => "GetClassWebSiteData",
            Method::GetContentOfGBAttachedDoc => "GetContentOfGBAttachedDoc",
            Method::GetReportCardInitialData => "GetReportCardInitialData",
            Method::GetReportCardDocumentData => "GetReportCardDocumentData",
            Method::GetSpecialEdData => "GetSpecialEdData",
            Method::StudentClassList => "StudentClassList",
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn format_test() {
        let param = ParamType::ReportPeriod(7);
        assert_eq!(&param.to_string()[..], "<ReportPeriod>7</ReportPeriod>")
    }
}