-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f293631
commit 94b3092
Showing
8 changed files
with
117 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package notifier | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net/smtp" | ||
|
||
"github.com/jacobmichels/Course-Sense-Go/internal/types" | ||
) | ||
|
||
type EmailNotifier struct { | ||
host string | ||
port int | ||
username string | ||
password string | ||
from string | ||
} | ||
|
||
func NewEmailNotifier(host, username, password, from string, port int) *EmailNotifier { | ||
return &EmailNotifier{host, port, username, password, from} | ||
} | ||
|
||
func (en *EmailNotifier) Name() string { | ||
return "EmailNotifier" | ||
} | ||
|
||
func (en *EmailNotifier) Notify(ctx context.Context, section *types.CourseSection) error { | ||
auth := smtp.PlainAuth("", en.username, en.password, en.host) | ||
msg := []byte(fmt.Sprintf("Hello from Course Sense!\n\nSpace has been found in the following course section: %s %d %s %s. Get over to WebAdvisor to claim the spot!", section.Department, section.CourseCode, section.SectionCode, section.Term)) | ||
|
||
for _, watcher := range section.Watchers { | ||
err := smtp.SendMail(fmt.Sprintf("%s:%d", en.host, en.port), auth, en.from, []string{watcher.Email}, msg) | ||
if err != nil { | ||
return fmt.Errorf("failed to notify %s: %w", watcher.Email, err) | ||
} | ||
log.Println("mail sent") | ||
} | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package notifier | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/jacobmichels/Course-Sense-Go/internal/types" | ||
"github.com/twilio/twilio-go" | ||
) | ||
|
||
type TwilioNotifier struct { | ||
accountSid string | ||
authToken string | ||
phoneNumber string | ||
client *twilio.RestClient | ||
} | ||
|
||
func NewTwilioNotifier(accountSid, authToken, phoneNumber string) *TwilioNotifier { | ||
client := twilio.NewRestClientWithParams(twilio.ClientParams{ | ||
Username: accountSid, | ||
Password: authToken, | ||
}) | ||
|
||
return &TwilioNotifier{accountSid, authToken, phoneNumber, client} | ||
} | ||
|
||
func (tn *TwilioNotifier) Name() string { | ||
return "TwilioNotifier" | ||
} | ||
|
||
func (tn *TwilioNotifier) Notify(ctx context.Context, section *types.CourseSection) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters