Skip to content

Commit

Permalink
Added get campaigns by advertiser
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jan 28, 2020
1 parent 3c2c254 commit d870063
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions advertiser_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,25 @@ func (c *Client) UpdateAdvertiserProfile(profile *AdvertiserProfile, userSession
err = json.Unmarshal([]byte(response), &updatedProfile)
return
}

// GetCampaignsByAdvertiserProfile will return a list of campaigns
// This will return an error if the campaign is not found (404)
//
// For more information: https://docs.tonicpow.com/#98017e9a-37dd-4810-9483-b6c400572e0c
func (c *Client) GetCampaignsByAdvertiserProfile(profileID uint64) (campaigns []*Campaign, err error) {

// Fire the request
var response string
if response, err = c.request(fmt.Sprintf("%s/campaigns/%d", modelAdvertiser, profileID), 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
}
9 changes: 9 additions & 0 deletions examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ func main() {
log.Printf("campaigns found: %d", len(campaigns))
}

//
// Example: List Campaigns (by advertiser)
//
if campaigns, err = TonicPowAPI.GetCampaignsByAdvertiserProfile(advertiser.ID); err != nil {
log.Fatalf("list campaign failed error %s - api error: %s", err.Error(), TonicPowAPI.LastRequest.Error.Message)
} else {
log.Printf("campaigns by advertiser found: %d", len(campaigns))
}

//
// Example: Get campaigns by url
//
Expand Down

0 comments on commit d870063

Please sign in to comment.