microsoft_graph_api 0.0.2 copy "microsoft_graph_api: ^0.0.2" to clipboard
microsoft_graph_api: ^0.0.2 copied to clipboard

A Flutter package that handles the Microsoft Graph API.

MSGraphAPI Class #

pub package GitHub stars

The MSGraphAPI class serves as a primary point of interaction for working with Microsoft Graph API, providing easy access to various services like users, calendar, meeting rooms, and places.

Properties #

  • me: An instance of the Me class for user-specific operations.
  • users: An instance of the Users class for operations related to all users.
  • calendar: An instance of the Calendar class for calendar-related operations.
  • meetingRooms: An instance of the MeetingRooms class for operations related to meeting rooms.
  • place: An instance of the Place class for place-related operations.

Constructor #

The constructor takes a string parameter, _token, which represents the authentication token for accessing Microsoft Graph API. It initializes instances of Me, Users, Calendar, MeetingRooms, and Place classes.

Usage #

Example #

String token = 'Your Microsoft Graph API token here';
MSGraphAPI graphAPI = MSGraphAPI(token);

// Use the instances
User userInfo = graphAPI.me.fetchUserInfo();
List<Room> allPlaceRooms = graphAPI.place.fetchAllRooms();

Features #

Me

Fetch User Information

The fetchUserInfo method is used to fetch the user's information from the Microsoft Graph API. The method sends a GET request and does not require any parameters. It returns a Future<User> object that represents the user's information.

User user = await graphAPI.me.fetchUserInfo();

Change Password

The changePassword method is used to change the user's password. It requires two parameters: currentPassword and newPassword, which represent the current and new passwords, respectively. The method sends a PATCH request to the Microsoft Graph API and returns a Future<bool> indicating the success of the operation.

bool isChanged = await graphAPI.me.changePassword(currentPassword, newPassword);

Fetch User Profile Image

The fetchUserProfileImage method is used to fetch the user's profile image from the Microsoft Graph API. The method sends a GET request and requires a size parameter, which specifies the desired size of the image. It returns a `Future

ImageProvider image = await graphAPI.me.fetchUserProfileImage(size);
Users

Fetch Specific User Information

The fetchSpecificUserInfo method is used to fetch the user's information for a specific user from the Microsoft Graph API. The method sends a GET request and requires the userId parameter. It returns a Future<User> object that represents the user's information.

User user = await graphAPI.users.fetchSpecificUserInfo(userId);

Create User

The createUser method is used to create a new user. It requires four parameters: displayName, mailNickname, userPrincipalName, and password. The method sends a POST request to the Microsoft Graph API and returns a Future<User> object representing the newly created user.

User newUser = await Users.createUser(displayName, mailNickname, userPrincipalName, password);

Delete User

The deleteUser method is used to delete a user. It requires the userId parameter and sends a DELETE request to the Microsoft Graph API. It returns a Future

bool success = await Users.deleteUser(userId);

Fetch All User Rooms (Beta)

The fetchAllUserRooms method is used to fetch all user rooms. This method sends a GET request to the 'findRooms' endpoint of the Microsoft Graph API and converts the response data into a list of 'Room' objects. It returns a Future<List

List<Room> rooms = await Users.fetchAllUserRooms();
Calendar

Fetch Calendar Events for Range

The fetchCalendarEventsForRange method is used to fetch calendar events within a specific date range. The method sends a GET request and requires the startDateTime and endDateTime parameters. It returns a Future<List<CalendarEvent>> object that represents the calendar events within the given date range.

List<CalendarEvent> events = await Calendar.fetchCalendarEventsForRange(startDateTime, endDateTime);

Create Calendar Event

The createCalendarEvent method is used to create a calendar event via the Microsoft Graph API. It performs a POST request to create the calendar event. The request requires an authorization header with the bearer token. This method accepts a range of optional parameters representing various attributes of the event to be created.

The parameters include id, createdDateTime, lastModifiedDateTime, isReminderOn, subject, bodyPreview, isAllDay, isOrganizer, startDateTime, endDateTime, a list of attendees, and organizer.

If a parameter is provided, it's included in the data sent in the request. If attendees or organizer are provided, they're converted to JSON before being included in the request data.

The function tries to create a calendar event and returns a Future that completes with a CalendarEvent if the request was successful. If an error occurs during the request, an error message is logged and the error is rethrown.

await Calendar.createCalendarEvent(
    id: 'event1',
    createdDateTime: '2023-06-21T10:00:00.000Z',
    lastModifiedDateTime: '2023-06-21T10:00:00.000Z',
    isReminderOn: true,
    subject: 'Important Meeting',
    bodyPreview: 'Discussing project status',
    isAllDay: false,
    isOrganizer: true,
    startDateTime: '2023-06-22T10:00:00.000Z',
    endDateTime: '2023-06-22T12:00:00.000Z',
    attendees: [Attendee(name: 'John Doe', email: 'johndoe@example.com')],
    organizer: Organizer(name: 'Jane Doe', email: 'janedoe@example.com')
);

Fetch Calendars

The fetchCalendars method is used to fetch calendar objects from the Microsoft Graph API. It performs a GET request to obtain the calendars. The request requires an authorization header with the bearer token. This method accepts one optional parameter userId to specify whose calendars to fetch. If userId is not provided, the calendars of the current user will be fetched.

The function attempts to fetch the calendars and returns a Future that completes with a list of Calendar objects if the request was successful. If an error occurs during the request, it prints an error message and rethrows the error.

List<Calendar> myCalendars = await Calendar.fetchCalendars();
List<Calendar> usersCalendars = await Calendar.fetchCalendars(userId: 'UserId here');

Find Meeting Times

The findMeetingTimes method is used to suggest meeting times based on availability data from the Microsoft Graph API. It performs a POST request to fetch the suggested meeting times. The request requires an authorization header with the bearer token. This method accepts optional parameters including userId, attendees, timeSlots, locationConstraint, and meetingDuration.

The parameters work as follows:

userId: The ID of the user for whom to find meeting times. If not provided, the current user is assumed. attendees: A list of attendees for the meeting. timeSlots: A list of available time slots for the meeting. locationConstraint: The constraints on the location of the meeting. meetingDuration: The duration of the meeting. The function creates a map from the provided parameters, converts it to JSON, and includes it in the body of the POST request. It then attempts to fetch the meeting time suggestions and returns a Future that completes with a MeetingTimeSuggestionsResult` object if the request was successful. If an error occurs during the request, it prints an error message and rethrows the error.

MeetingTimeSuggestionsResult otherUsersMeetingTimes = await Calendar.findMeetingTimes(
    userId: 'user1',
    attendees: [Attendee(name: 'John Doe', email: 'johndoe@example.com')],
    timeSlots: [TimeSlot(start: '2023-06-22T09:00:00.000Z', end: '2023-06-22T18:00:00.000Z')],
    locationConstraint: LocationConstraint(isRequired: false, suggestLocation: false),
    meetingDuration: 'PT1H' //The length of the meeting, denoted in ISO8601 format. For example, 1 hour is denoted as 'PT1H', where 'P' is the duration designator, 'T' is the time designator, and 'H' is the hour designator. Use M to indicate minutes for the duration; for example, 2 hours and 30 minutes would be 'PT2H30M'. If no meeting duration is specified, findMeetingTimes uses the default of 30 minutes.
);

MeetingTimeSuggestionsResult myMeetingTimes = await Calendar.findMeetingTimes(
attendees: [Attendee(name: 'John Doe', email: 'johndoe@example.com')],
timeSlots: [TimeSlot(start: '2023-06-22T09:00:00.000Z', end: '2023-06-22T18:00:00.000Z')],
locationConstraint: LocationConstraint(isRequired: false, suggestLocation: false),
meetingDuration: 'PT1H' //The length of the meeting, denoted in ISO8601 format. For example, 1 hour is denoted as 'PT1H', where 'P' is the duration designator, 'T' is the time designator, and 'H' is the hour designator. Use M to indicate minutes for the duration; for example, 2 hours and 30 minutes would be 'PT2H30M'. If no meeting duration is specified, findMeetingTimes uses the default of 30 minutes.
);
MeetingRooms

Book Meeting Room

The bookMeetingRoom method is used to book a meeting room by creating a new event. It requires a Map<String, dynamic> parameter representing the event to be created. This event should represent the booking of the meeting room. The method sends a POST request to the Microsoft Graph API. If the request is successful, it logs a success message. If the request fails, it logs the error message.

await MeetingRooms.bookMeetingRoom(event);
Place

Fetch All Rooms

The fetchAllRooms method is used to fetch all the rooms from the Microsoft Graph API. It performs a GET request for the rooms. The request requires an authorization header with the bearer token. If the request is successful, it logs the rooms. If there's an error during the request, it logs an error message.

Future<List<Room>> rooms = Place.fetchAllRooms();

Fetch All Room Lists

The fetchAllRoomLists method is used to fetch all the room lists from the Microsoft Graph API. It performs a GET request for the room lists. The request requires an authorization header with the bearer token. If the request is successful, it logs the room lists. If there's an error during the request, it logs an error message.

Future<List<Room>> rooms = Place.fetchAllRooms();
14
likes
0
pub points
79%
popularity

Publisher

verified publisherkahle.dev

A Flutter package that handles the Microsoft Graph API.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, equatable, flutter, mockito

More

Packages that depend on microsoft_graph_api