diff --git a/README.md b/README.md index 6391b88..729a0b5 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ set NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE #### Additional SMS Configuration ``` set TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID_HERE -set TWILIO_SERVICE_SID=YOUR_TWILIO_SERVICE_SID_HERE set TWILIO_TOKEN=YOUR_TWILIO_TOKEN_HERE set TWILIO_SOURCE_NUMBER=YOUR_TWILIO_SERVICE_NUMBER_HERE set TWILIO_DESTINATION_NUMBER=YOUR_DESITNATION_NUMBER_FOR_NOTIFICATIONS_HERE @@ -66,7 +65,6 @@ export NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE ``` export NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE export TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID_HERE -export TWILIO_SERVICE_SID=YOUR_TWILIO_SERVICE_SID_HERE export TWILIO_TOKEN=YOUR_TWILIO_TOKEN_HERE export TWILIO_SOURCE_NUMBER=YOUR_TWILIO_SERVICE_NUMBER_HERE export TWILIO_DESTINATION_NUMBER=YOUR_DESITNATION_NUMBER_FOR_NOTIFICATIONS_HERE @@ -85,7 +83,6 @@ export NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE ``` export NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE export TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID_HERE -export TWILIO_SERVICE_SID=YOUR_TWILIO_SERVICE_SID_HERE export TWILIO_TOKEN=YOUR_TWILIO_TOKEN_HERE export TWILIO_SOURCE_NUMBER=YOUR_TWILIO_SERVICE_NUMBER_HERE export TWILIO_DESTINATION_NUMBER=YOUR_DESITNATION_NUMBER_FOR_NOTIFICATIONS_HERE diff --git a/internal/alert/alert.go b/internal/alert/alert.go index 7273d1a..3a48181 100644 --- a/internal/alert/alert.go +++ b/internal/alert/alert.go @@ -12,7 +12,7 @@ import ( //SendText Sends an SMS notification using Twilio Service. func SendText(item string, config config.TwilioConfig, client *http.Client) error { - endpoint := fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages", config.ServiceSID) + endpoint := fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages", config.AccountSID) msgData := url.Values{} msgData.Set("To", config.DestinationNumber) diff --git a/internal/config/config.go b/internal/config/config.go index d6c24eb..b5934b5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,7 +7,6 @@ import ( type TwilioConfig struct { AccountSID string - ServiceSID string Token string SourceNumber string DestinationNumber string @@ -29,13 +28,6 @@ func GetTwilioConfig() TwilioConfig { configuration.AccountSID = accountSid - serviceSid, serviceSidOk := os.LookupEnv("TWILIO_SERVICE_SID") - if serviceSidOk == false { - log.Fatal("TWILIO_SERVICE_SID Environment Variable is unset, exiting.") - } - - configuration.ServiceSID = serviceSid - token, tokenOk := os.LookupEnv("TWILIO_TOKEN") if tokenOk == false { log.Fatal("TWILIO_TOKEN Environment Variable is unset, exiting.") diff --git a/main.go b/main.go index 78bcf41..70e6d42 100644 --- a/main.go +++ b/main.go @@ -13,17 +13,43 @@ import ( "github.com/ianmarmour/nvidia-clerk/internal/rest" ) -func main() { - browser.StartChromeDebugMode() - sessionContext := browser.StartSession() +func runTest(name string, client *http.Client, config config.Config) { + switch name { + case "sms": + textErr := alert.SendText(config.SKU, config.TwilioConfig, client) + if textErr != nil { + fmt.Printf("Error testing SMS notification exiting...\n") + os.Exit(1) + } else { + fmt.Printf("SMS Notification testing completed succesfully") + } + default: + + } + + fmt.Printf("Testing completed succesfully exiting...\n") + os.Exit(0) +} +func main() { + // Parse Argument Flags useSms := flag.Bool("sms", false, "Enable SMS notifications for whenever SKU is in stock.") + useTest := flag.Bool("test", false, "Enable testing mode") flag.Parse() config := config.GetConfig(*useSms) - httpClient := &http.Client{Timeout: 10 * time.Second} + // Execute Tests + if *useTest == true { + if *useSms == true { + runTest("sms", httpClient, config) + } + } + + browser.StartChromeDebugMode() + sessionContext := browser.StartSession() + for { skuInfo, skuInfoErr := rest.GetSkuInfo(config.SKU, httpClient) if skuInfoErr != nil {