Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove direct msgraph dependency, updated dependencies #77

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions gcal/get_calendars.go → gcal/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,30 @@ package gcal

import (
"context"
"net/http"

"github.com/pkg/errors"
"google.golang.org/api/calendar/v3"
"google.golang.org/api/option"

"github.com/mattermost/mattermost-plugin-mscalendar/calendar/remote"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/utils/bot"
)

func (c *client) GetCalendars(remoteUserID string) ([]*remote.Calendar, error) {
if true {
return nil, errors.New("gcal GetCalendars not implemented")
}
// CreateCalendar creates a calendar
func (c *client) CreateCalendar(remoteUserID string, calIn *remote.Calendar) (*remote.Calendar, error) {
return nil, errors.New("gcal CreateCalendar not implemented")
}

var v struct {
Value []*remote.Calendar `json:"value"`
}
req := c.rbuilder.Users().ID(remoteUserID).Calendars().Request()
req.Expand("children")
err := req.JSONRequest(c.ctx, http.MethodGet, "", nil, &v)
if err != nil {
return nil, errors.Wrap(err, "msgraph GetCalendars")
}
c.Logger.With(bot.LogContext{
"UserID": remoteUserID,
"v": v.Value,
}).Infof("msgraph: GetUserCalendars returned `%d` calendars.", len(v.Value))
return v.Value, nil
// DeleteCalendar deletes a calendar
func (c *client) DeleteCalendar(remoteUserID string, calID string) error {
return errors.New("gcal DeleteCalendar not implemented")
}

// GetCalendars returns a list of calendars
func (c *client) GetCalendars(remoteUserID string) ([]*remote.Calendar, error) {
return nil, errors.New("gcal GetCalendars not implemented")
}

// GetDefaultCalendar returns the default calendar for the user
func (c *client) GetDefaultCalendar() (*remote.Calendar, error) {
service, err := calendar.NewService(context.Background(), option.WithHTTPClient(c.httpClient))
if err != nil {
Expand All @@ -53,6 +46,7 @@ func (c *client) GetDefaultCalendar() (*remote.Calendar, error) {
return remoteCal, nil
}

// convertGoogleCalendarToRemoteCalendar converts a google calendar to a local representation calendar
func convertGoogleCalendarToRemoteCalendar(cal *calendar.Calendar) *remote.Calendar {
return &remote.Calendar{
ID: cal.Id,
Expand Down
104 changes: 0 additions & 104 deletions gcal/call.go

This file was deleted.

3 changes: 0 additions & 3 deletions gcal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"context"
"net/http"

msgraph "github.com/yaegashi/msgraph.go/v1.0"

"github.com/mattermost/mattermost-plugin-mscalendar/calendar/config"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/utils/bot"
)
Expand All @@ -19,7 +17,6 @@ type client struct {
ctx context.Context

httpClient *http.Client
rbuilder *msgraph.GraphServiceRequestBuilder

conf *config.Config
bot.Logger
Expand Down
30 changes: 0 additions & 30 deletions gcal/create_calendar.go

This file was deleted.

23 changes: 0 additions & 23 deletions gcal/delete_calendar.go

This file was deleted.

48 changes: 4 additions & 44 deletions gcal/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,17 @@ package gcal

import (
"context"
"net/http"
"time"

"github.com/pkg/errors"
msgraph "github.com/yaegashi/msgraph.go/v1.0"
"google.golang.org/api/calendar/v3"
"google.golang.org/api/option"

"github.com/mattermost/mattermost-plugin-mscalendar/calendar/remote"
)

func (c *client) GetEvent(remoteUserID, eventID string) (*remote.Event, error) {
if true {
return nil, errors.New("gcal GetEvent not implemented")
}

e := &remote.Event{}

err := c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).Request().JSONRequest(
c.ctx, http.MethodGet, "", nil, &e)
if err != nil {
return nil, errors.Wrap(err, "msgraph GetEvent")
}
return e, nil
return nil, errors.New("gcal GetEvent not implemented")
}

// CreateEvent creates a calendar event
Expand All @@ -52,42 +39,15 @@ func (c *client) CreateEvent(_ string, in *remote.Event) (*remote.Event, error)
}

func (c *client) AcceptEvent(remoteUserID, eventID string) error {
if true {
return errors.New("gcal AcceptEvent not implemented")
}

dummy := &msgraph.EventAcceptRequestParameter{}
err := c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).Accept(dummy).Request().Post(c.ctx)
if err != nil {
return errors.Wrap(err, "msgraph Accept Event")
}
return nil
return errors.New("gcal AcceptEvent not implemented")
}

func (c *client) DeclineEvent(remoteUserID, eventID string) error {
if true {
return errors.New("gcal DeclineEvent not implemented")
}

dummy := &msgraph.EventDeclineRequestParameter{}
err := c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).Decline(dummy).Request().Post(c.ctx)
if err != nil {
return errors.Wrap(err, "msgraph DeclineEvent")
}
return nil
return errors.New("gcal DeclineEvent not implemented")
}

func (c *client) TentativelyAcceptEvent(remoteUserID, eventID string) error {
if true {
return errors.New("gcal TentativelyAcceptEvent not implemented")
}

dummy := &msgraph.EventTentativelyAcceptRequestParameter{}
err := c.rbuilder.Users().ID(remoteUserID).Events().ID(eventID).TentativelyAccept(dummy).Request().Post(c.ctx)
if err != nil {
return errors.Wrap(err, "msgraph TentativelyAcceptEvent")
}
return nil
return errors.New("gcal TentativelyAcceptEvent not implemented")
}

func (c *client) GetEventsBetweenDates(_ string, start, end time.Time) (events []*remote.Event, err error) {
Expand Down
12 changes: 0 additions & 12 deletions gcal/get_super_user_token.go

This file was deleted.

Loading
Loading