Skip to content

Commit

Permalink
Implemented list campaigns request
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Dec 31, 2019
1 parent 37121b2 commit f363ee5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
23 changes: 23 additions & 0 deletions campaigns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ func (c *Campaign) permitFields() {
c.AdvertiserProfileID = 0
c.Balance = 0
c.BalanceSatoshis = 0
c.Clicks = 0
c.FundingAddress = ""
c.LinksCreated = 0
c.PublicGUID = ""
}

Expand Down Expand Up @@ -72,6 +74,27 @@ func (c *Client) GetCampaign(campaignID uint64, userSessionToken string) (campai
return
}

// ListCampaigns will return a list of active campaigns
//
// For more information: https://docs.tonicpow.com/#c1b17be6-cb10-48b3-a519-4686961ff41c
func (c *Client) ListCampaigns() (campaigns []*Campaign, err error) {

// Fire the request
var response string
if response, err = c.request(fmt.Sprintf("%s/list", modelCampaign), http.MethodGet, nil, ""); err != nil {
return
}

// Only a 200 is treated as a success
if err = c.error(http.StatusOK, response); err != nil {
return
}

// Convert model response
err = json.Unmarshal([]byte(response), &campaigns)
return
}

// GetCampaignBalance will update the models's balance from the chain
//
// For more information: https://docs.tonicpow.com/#b6c60c63-8ac5-4c74-a4a2-cf3e858e5a8d
Expand Down
29 changes: 16 additions & 13 deletions definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,22 @@ type AdvertiserProfile struct {
//
// For more information: https://docs.tonicpow.com/#5aca2fc7-b3c8-445b-aa88-f62a681f8e0c
type Campaign struct {
AdvertiserProfileID uint64 `json:"advertiser_profile_id,omitempty"`
Balance float64 `json:"balance,omitempty"`
BalanceSatoshis int64 `json:"balance_satoshis,omitempty"`
Currency string `json:"currency,omitempty"`
Description string `json:"description,omitempty"`
FundingAddress string `json:"funding_address,omitempty"`
Goals []*Goal `json:"goals,omitempty"`
ID uint64 `json:"id,omitempty"`
ImageURL string `json:"image_url,omitempty"`
PayPerClickRate float64 `json:"pay_per_click_rate,omitempty"`
PublicGUID string `json:"public_guid,omitempty"`
TargetURL string `json:"target_url,omitempty"`
Title string `json:"title,omitempty"`
AdvertiserProfile *AdvertiserProfile `json:"advertiser_profile,omitempty"`
AdvertiserProfileID uint64 `json:"advertiser_profile_id,omitempty"`
Balance float64 `json:"balance,omitempty"`
BalanceSatoshis int64 `json:"balance_satoshis,omitempty"`
Clicks uint64 `json:"clicks,omitempty"`
Currency string `json:"currency,omitempty"`
Description string `json:"description,omitempty"`
FundingAddress string `json:"funding_address,omitempty"`
Goals []*Goal `json:"goals,omitempty"`
ID uint64 `json:"id,omitempty"`
ImageURL string `json:"image_url,omitempty"`
LinksCreated uint64 `json:"links_created,omitempty"`
PayPerClickRate float64 `json:"pay_per_click_rate,omitempty"`
PublicGUID string `json:"public_guid,omitempty"`
TargetURL string `json:"target_url,omitempty"`
Title string `json:"title,omitempty"`
}

// Goal is the goal model (child of Campaign)
Expand Down
10 changes: 10 additions & 0 deletions examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,14 @@ func main() {
} else {
log.Printf("got link by id %d", goal.ID)
}

//
// Example: List active campaigns
//
var campaigns []*tonicpow.Campaign
if campaigns, err = TonicPowAPI.ListCampaigns(); err != nil {
log.Fatalf("list campaign failed - api error: %s", TonicPowAPI.LastRequest.Error.Message)
} else {
log.Printf("campaigns found: %d", len(campaigns))
}
}

0 comments on commit f363ee5

Please sign in to comment.