Skip to content

Commit b9de397

Browse files
authored
refactor: define interfaces for Google API clients (#58)
Add interface definitions for Gmail, Calendar, and Contacts clients to enable unit testing through mock implementations. - GmailClientInterface: GetMessage, SearchMessages, GetThread, FetchLabels, GetLabelName, GetLabels, GetAttachments, DownloadAttachment, DownloadInlineAttachment - CalendarClientInterface: ListCalendars, ListEvents, GetEvent - ContactsClientInterface: ListContacts, SearchContacts, GetContact, ListContactGroups Each interface includes compile-time verification that the concrete Client type implements it. Closes #35
1 parent a7180e8 commit b9de397

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

internal/calendar/interfaces.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package calendar
2+
3+
import (
4+
"google.golang.org/api/calendar/v3"
5+
)
6+
7+
// CalendarClientInterface defines the interface for Calendar client operations.
8+
// This enables unit testing through mock implementations.
9+
type CalendarClientInterface interface {
10+
// ListCalendars returns all calendars the user has access to
11+
ListCalendars() ([]*calendar.CalendarListEntry, error)
12+
13+
// ListEvents returns events from the specified calendar within the given time range
14+
ListEvents(calendarID string, timeMin, timeMax string, maxResults int64) ([]*calendar.Event, error)
15+
16+
// GetEvent retrieves a single event by ID
17+
GetEvent(calendarID, eventID string) (*calendar.Event, error)
18+
}
19+
20+
// Verify that Client implements CalendarClientInterface
21+
var _ CalendarClientInterface = (*Client)(nil)

internal/contacts/interfaces.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package contacts
2+
3+
import (
4+
"google.golang.org/api/people/v1"
5+
)
6+
7+
// ContactsClientInterface defines the interface for Contacts client operations.
8+
// This enables unit testing through mock implementations.
9+
type ContactsClientInterface interface {
10+
// ListContacts retrieves contacts from the user's account
11+
ListContacts(pageToken string, pageSize int64) (*people.ListConnectionsResponse, error)
12+
13+
// SearchContacts searches for contacts matching a query
14+
SearchContacts(query string, pageSize int64) (*people.SearchResponse, error)
15+
16+
// GetContact retrieves a specific contact by resource name
17+
GetContact(resourceName string) (*people.Person, error)
18+
19+
// ListContactGroups retrieves all contact groups
20+
ListContactGroups(pageToken string, pageSize int64) (*people.ListContactGroupsResponse, error)
21+
}
22+
23+
// Verify that Client implements ContactsClientInterface
24+
var _ ContactsClientInterface = (*Client)(nil)

internal/gmail/interfaces.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package gmail
2+
3+
import (
4+
"google.golang.org/api/gmail/v1"
5+
)
6+
7+
// GmailClientInterface defines the interface for Gmail client operations.
8+
// This enables unit testing through mock implementations.
9+
type GmailClientInterface interface {
10+
// GetMessage retrieves a single message by ID
11+
GetMessage(messageID string, includeBody bool) (*Message, error)
12+
13+
// SearchMessages searches for messages matching the query
14+
SearchMessages(query string, maxResults int64) ([]*Message, int, error)
15+
16+
// GetThread retrieves all messages in a thread
17+
GetThread(id string) ([]*Message, error)
18+
19+
// FetchLabels retrieves and caches all labels from the Gmail account
20+
FetchLabels() error
21+
22+
// GetLabelName resolves a label ID to its display name
23+
GetLabelName(labelID string) string
24+
25+
// GetLabels returns all cached labels
26+
GetLabels() []*gmail.Label
27+
28+
// GetAttachments retrieves attachment metadata for a message
29+
GetAttachments(messageID string) ([]*Attachment, error)
30+
31+
// DownloadAttachment downloads a single attachment by message ID and attachment ID
32+
DownloadAttachment(messageID string, attachmentID string) ([]byte, error)
33+
34+
// DownloadInlineAttachment downloads an attachment that has inline data
35+
DownloadInlineAttachment(messageID string, partID string) ([]byte, error)
36+
}
37+
38+
// Verify that Client implements GmailClientInterface
39+
var _ GmailClientInterface = (*Client)(nil)

0 commit comments

Comments
 (0)