Skip to content

Commit

Permalink
Replace waiver with freebie
Browse files Browse the repository at this point in the history
  • Loading branch information
kemitchell committed May 18, 2020
1 parent e0d0b09 commit b948fc6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
18 changes: 10 additions & 8 deletions api/waive.go → api/freebie.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@ import "io/ioutil"
import "net/http"
import "strconv"

type waiveRequest struct {
type freebieRequest struct {
Action string `json:"action"`
DeveloperID string `json:"developerID"`
Token string `json:"token"`
OfferID string `json:"offerID"`
Beneficiary string `json:"beneficiary"`
Name string `json:"name"`
EMail string `json:"email"`
Jurisdiction string `json:"jurisdiction"`
Term interface{} `json:"term"`
}

type waiveResponse struct {
type freebieResponse struct {
Error interface{} `json:"error"`
}

// Waive sends waiver API requests.
func Waive(developer *data.Developer, offerID, beneficiary, jurisdiction string, term interface{}) ([]byte, error) {
bodyData := waiveRequest{
Action: "waiver",
// Freebie sends freebie API requests.
func Freebie(developer *data.Developer, offerID, name, jurisdiction, email string, term interface{}) ([]byte, error) {
bodyData := freebieRequest{
Action: "freebie",
DeveloperID: developer.DeveloperID,
Token: developer.Token,
OfferID: offerID,
Beneficiary: beneficiary,
Name: name,
Jurisdiction: jurisdiction,
EMail: email,
Term: term,
}
body, err := json.Marshal(bodyData)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var commands = map[string]*subcommands.Subcommand{
"retract": subcommands.Retract,
"token": subcommands.Token,
"version": subcommands.Version,
"waive": subcommands.Waive,
"freebie": subcommands.Freebie,
"whoami": subcommands.WhoAmI,
}

Expand Down
42 changes: 22 additions & 20 deletions subcommands/waive.go → subcommands/freebie.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@ import "licensezero.com/cli/data"
import "io/ioutil"
import "os"

const waiveDescription = "Generate a waiver."
const freebieDescription = "Generate a waiver."

// Waive generates a signed waiver.
var Waive = &Subcommand{
Description: waiveDescription,
// Freebie generates a signed waiver.
var Freebie = &Subcommand{
Description: freebieDescription,
Handler: func(args []string, paths Paths) {
flagSet := flag.NewFlagSet("waive", flag.ExitOnError)
jurisdiction := flagSet.String("jurisdiction", "", "Jurisdiction.")
flagSet := flag.NewFlagSet("freebie", flag.ExitOnError)
days := flagSet.Uint("days", 0, "Days.")
forever := flagSet.Bool("forever", false, "Forever.")
beneficiary := flagSet.String("beneficiary", "", "Beneficiary legal name.")
name := flagSet.String("name", "", "User Legal Name.")
email := flagSet.String("email", "", "User E-Mail.")
jurisdiction := flagSet.String("jurisdiction", "", "User Jurisdiction.")
offerID := offerIDFlag(flagSet)
id := idFlag(flagSet)
flagSet.SetOutput(ioutil.Discard)
flagSet.Usage = waiveUsage
flagSet.Usage = freebieUsage
flagSet.Parse(args)
if *offerID == "" && *id == "" {
waiveUsage()
freebieUsage()
} else if *offerID != "" && *id != "" {
waiveUsage()
freebieUsage()
} else if *forever && *days > 0 {
waiveUsage()
freebieUsage()
} else if *days == 0 && !*forever {
waiveUsage()
} else if *beneficiary == "" || *jurisdiction == "" {
waiveUsage()
freebieUsage()
} else if *name == "" || *jurisdiction == "" || *email == "" {
freebieUsage()
}
if *offerID != "" {
*id = *offerID
Expand All @@ -49,7 +50,7 @@ var Waive = &Subcommand{
} else {
term = *days
}
bytes, err := api.Waive(developer, *id, *beneficiary, *jurisdiction, term)
bytes, err := api.Freebie(developer, *id, *name, *jurisdiction, *email, term)
if err != nil {
Fail("Error sending waiver request: " + err.Error())
}
Expand All @@ -58,17 +59,18 @@ var Waive = &Subcommand{
},
}

func waiveUsage() {
usage := waiveDescription + "\n\n" +
func freebieUsage() {
usage := freebieDescription + "\n\n" +
"Usage:\n" +
" licensezero waive --id ID --beneficiary NAME --jurisdiction CODE (--days DAYS | --forever)\n\n" +
" licensezero freebie --id ID --name NAME --email EMAIL --jurisdiction CODE (--days DAYS | --forever)\n\n" +
"Options:\n" +
flagsList(map[string]string{
"id ID": idLine,
"beneficiary NAME": "Beneficiary legal name.",
"name NAME": "User legal name.",
"email EMAIL": "User e-mail.",
"jurisdiction CODE": "User jurisdiction (ISO 3166-2, like \"US-CA\").",
"days DAYS": "Term, in days.",
"forever": "Infinite term.",
"jurisdiction CODE": "Beneficiary jurisdiction (ISO 3166-2, like \"US-CA\").",
})
Fail(usage)
}
File renamed without changes.

0 comments on commit b948fc6

Please sign in to comment.