إدارة دعوات الدورات التدريبية

يمثّل Invitation مورد في Classroom دعوة موجّهة إلى مستخدم للانضمام إلى دورة تدريبية بدور محدّد في الدورة التدريبية: طالب أو معلّم أو مالك.

يحتوي كل مرجع Invitation على الحقول التالية:

  • id: معرّف الدعوة الذي خصّصته Classroom.
  • userId: رقم تعريف المستخدم الذي تمت دعوته إلى الدورة التدريبية.
  • courseId: الدورة التدريبية التي تتم دعوة المستخدم إليها.
  • role: الدور في الدورة التدريبية الذي سيحصل عليه المستخدم المدعو في الدورة التدريبية.

إنشاء دعوة

يمكن استخدام طريقة invitations.create() لدعوة مستخدم إلى دورة تدريبية بدور معيّن. أدرِج Invitation المصدر في نص الطلب، وحدِّد courseId وuserId وrole.

جافا

classroom/snippets/src/main/java/CreateInvitation.java
Invitation invitation = null;
try {
  /* Set the role the user is invited to have in the course. Possible values of CourseRole can be
  found here: https://developers.google.com/classroom/reference/rest/v1/invitations#courserole.*/
  Invitation content =
      new Invitation().setCourseId(courseId).setUserId(userId).setRole("TEACHER");

  invitation = service.invitations().create(content).execute();

  System.out.printf(
      "User (%s) has been invited to course (%s).\n",
      invitation.getUserId(), invitation.getCourseId());
} catch (GoogleJsonResponseException e) {
  // TODO (developer) - handle error appropriately
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("The course or user does not exist.\n");
  }
  throw e;
} catch (Exception e) {
  throw e;
}
return invitation;

استرداد دعوة

يمكنك استرداد دعوة معيّنة من خلال استدعاء طريقة invitations.get() وتحديد id للدعوة.

جافا

classroom/snippets/src/main/java/GetInvitation.java
Invitation invitation = null;
try {
  invitation = service.invitations().get(id).execute();
  System.out.printf(
      "Invitation (%s) for user (%s) in course (%s) retrieved.\n",
      invitation.getId(), invitation.getUserId(), invitation.getCourseId());
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("The invitation id (%s) does not exist.\n", id);
  }
  throw e;
} catch (Exception e) {
  throw e;
}
return invitation;

قبول دعوة

يؤدي قبول الدعوة إلى حذفها وإضافة المستخدم المدعو إلى الدورة التدريبية بالدور المحدّد في الدعوة. يمكنك قبول دعوة من خلال استدعاء طريقة invitations.accept() وتحديد id للدعوة.

جافا

classroom/snippets/src/main/java/AcceptInvitation.java
try {
  service.invitations().accept(id).execute();
  System.out.printf("Invitation (%s) was accepted.\n", id);
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("The invitation id (%s) does not exist.\n", id);
  }
  throw e;
} catch (Exception e) {
  throw e;
}

حذف دعوة

الطريقة الوحيدة لتعديل دعوة هي حذفها وإنشاء دعوة جديدة. لحذف الدعوة، استدعِ الدالة invitations.delete() وحدِّد id.

جافا

classroom/snippets/src/main/java/DeleteInvitation.java
try {
  service.invitations().delete(id).execute();
  System.out.printf("Invitation (%s) was deleted.\n", id);
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("The invitation id (%s) does not exist.\n", id);
  }
  throw e;
} catch (Exception e) {
  throw e;
}