diff --git a/definitions.go b/definitions.go index 444ba17..d767965 100644 --- a/definitions.go +++ b/definitions.go @@ -6,7 +6,7 @@ type APIEnvironment string const ( // defaultUserAgent is the default user agent for all requests - defaultUserAgent string = "go-tonicpow: v0.5.2" + defaultUserAgent string = "go-tonicpow: v0.5.3" // Field key names for various model requests fieldAdvertiserProfileID = "advertiser_profile_id" @@ -30,7 +30,6 @@ const ( fieldReason = "reason" fieldResultsPerPage = "results_per_page" fieldSearchQuery = "query" - fieldShortCode = "short_code" fieldSlug = "slug" fieldSortBy = "sort_by" fieldSortOrder = "sort_order" @@ -44,7 +43,6 @@ const ( modelCampaign = "campaigns" modelConversion = "conversions" modelGoal = "goals" - modelLink = "links" modelRates = "rates" modelUser = "users" @@ -291,39 +289,6 @@ type Goal struct { Title string `json:"title"` } -// Link is the link model (child of User) (relates Campaign to User) -// Use the CustomShortCode on create for using your own short code -// -// For more information: https://docs.tonicpow.com/#ee74c3ce-b4df-4d57-abf2-ccf3a80e4e1e -type Link struct { - AvatarURL string `json:"avatar_url,omitempty"` - CampaignID uint64 `json:"campaign_id"` - CampaignImageURL string `json:"image_url"` - CampaignSlug string `json:"slug"` - CampaignTitle string `json:"title"` - ClickSatoshis int32 `json:"click_satoshis"` - ConversionSatoshis int32 `json:"conversion_satoshis"` - Country string `json:"country"` - CustomShortCode string `json:"custom_short_code"` - ID uint64 `json:"id,omitempty"` - Label string `json:"label"` - ShortCode string `json:"short_code"` - ShortLinkURL string `json:"short_link_url"` - TargetURL string `json:"target_url"` - TotalClicks int32 `json:"total_clicks"` - TotalConversions int32 `json:"total_conversions"` - UserID uint64 `json:"user_id"` - Username string `json:"username,omitempty"` -} - -// LinkResults is the page response for link results from listing -type LinkResults struct { - CurrentPage int `json:"current_page"` - Links []*Link `json:"links"` - Results int `json:"results"` - ResultsPerPage int `json:"results_per_page"` -} - // Rate is the rate results // // For more information: https://docs.tonicpow.com/#fb00736e-61b9-4ec9-acaf-e3f9bb046c89 diff --git a/links.go b/links.go deleted file mode 100644 index f3d22d6..0000000 --- a/links.go +++ /dev/null @@ -1,168 +0,0 @@ -package tonicpow - -import ( - "encoding/json" - "fmt" - "net/http" -) - -// CreateLink will make a new link -// -// For more information: https://docs.tonicpow.com/#154bf9e1-6047-452f-a289-d21f507b0f1d -func (c *Client) CreateLink(link *Link) (createdLink *Link, err error) { - - // Basic requirements - if link.CampaignID == 0 { - err = c.createError(fmt.Sprintf("missing required attribute: %s", fieldCampaignID), http.StatusBadRequest) - return - } - - if link.UserID == 0 { - err = c.createError(fmt.Sprintf("missing required attribute: %s", fieldUserID), http.StatusBadRequest) - return - } - - // Fire the Request - var response string - if response, err = c.Request(modelLink, http.MethodPost, link); err != nil { - return - } - - // Only a 201 is treated as a success - if err = c.Error(http.StatusCreated, response); err != nil { - return - } - - // Convert model response - if err = json.Unmarshal([]byte(response), &createdLink); err != nil { - err = c.createError(fmt.Sprintf("failed unmarshaling data: %s", "link"), http.StatusExpectationFailed) - } - return -} - -// CreateLinkByURL will make a new link -// -// For more information: https://docs.tonicpow.com/#d5a22343-c580-43cc-8e27-dd131896ea3b -func (c *Client) CreateLinkByURL(link *Link) (createdLink *Link, err error) { - - // Basic requirements - if len(link.TargetURL) == 0 { - err = c.createError(fmt.Sprintf("missing required attribute: %s", fieldTargetURL), http.StatusBadRequest) - return - } - - if link.UserID == 0 { - err = c.createError(fmt.Sprintf("missing required attribute: %s", fieldUserID), http.StatusBadRequest) - return - } - - // Force campaign ID to zero - link.CampaignID = 0 - - // Fire the Request - var response string - if response, err = c.Request(modelLink, http.MethodPost, link); err != nil { - return - } - - // Only a 201 is treated as a success - if err = c.Error(http.StatusCreated, response); err != nil { - return - } - - // Convert model response - if err = json.Unmarshal([]byte(response), &createdLink); err != nil { - err = c.createError(fmt.Sprintf("failed unmarshaling data: %s", "link"), http.StatusExpectationFailed) - } - return -} - -// GetLink will get an existing link -// This will return an Error if the link is not found (404) -// -// For more information: https://docs.tonicpow.com/#c53add03-303e-4f72-8847-2adfdb992eb3 -func (c *Client) GetLink(linkID uint64) (link *Link, err error) { - - // Must have an id - if linkID == 0 { - err = c.createError(fmt.Sprintf("missing required attribute: %s", fieldID), http.StatusBadRequest) - return - } - - // Fire the Request - var response string - if response, err = c.Request(fmt.Sprintf("%s/details/%d", modelLink, linkID), 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 - if err = json.Unmarshal([]byte(response), &link); err != nil { - err = c.createError(fmt.Sprintf("failed unmarshaling data: %s", "link"), http.StatusExpectationFailed) - } - return -} - -// CheckLink will check for an existing link with a short_code -// This will return an Error if the link is not found (404) -// -// For more information: https://docs.tonicpow.com/#cc9780b7-0d84-4a60-a28f-664b2ecb209b -func (c *Client) CheckLink(shortCode string) (link *Link, err error) { - - // Must have a short code - if len(shortCode) == 0 { - err = c.createError(fmt.Sprintf("missing required attribute: %s", fieldShortCode), http.StatusBadRequest) - return - } - - // Fire the Request - var response string - if response, err = c.Request(fmt.Sprintf("%s/check/%s", modelLink, shortCode), 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 - if err = json.Unmarshal([]byte(response), &link); err != nil { - err = c.createError(fmt.Sprintf("failed unmarshaling data: %s", "link"), http.StatusExpectationFailed) - } - return -} - -// ListLinksByUserID will get links associated to the user id -// This will return an Error if the link(s) are not found (404) -// -// For more information: https://docs.tonicpow.com/#23d068f1-4f0e-476a-a802-50b7edccd0b2 -func (c *Client) ListLinksByUserID(userID uint64, page, resultsPerPage int) (results *LinkResults, err error) { - - // Must have an id - if userID == 0 { - err = c.createError(fmt.Sprintf("missing required attribute: %s", fieldUserID), http.StatusBadRequest) - return - } - - // Fire the Request - var response string - if response, err = c.Request(fmt.Sprintf("%s/links/?id=%d&%s=%d&%s=%d", modelUser, userID, fieldCurrentPage, page, fieldResultsPerPage, resultsPerPage), 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 - if err = json.Unmarshal([]byte(response), &results); err != nil { - err = c.createError(fmt.Sprintf("failed unmarshaling data: %s", "link"), http.StatusExpectationFailed) - } - return -}