কোর্সের আমন্ত্রণগুলি পরিচালনা করুন

ক্লাসরুমের একটি Invitation রিসোর্স হলো কোনো ব্যবহারকারীকে একটি নির্দিষ্ট কোর্স রোল —যেমন শিক্ষার্থী, শিক্ষক বা মালিক—সহ একটি কোর্সে যোগদানের জন্য আমন্ত্রণ।

প্রতিটি Invitation রিসোর্সে নিম্নলিখিত ফিল্ডগুলো থাকে:

  • id : আমন্ত্রণপত্রের জন্য শ্রেণীকক্ষ কর্তৃক নির্ধারিত শনাক্তকারী।
  • userId : কোর্সে আমন্ত্রিত ব্যবহারকারীর আইডি।
  • courseId : যে কোর্সে ব্যবহারকারীকে আমন্ত্রণ জানানো হচ্ছে।
  • role : কোর্সে আমন্ত্রিত ব্যবহারকারীর যে ভূমিকা থাকবে।

একটি আমন্ত্রণ তৈরি করুন

invitations.create() মেথডটি ব্যবহার করে কোনো ব্যবহারকারীকে একটি নির্দিষ্ট রোলসহ কোর্সে আমন্ত্রণ জানানো যায়। রিকোয়েস্ট বডিতে Invitation রিসোর্সটি অন্তর্ভুক্ত করুন এবং courseId , userIdrole উল্লেখ করুন।

জাভা

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;
}