Skip to content

Commit

Permalink
Starting goal test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jun 4, 2021
1 parent c5b9113 commit 6d1da95
Show file tree
Hide file tree
Showing 5 changed files with 381 additions and 4 deletions.
2 changes: 1 addition & 1 deletion definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
// Config defaults
// Package configuration defaults
apiVersion string = "v1"
defaultHTTPTimeout = 10 * time.Second // Default timeout for all GET requests in seconds
defaultRetryCount int = 2 // Default retry count for HTTP requests
Expand Down
39 changes: 39 additions & 0 deletions examples/goals/create/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"log"
"os"

"github.com/tonicpow/go-tonicpow"
)

func main() {

// Load the api client
client, err := tonicpow.NewClient(
tonicpow.WithAPIKey(os.Getenv("TONICPOW_API_KEY")),
tonicpow.WithEnvironmentString(os.Getenv("TONICPOW_ENVIRONMENT")),
)
if err != nil {
log.Fatalf("error in NewClient: %s", err.Error())
}

// Start goal
goal := &tonicpow.Goal{
CampaignID: 23,
Description: "Example goal description",
MaxPerPromoter: 1,
Name: "example_goal",
PayoutRate: 0.01,
PayoutType: "flat",
Title: "Example Goal",
}

// Create a goal
err = client.CreateGoal(goal)
if err != nil {
log.Fatalf("error in CreateGoal: %s", err.Error())
}

log.Printf("created goal: %d", goal.ID)
}
29 changes: 29 additions & 0 deletions examples/goals/get/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"log"
"os"

"github.com/tonicpow/go-tonicpow"
)

func main() {

// Load the api client
client, err := tonicpow.NewClient(
tonicpow.WithAPIKey(os.Getenv("TONICPOW_API_KEY")),
tonicpow.WithEnvironmentString(os.Getenv("TONICPOW_ENVIRONMENT")),
)
if err != nil {
log.Fatalf("error in NewClient: %s", err.Error())
}

// Get a goal
var goal *tonicpow.Goal
goal, err = client.GetGoal(13)
if err != nil {
log.Fatalf("error in GetGoal: %s", err.Error())
}

log.Printf("goal: %s", goal.Name)
}
6 changes: 4 additions & 2 deletions goals.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
// permitFields will remove fields that cannot be used
func (g *Goal) permitFields() {
g.CampaignID = 0
g.Payouts = 0
}

// CreateGoal will make a new goal
Expand All @@ -21,6 +20,9 @@ func (c *Client) CreateGoal(goal *Goal) (err error) {
if goal.CampaignID == 0 {
err = fmt.Errorf(fmt.Sprintf("missing required attribute: %s", fieldCampaignID))
return
} else if len(goal.Name) == 0 {
err = fmt.Errorf(fmt.Sprintf("missing required attribute: %s", fieldName))
return
}

// Fire the Request
Expand All @@ -43,7 +45,7 @@ func (c *Client) CreateGoal(goal *Goal) (err error) {
// For more information: https://docs.tonicpow.com/#48d7bbc8-5d7b-4078-87b7-25f545c3deaf
func (c *Client) GetGoal(goalID uint64) (goal *Goal, err error) {

// Must have an id
// Must have an ID
if goalID == 0 {
err = fmt.Errorf("missing required attribute: %s", fieldID)
return
Expand Down

0 comments on commit 6d1da95

Please sign in to comment.