pub struct RequestParameter {
pub name: String,
pub value: String,
}
macro_rules! api_parameter {
(
$(#[$outer:meta])*
$name:ident => $name_output:expr,
$(
$(#[$option_outer:meta])*
$option:ident => $option_output:expr ,
)* $(,)?
) => {
$(#[$outer])*
pub enum $name {
$(
$(#[$option_outer])*
$option,
)*
}
impl From<$name> for RequestParameter {
fn from(value: $name) -> Self {
RequestParameter {
name: $name_output.into(),
value: match value {
$(<$name>::$option => $option_output,)*
}.into(),
}
}
}
impl std::str::FromStr for $name {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
$($option_output => Ok(Self::$option),)*
_ => Err(()),
}
}
}
};
(
$(#[$outer:meta])*
$name:ident => $name_output:expr
) => {
$(#[$outer])*
pub struct $name<'i>(pub &'i str);
impl<'i> From<$name<'i>> for RequestParameter {
fn from(value: $name) -> Self {
RequestParameter {
name: $name_output.into(),
value: value.0.into(),
}
}
}
};
}
api_parameter! {
UserId => "user_id"
}
api_parameter! {
#[derive(Debug)]
EnrollmentType => "enrollment_type[]",
Teacher => "teacher",
Student => "student",
StudentView => "student_view",
TA => "ta",
Observer => "observer",
Designer => "designer",
}
api_parameter! {
#[derive(Debug)]
SortOn => "sort",
Username => "username",
LastLogin => "last_login",
Email => "email",
SisId => "sis_id",
}
api_parameter! {
EnrollmentState => "enrollment_state[]",
Active => "active",
Invited => "invited",
Rejected => "rejected",
Completed => "completed",
Inactive => "inactive",
InvitedOrPending => "invited_or_pending",
}
api_parameter! {
Include => "include[]",
Enrollments => "enrollments",
Locked => "locked",
AvatarUrl => "avatar_url",
TestStudent => "test_student",
Bio => "bio",
CustomLinks => "custom_links",
CurrentGradingPeriodScores => "current_grading_period_scores",
Uuid => "uuid",
NeedsGradingCount => "needs_grading_count",
SyllabusBody => "syllabus_body",
PublicDescription => "public_description",
TotalScores => "total_scores",
Term => "term",
Account => "account",
CourseProgress => "course_progress",
Sections => "sections",
StorageQuotaUsedMb => "storage_quota_used_mb",
TotalStudents => "total_students",
PassbackStatus => "passback_status",
Favorites => "favorites",
Teachers => "teachers",
ObservedUsers => "observed_users",
CourseImage => "course_image",
Concluded => "concluded",
}