From d8700635f5d81311c42a5a2efcc243b04953a072 Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Mon, 27 Jan 2020 22:25:51 -0500 Subject: [PATCH] Added get campaigns by advertiser --- advertiser_profiles.go | 22 ++++++++++++++++++++++ examples/examples.go | 9 +++++++++ 2 files changed, 31 insertions(+) diff --git a/advertiser_profiles.go b/advertiser_profiles.go index 01bd7bd..2b73dfa 100644 --- a/advertiser_profiles.go +++ b/advertiser_profiles.go @@ -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 +} diff --git a/examples/examples.go b/examples/examples.go index 9e0e80e..cefe4da 100644 --- a/examples/examples.go +++ b/examples/examples.go @@ -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 //