From e135b81bb9d487a70edbd01073565d3fbd82d221 Mon Sep 17 00:00:00 2001 From: t94j0 Date: Tue, 1 Aug 2017 12:22:34 -0400 Subject: [PATCH] Fixed --- README.md | 5 +++- cmd/list.go | 27 +++++++++++++++++++ cmd/root.go | 5 +++- domain/check_domain.go | 6 ++++- domain/domains_keywords.go | 5 +++- domain/purchase.go | 55 ++++++++++++++++++++++++-------------- 6 files changed, 79 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d71bc1f..a5e260d 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,10 @@ The options are: * email - Email for contact * phone - Phone number (format: TODO) * fax - Fax number - * mailing - Mailing number + * address + * city + * postal + * country_code - ISO ["Alpha 2 Code"](http://www.nationsonline.org/oneworld/country_code_list.htm) * godaddy - Godaddy configuration * key * secret diff --git a/cmd/list.go b/cmd/list.go index 87ad15a..f515e75 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -19,6 +19,7 @@ var listCmd = &cobra.Command{ Short: "List domains to purchase", Long: `List domains and have the option to purchase the domains as well`, Run: func(cmd *cobra.Command, args []string) { + checkConfig() // Configure domain finding mechanism if viper.GetString("file") != "" { if err := domain.ParseFile(viper.GetString("file")); err != nil { @@ -36,6 +37,32 @@ var listCmd = &cobra.Command{ }, } +func checkConfig() { + godaddyConfig := []string{ + "godaddyKey", + "godaddySecret", + "first", + "middle", + "last", + "organization", + "title", + "email", + "phone", + "address", + "city", + "state", + "postal", + "country_code", + } + + for _, c := range godaddyConfig { + if viper.GetString(c) == "" { + fmt.Printf("Not using GoDaddy (Provide %s)\n", c) + break + } + } +} + func init() { RootCmd.AddCommand(listCmd) diff --git a/cmd/root.go b/cmd/root.go index 955be04..b53ee76 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -48,7 +48,7 @@ func initConfig() { os.Exit(1) } - // Search config in home directory with name ".AIRMASTER" (without extension). + // Search config in home directory with name ".AIRMASTER" viper.AddConfigPath(home) viper.SetConfigName(".AIRMASTER") } @@ -58,5 +58,8 @@ func initConfig() { // If a config file is found, read it in. if err := viper.ReadInConfig(); err == nil { fmt.Println("Using config file:", viper.ConfigFileUsed()) + } else { + fmt.Println(err) + os.Exit(1) } } diff --git a/domain/check_domain.go b/domain/check_domain.go index e11504f..565c356 100644 --- a/domain/check_domain.go +++ b/domain/check_domain.go @@ -63,7 +63,11 @@ func CheckDomain(domain string, client *http.Client, cooldown int64) error { categorization := getCategorization(cat.Categorization) // Purchase domain if that option is specified if viper.GetBool("purchase") { - newDomain := NewDomain(cat.URL, categorization) + domainURL, err := url.Parse(cat.URL) + if err != nil { + return err + } + newDomain := NewDomain(domainURL.Host, categorization) newDomain.PromptPurchase() return nil } else { diff --git a/domain/domains_keywords.go b/domain/domains_keywords.go index bf32353..7d30863 100644 --- a/domain/domains_keywords.go +++ b/domain/domains_keywords.go @@ -48,6 +48,9 @@ func ParseKeywords(keywords []string) error { } fmt.Println("Done getting domains") + if len(rawDomains) == 0 { + fmt.Println("No domains found") + } jar, err := cookiejar.New(&cookiejar.Options{}) if err != nil { @@ -65,7 +68,7 @@ func ParseKeywords(keywords []string) error { !strings.Contains(domain.Status, "Auction") { if err := CheckDomain(domain.Site, client, 0); err != nil { - fmt.Println("Error checking domain:", err) + fmt.Println("Error checking domain ("+domain.Site+"):", err) } } } diff --git a/domain/purchase.go b/domain/purchase.go index 4821167..390419f 100644 --- a/domain/purchase.go +++ b/domain/purchase.go @@ -30,29 +30,39 @@ type Domain struct { var ErrUnavailable = errors.New("Domain unavailable") func NewDomain(url, categorization string) *Domain { - return &Domain{url, categorization, 0, 0} + return &Domain{url, categorization} } func (d *Domain) PromptPurchase() { - fmt.Println("This feature has not been implemented!") - return + var clientList []Registrars - clientList := []Registrars{ - godaddy.NewClient( - viper.GetString("godaddy.key"), - viper.GetString("godaddy.secret"), - godaddy.Contact{ - viper.GetString("user.first"), - viper.GetString("user.middle"), - viper.GetString("user.last"), - viper.GetString("user.organization"), - viper.GetString("user.title"), - viper.GetString("user.email"), - viper.GetString("user.phone"), - viper.GetString("user.fax"), - viper.GetString("user.mailing"), + godaddyClient, err := godaddy.NewClient( + viper.GetString("godaddyKey"), + viper.GetString("godaddySecret"), + godaddy.Contact{ + viper.GetString("first"), + viper.GetString("middle"), + viper.GetString("last"), + viper.GetString("organization"), + viper.GetString("title"), + viper.GetString("email"), + viper.GetString("phone"), + viper.GetString("fax"), + godaddy.Address{ + viper.GetString("address"), + viper.GetString("city"), + viper.GetString("state"), + viper.GetString("postal"), + viper.GetString("country_code"), }, - ), + }, + ) + + // TODO: Have a more elegant way to handle this + if err == nil { + clientList = append(clientList, godaddyClient) + } else { + fmt.Println(err) } for _, client := range clientList { @@ -61,16 +71,21 @@ func (d *Domain) PromptPurchase() { fmt.Fprintln(os.Stderr, "Error getting availability:", err) continue } + if isAvailable { fmt.Printf( "Would you like to purchase \"%s\" (%s) for %d from %s (y/N): ", - d.URL, d.Categorization, price, client.GetName, + d.URL, d.Categorization, price, client.GetName(), ) reader := bufio.NewReader(os.Stdin) input, _ := reader.ReadString('\n') if strings.Contains(input, "Y") || strings.Contains(input, "y") { - client.Purchase(d.URL) + if err := client.Purchase(d.URL); err != nil { + fmt.Fprintln(os.Stderr, "Error purchasing domain:", err) + } } + } else { + fmt.Printf("Found %s, but not available\n", d.URL) } } }