Documentation ¶
Overview ¶
Package tonicpow is the official golang implementation for the TonicPow API
If you have any suggestions or comments, please feel free to open an issue on this GitHub repository!
By TonicPow Inc (https://tonicpow.com)
Index ¶
- Constants
- Variables
- func UserAgent() string
- func Version() string
- type AdvertiserProfile
- type AdvertiserResults
- type AdvertiserService
- type App
- type AppResults
- type Campaign
- type CampaignImage
- type CampaignRequirements
- type CampaignResults
- type CampaignService
- type Client
- func (c *Client) CampaignsFeed(feedType FeedType) (feed string, response *StandardResponse, err error)
- func (c *Client) CancelConversion(conversionID uint64, cancelReason string) (conversion *Conversion, response *StandardResponse, err error)
- func (c *Client) CreateCampaign(campaign *Campaign) (*StandardResponse, error)
- func (c *Client) CreateConversion(opts ...ConversionOps) (conversion *Conversion, response *StandardResponse, err error)
- func (c *Client) CreateGoal(goal *Goal) (*StandardResponse, error)
- func (c *Client) DeleteGoal(goalID uint64) (bool, *StandardResponse, error)
- func (c *Client) GetAdvertiserProfile(profileID uint64) (profile *AdvertiserProfile, response *StandardResponse, err error)
- func (c *Client) GetCampaign(campaignID uint64) (campaign *Campaign, response *StandardResponse, err error)
- func (c *Client) GetCampaignBySlug(slug string) (campaign *Campaign, response *StandardResponse, err error)
- func (c *Client) GetConversion(conversionID uint64) (conversion *Conversion, response *StandardResponse, err error)
- func (c *Client) GetCurrentRate(currency string, customAmount float64) (rate *Rate, response *StandardResponse, err error)
- func (c *Client) GetEnvironment() Environment
- func (c *Client) GetGoal(goalID uint64) (goal *Goal, response *StandardResponse, err error)
- func (c *Client) GetUserAgent() string
- func (c *Client) ListAppsByAdvertiserProfile(profileID uint64, page, resultsPerPage int, sortBy, sortOrder string) (apps *AppResults, response *StandardResponse, err error)
- func (c *Client) ListCampaigns(page, resultsPerPage int, sortBy, sortOrder, searchQuery string, ...) (results *CampaignResults, response *StandardResponse, err error)
- func (c *Client) ListCampaignsByAdvertiserProfile(profileID uint64, page, resultsPerPage int, sortBy, sortOrder string) (campaigns *CampaignResults, response *StandardResponse, err error)
- func (c *Client) ListCampaignsByURL(targetURL string, page, resultsPerPage int, sortBy, sortOrder string) (results *CampaignResults, response *StandardResponse, err error)
- func (c *Client) Options() *ClientOptions
- func (c *Client) Request(httpMethod string, requestEndpoint string, data interface{}, expectedCode int) (response *StandardResponse, err error)
- func (c *Client) UpdateAdvertiserProfile(profile *AdvertiserProfile) (*StandardResponse, error)
- func (c *Client) UpdateCampaign(campaign *Campaign) (response *StandardResponse, err error)
- func (c *Client) UpdateGoal(goal *Goal) (*StandardResponse, error)
- func (c *Client) WithCustomHTTPClient(client *resty.Client) *Client
- type ClientInterface
- type ClientOps
- func WithAPIKey(appAPIKey string) ClientOps
- func WithCustomEnvironment(name, alias, apiURL string) ClientOps
- func WithCustomHeaders(headers map[string][]string) ClientOps
- func WithEnvironment(e Environment) ClientOps
- func WithEnvironmentString(e string) ClientOps
- func WithHTTPTimeout(timeout time.Duration) ClientOps
- func WithRequestTracing() ClientOps
- func WithRetryCount(retries int) ClientOps
- func WithUserAgent(userAgent string) ClientOps
- type ClientOptions
- type Conversion
- type ConversionOps
- func WithCustomDimensions(dimensions string) ConversionOps
- func WithDelay(minutes uint64) ConversionOps
- func WithGoalID(goalID uint64) ConversionOps
- func WithGoalName(name string) ConversionOps
- func WithPurchaseAmount(amount float64) ConversionOps
- func WithShortCode(shortCode string) ConversionOps
- func WithTncpwSession(session string) ConversionOps
- func WithTwitterID(twitterID string) ConversionOps
- func WithUserID(userID uint64) ConversionOps
- type ConversionService
- type Environment
- type Error
- type FeedType
- type Goal
- type GoalService
- type Rate
- type RateService
- type StandardResponse
Examples ¶
- Client.CancelConversion
- Client.CreateCampaign
- Client.CreateConversion
- Client.CreateGoal
- Client.DeleteGoal
- Client.GetAdvertiserProfile
- Client.GetCampaign
- Client.GetCampaignBySlug
- Client.GetConversion
- Client.GetCurrentRate
- Client.GetGoal
- Client.UpdateAdvertiserProfile
- Client.UpdateCampaign
- Client.UpdateGoal
- Environment.Alias
- Environment.Name
- Environment.URL
- NewClient
- UserAgent
- Version
Constants ¶
const ( // SortByFieldBalance is for sorting results by field: balance SortByFieldBalance string = "balance" // SortByFieldCreatedAt is for sorting results by field: created_at SortByFieldCreatedAt string = "created_at" // SortByFieldName is for sorting results by field: name SortByFieldName string = "name" // SortByFieldLinksCreated is for sorting results by field: links_created SortByFieldLinksCreated string = "links_created" // SortByFieldPaidClicks is for sorting results by field: paid_clicks SortByFieldPaidClicks string = "paid_clicks" // SortByFieldPayPerClick is for sorting results by field: pay_per_click_rate SortByFieldPayPerClick string = "pay_per_click_rate" // SortOrderAsc is for returning the results in ascending order SortOrderAsc string = "asc" // SortOrderDesc is for returning the results in descending order SortOrderDesc string = "desc" // FeedTypeAtom is for using the feed type: Atom FeedTypeAtom FeedType = "atom" // FeedTypeJSON is for using the feed type: JSON FeedTypeJSON FeedType = "json" // FeedTypeRSS is for using the feed type: RSS FeedTypeRSS FeedType = "rss" )
Variables ¶
var ( EnvironmentLive = Environment{ // contains filtered or unexported fields } EnvironmentStaging = Environment{ // contains filtered or unexported fields } EnvironmentDevelopment = Environment{ // contains filtered or unexported fields } )
Current environments available
Functions ¶
Types ¶
type AdvertiserProfile ¶ added in v0.2.0
type AdvertiserProfile struct { HomepageURL string `json:"homepage_url"` IconURL string `json:"icon_url"` PublicGUID string `json:"public_guid"` Name string `json:"name"` ID uint64 `json:"id,omitempty"` LinkServiceDomainID uint64 `json:"link_service_domain_id"` UserID uint64 `json:"user_id"` DomainVerified bool `json:"domain_verified"` Unlisted bool `json:"unlisted"` }
AdvertiserProfile is the advertiser_profile model (child of User)
For more information: https://docs.tonicpow.com/#2f9ec542-0f88-4671-b47c-d0ee390af5ea
type AdvertiserResults ¶ added in v0.7.4
type AdvertiserResults struct { Advertisers []*AdvertiserProfile `json:"advertisers"` CurrentPage int `json:"current_page"` Results int `json:"results"` ResultsPerPage int `json:"results_per_page"` }
AdvertiserResults is the page response for advertiser profile results from listing
type AdvertiserService ¶ added in v0.7.4
type AdvertiserService interface { GetAdvertiserProfile(profileID uint64) (profile *AdvertiserProfile, response *StandardResponse, err error) ListAppsByAdvertiserProfile(profileID uint64, page, resultsPerPage int, sortBy, sortOrder string) (apps *AppResults, response *StandardResponse, err error) ListCampaignsByAdvertiserProfile(profileID uint64, page, resultsPerPage int, sortBy, sortOrder string) (campaigns *CampaignResults, response *StandardResponse, err error) UpdateAdvertiserProfile(profile *AdvertiserProfile) (*StandardResponse, error) }
AdvertiserService is the advertiser requests
type App ¶ added in v0.7.4
type App struct { AdvertiserProfileID uint64 `json:"advertiser_profile_id"` ID uint64 `json:"id"` Name string `json:"name"` UserID uint64 `json:"user_id"` WebhookURL string `json:"webhook_url"` }
App is the app model (child of advertiser_profile)
For more information: (todo)
type AppResults ¶ added in v0.7.4
type AppResults struct { Apps []*App `json:"apps"` CurrentPage int `json:"current_page"` Results int `json:"results"` ResultsPerPage int `json:"results_per_page"` }
AppResults is the page response for app results from listing
type Campaign ¶ added in v0.2.0
type Campaign struct { Goals []*Goal `json:"goals"` Images []*CampaignImage `json:"images"` CreatedAt string `json:"created_at"` Currency string `json:"currency"` Description string `json:"description"` ExpiresAt string `json:"expires_at"` FundingAddress string `json:"funding_address"` FundingPaymailAddress string `json:"funding_paymail_address"` ImageURL string `json:"image_url"` LastEventAt string `json:"last_event_at"` PublicGUID string `json:"public_guid"` Slug string `json:"slug"` TargetURL string `json:"target_url"` TargetType string `json:"target_type"` TargetData string `json:"target_data"` Title string `json:"title"` TxID string `json:"-"` AdvertiserProfile *AdvertiserProfile `json:"advertiser_profile"` Balance float64 `json:"balance"` BalanceAlertThreshold float64 `json:"balance_alert_threshold"` PayPerClickRate float64 `json:"pay_per_click_rate"` AdvertiserProfileID uint64 `json:"advertiser_profile_id"` BalanceSatoshis uint64 `json:"balance_satoshis"` ID uint64 `json:"id,omitempty"` LinksCreated uint64 `json:"links_created"` LinkServiceDomainID uint64 `json:"link_service_domain_id"` PaidClicks uint64 `json:"paid_clicks"` PaidConversions uint64 `json:"paid_conversions"` PayoutMode int `json:"payout_mode"` Requirements *CampaignRequirements `json:"requirements"` BotProtection bool `json:"bot_protection"` ContributeEnabled bool `json:"contribute_enabled"` DomainVerified bool `json:"domain_verified"` Unlisted bool `json:"unlisted"` MatchDomain bool `json:"match_domain"` }
Campaign is the campaign model (child of AdvertiserProfile)
For more information: https://docs.tonicpow.com/#5aca2fc7-b3c8-445b-aa88-f62a681f8e0c
type CampaignImage ¶ added in v0.7.4
type CampaignImage struct { Height int `json:"height"` MimeType string `json:"mime_type"` URL string `json:"url"` Width int `json:"width"` }
CampaignImage is the structure of the image metadata
type CampaignRequirements ¶ added in v0.7.4
type CampaignRequirements struct { ContractRequired bool `json:"contract_required"` DotWallet bool `json:"dotwallet"` Facebook bool `json:"facebook"` Google bool `json:"google"` HandCash bool `json:"handcash"` KYC bool `json:"kyc"` MoneyButton bool `json:"moneybutton"` Relay bool `json:"relay"` Twitter bool `json:"twitter"` VisitorCountries []string `json:"visitor_countries"` VisitorRestrictions bool `json:"visitor_restrictions"` }
CampaignRequirements is the structure for "requirements"
type CampaignResults ¶ added in v0.7.4
type CampaignResults struct { Campaigns []*Campaign `json:"campaigns"` CurrentPage int `json:"current_page"` Results int `json:"results"` ResultsPerPage int `json:"results_per_page"` }
CampaignResults is the page response for campaign results from listing
type CampaignService ¶ added in v0.7.4
type CampaignService interface { CampaignsFeed(feedType FeedType) (feed string, response *StandardResponse, err error) CreateCampaign(campaign *Campaign) (*StandardResponse, error) GetCampaign(campaignID uint64) (campaign *Campaign, response *StandardResponse, err error) GetCampaignBySlug(slug string) (campaign *Campaign, response *StandardResponse, err error) ListCampaigns(page, resultsPerPage int, sortBy, sortOrder, searchQuery string, minimumBalance uint64, includeExpired bool) (results *CampaignResults, response *StandardResponse, err error) ListCampaignsByURL(targetURL string, page, resultsPerPage int, sortBy, sortOrder string) (results *CampaignResults, response *StandardResponse, err error) UpdateCampaign(campaign *Campaign) (response *StandardResponse, err error) }
CampaignService is the campaign requests
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the TonicPow client/configuration
func (*Client) CampaignsFeed ¶ added in v0.7.4
func (c *Client) CampaignsFeed(feedType FeedType) (feed string, response *StandardResponse, err error)
CampaignsFeed will return a feed of active campaigns This will return an Error if no campaigns are found (404)
For more information: https://docs.tonicpow.com/#b3fe69d3-24ba-4c2a-a485-affbb0a738de
func (*Client) CancelConversion ¶ added in v0.7.4
func (c *Client) CancelConversion(conversionID uint64, cancelReason string) (conversion *Conversion, response *StandardResponse, err error)
CancelConversion will cancel an existing conversion (if delay was set and > 1 minute remaining)
For more information: https://docs.tonicpow.com/#e650b083-bbb4-4ff7-9879-c14b1ab3f753
Example ¶
ExampleClient_CancelConversion example using CancelConversion()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseConversion := newTestConversion() responseConversion.Status = "processed" _ = mockResponseData( http.MethodPut, fmt.Sprintf("%s/%s/cancel", EnvironmentDevelopment.apiURL, modelConversion), http.StatusOK, responseConversion, ) // Cancel conversion (using mocking response) _, _, err = client.CancelConversion(responseConversion.ID, "your custom reason") if err != nil { fmt.Printf("error canceling conversion: " + err.Error()) return } fmt.Printf("conversion: %s", responseConversion.Status)
Output: conversion: processed
func (*Client) CreateCampaign ¶ added in v0.2.0
func (c *Client) CreateCampaign(campaign *Campaign) (*StandardResponse, error)
CreateCampaign will make a new campaign for the associated advertiser profile
For more information: https://docs.tonicpow.com/#b67e92bf-a481-44f6-a31d-26e6e0c521b1
Example ¶
ExampleClient_CreateCampaign example using CreateCampaign()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseCampaign := newTestCampaign() _ = mockResponseData( http.MethodPost, fmt.Sprintf("%s/%s", EnvironmentDevelopment.apiURL, modelCampaign), http.StatusCreated, responseCampaign, ) // Create campaign (using mocking response) if _, err = client.CreateCampaign(responseCampaign); err != nil { fmt.Printf("error creating campaign: " + err.Error()) return } fmt.Printf("created campaign: %s", responseCampaign.Title)
Output: created campaign: TonicPow
func (*Client) CreateConversion ¶ added in v0.7.4
func (c *Client) CreateConversion(opts ...ConversionOps) (conversion *Conversion, response *StandardResponse, err error)
CreateConversion will fire a conversion for a given goal, if successful it will make a new Conversion
For more information: https://docs.tonicpow.com/#caeffdd5-eaad-4fc8-ac01-8288b50e8e27
Example ¶
ExampleClient_CreateConversion example using CreateConversion()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseConversion := newTestConversion() _ = mockResponseData( http.MethodPost, fmt.Sprintf("%s/%s", EnvironmentDevelopment.apiURL, modelConversion), http.StatusCreated, responseConversion, ) // Create conversion (using mocking response) var newConversion *Conversion newConversion, _, err = client.CreateConversion( WithGoalID(testGoalID), WithTncpwSession(testTncpwSession), ) if err != nil { fmt.Printf("error creating conversion: " + err.Error()) return } fmt.Printf("conversion created: %d", newConversion.ID)
Output: conversion created: 99
func (*Client) CreateGoal ¶ added in v0.2.0
func (c *Client) CreateGoal(goal *Goal) (*StandardResponse, error)
CreateGoal will make a new goal
For more information: https://docs.tonicpow.com/#29a93e9b-9726-474c-b25e-92586200a803
Example ¶
ExampleClient_CreateGoal example using CreateGoal()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseGoal := newTestGoal() _ = mockResponseData( http.MethodPost, fmt.Sprintf("%s/%s", EnvironmentDevelopment.apiURL, modelGoal), http.StatusCreated, responseGoal, ) // Create goal (using mocking response) if _, err = client.CreateGoal(responseGoal); err != nil { fmt.Printf("error creating goal: " + err.Error()) return } fmt.Printf("created goal: %s", responseGoal.Name)
Output: created goal: example_goal
func (*Client) DeleteGoal ¶ added in v0.7.4
func (c *Client) DeleteGoal(goalID uint64) (bool, *StandardResponse, error)
DeleteGoal will delete an existing goal
For more information: https://docs.tonicpow.com/#38605b65-72c9-4fc8-87a7-bc644bc89a96
Example ¶
ExampleClient_DeleteGoal example using DeleteGoal()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseGoal := newTestGoal() _ = mockResponseData( http.MethodDelete, fmt.Sprintf("%s/%s?%s=%d", EnvironmentDevelopment.apiURL, modelGoal, fieldID, responseGoal.ID), http.StatusOK, nil, ) // Delete goal (using mocking response) var deleted bool if deleted, _, err = client.DeleteGoal(responseGoal.ID); err != nil { fmt.Printf("error deleting goal: " + err.Error()) return } fmt.Printf("goal deleted: %t", deleted)
Output: goal deleted: true
func (*Client) GetAdvertiserProfile ¶ added in v0.2.0
func (c *Client) GetAdvertiserProfile(profileID uint64) (profile *AdvertiserProfile, response *StandardResponse, err error)
GetAdvertiserProfile will get an existing advertiser profile This will return an Error if the profile is not found (404)
For more information: https://docs.tonicpow.com/#b3a62d35-7778-4314-9321-01f5266c3b51
Example ¶
ExampleClient_GetAdvertiserProfile example using GetAdvertiserProfile()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // For mocking responseProfile := newTestAdvertiserProfile() // Mock response (for example only) _ = mockResponseData( http.MethodGet, fmt.Sprintf("%s/%s/details/%d", EnvironmentDevelopment.apiURL, modelAdvertiser, responseProfile.ID), http.StatusOK, responseProfile, ) // Get profile (using mocking response) var profile *AdvertiserProfile if profile, _, err = client.GetAdvertiserProfile(testAdvertiserID); err != nil { fmt.Printf("error getting profile: " + err.Error()) return } fmt.Printf("advertiser profile: %s", profile.Name)
Output: advertiser profile: TonicPow
func (*Client) GetCampaign ¶ added in v0.2.0
func (c *Client) GetCampaign(campaignID uint64) (campaign *Campaign, response *StandardResponse, err error)
GetCampaign will get an existing campaign by ID This will return an Error if the campaign is not found (404)
For more information: https://docs.tonicpow.com/#b827446b-be34-4678-b347-33c4f63dbf9e
Example ¶
ExampleClient_GetCampaign example using GetCampaign()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseCampaign := newTestCampaign() _ = mockResponseData( http.MethodGet, fmt.Sprintf( "%s/%s/details/?%s=%d", EnvironmentDevelopment.apiURL, modelCampaign, fieldID, responseCampaign.ID, ), http.StatusOK, responseCampaign, ) // Get campaign (using mocking response) if responseCampaign, _, err = client.GetCampaign(responseCampaign.ID); err != nil { fmt.Printf("error getting campaign: " + err.Error()) return } fmt.Printf("campaign: %s", responseCampaign.Title)
Output: campaign: TonicPow
func (*Client) GetCampaignBySlug ¶ added in v0.7.4
func (c *Client) GetCampaignBySlug(slug string) (campaign *Campaign, response *StandardResponse, err error)
GetCampaignBySlug will get an existing campaign by slug This will return an Error if the campaign is not found (404)
For more information: https://docs.tonicpow.com/#b827446b-be34-4678-b347-33c4f63dbf9e
Example ¶
ExampleClient_GetCampaignBySlug example using GetCampaignBySlug()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseCampaign := newTestCampaign() _ = mockResponseData( http.MethodGet, fmt.Sprintf( "%s/%s/details/?%s=%s", EnvironmentDevelopment.apiURL, modelCampaign, fieldSlug, responseCampaign.Slug, ), http.StatusOK, responseCampaign, ) // Get campaign (using mocking response) if responseCampaign, _, err = client.GetCampaignBySlug( responseCampaign.Slug, ); err != nil { fmt.Printf("error getting campaign: " + err.Error()) return } fmt.Printf("campaign: %s", responseCampaign.Title)
Output: campaign: TonicPow
func (*Client) GetConversion ¶ added in v0.7.4
func (c *Client) GetConversion(conversionID uint64) (conversion *Conversion, response *StandardResponse, err error)
GetConversion will get an existing conversion This will return an Error if the goal is not found (404)
For more information: https://docs.tonicpow.com/#fce465a1-d8d5-442d-be22-95169170167e
Example ¶
ExampleClient_GetConversion example using GetConversion()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseConversion := newTestConversion() _ = mockResponseData( http.MethodGet, fmt.Sprintf("%s/%s/details/%d", EnvironmentDevelopment.apiURL, modelConversion, responseConversion.ID), http.StatusOK, responseConversion, ) // Create conversion (using mocking response) var conversion *Conversion conversion, _, err = client.GetConversion(responseConversion.ID) if err != nil { fmt.Printf("error getting conversion: " + err.Error()) return } fmt.Printf("conversion: %d", conversion.ID)
Output: conversion: 99
func (*Client) GetCurrentRate ¶ added in v0.7.4
func (c *Client) GetCurrentRate(currency string, customAmount float64) (rate *Rate, response *StandardResponse, err error)
GetCurrentRate will get a current rate for the given currency (using default currency amount)
For more information: https://docs.tonicpow.com/#71b8b7fc-317a-4e68-bd2a-5b0da012361c
Example ¶
ExampleClient_GetCurrentRate example using GetCurrentRate()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // For mocking rates := newTestRate() // Mock response (for example only) _ = mockResponseData( http.MethodGet, fmt.Sprintf( "%s/%s/%s?%s=%f", EnvironmentDevelopment.apiURL, modelRates, testRateCurrency, fieldAmount, 0.0, ), http.StatusOK, rates, ) // Get rate (using mocking response) var currentRate *Rate if currentRate, _, err = client.GetCurrentRate( testRateCurrency, 0.00, ); err != nil { fmt.Printf("error getting profile: " + err.Error()) return } fmt.Printf("current rate: %s %f usd is %d sats", currentRate.Currency, currentRate.CurrencyAmount, currentRate.PriceInSatoshis)
Output: current rate: usd 0.010000 usd is 4200 sats
func (*Client) GetEnvironment ¶ added in v0.7.4
func (c *Client) GetEnvironment() Environment
GetEnvironment will return the Environment of the client
func (*Client) GetGoal ¶ added in v0.2.0
func (c *Client) GetGoal(goalID uint64) (goal *Goal, response *StandardResponse, err error)
GetGoal will get an existing goal This will return an Error if the goal is not found (404)
For more information: https://docs.tonicpow.com/#48d7bbc8-5d7b-4078-87b7-25f545c3deaf
Example ¶
ExampleClient_GetGoal example using GetGoal()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseGoal := newTestGoal() _ = mockResponseData( http.MethodGet, fmt.Sprintf( "%s/%s/details/%d", EnvironmentDevelopment.apiURL, modelGoal, responseGoal.ID, ), http.StatusOK, responseGoal, ) // Get goal (using mocking response) if responseGoal, _, err = client.GetGoal(responseGoal.ID); err != nil { fmt.Printf("error getting goal: " + err.Error()) return } fmt.Printf("goal: %s", responseGoal.Name)
Output: goal: example_goal
func (*Client) GetUserAgent ¶ added in v0.7.4
GetUserAgent will return the user agent string of the client
func (*Client) ListAppsByAdvertiserProfile ¶ added in v0.7.4
func (c *Client) ListAppsByAdvertiserProfile(profileID uint64, page, resultsPerPage int, sortBy, sortOrder string) (apps *AppResults, response *StandardResponse, err error)
ListAppsByAdvertiserProfile will return a list of apps
For more information: https://docs.tonicpow.com/#9c9fa8dc-3017-402e-8059-136b0eb85c2e
func (*Client) ListCampaigns ¶ added in v0.7.4
func (c *Client) ListCampaigns(page, resultsPerPage int, sortBy, sortOrder, searchQuery string, minimumBalance uint64, includeExpired bool) (results *CampaignResults, response *StandardResponse, err error)
ListCampaigns 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/#c1b17be6-cb10-48b3-a519-4686961ff41c
func (*Client) ListCampaignsByAdvertiserProfile ¶ added in v0.7.4
func (c *Client) ListCampaignsByAdvertiserProfile(profileID uint64, page, resultsPerPage int, sortBy, sortOrder string) (campaigns *CampaignResults, response *StandardResponse, err error)
ListCampaignsByAdvertiserProfile will return a list of campaigns
For more information: https://docs.tonicpow.com/#98017e9a-37dd-4810-9483-b6c400572e0c
func (*Client) ListCampaignsByURL ¶ added in v0.7.4
func (c *Client) ListCampaignsByURL(targetURL string, page, resultsPerPage int, sortBy, sortOrder string) (results *CampaignResults, response *StandardResponse, err error)
ListCampaignsByURL will return a list of campaigns using the target url This will return an Error if the url is not found (404)
For more information: https://docs.tonicpow.com/#30a15b69-7912-4e25-ba41-212529fba5ff
func (*Client) Options ¶ added in v0.7.4
func (c *Client) Options() *ClientOptions
Options will return the clients current options
func (*Client) Request ¶
func (c *Client) Request(httpMethod string, requestEndpoint string, data interface{}, expectedCode int) (response *StandardResponse, err error)
Request is a standard GET / POST / PUT / DELETE request for all outgoing HTTP requests Omit the data attribute if using a GET request
func (*Client) UpdateAdvertiserProfile ¶ added in v0.2.0
func (c *Client) UpdateAdvertiserProfile(profile *AdvertiserProfile) (*StandardResponse, error)
UpdateAdvertiserProfile will update an existing profile
For more information: https://docs.tonicpow.com/#0cebd1ff-b1ce-4111-aff6-9d586f632a84
Example ¶
ExampleClient_UpdateAdvertiserProfile example using UpdateAdvertiserProfile()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Start with an existing profile profile := newTestAdvertiserProfile() profile.Name = testAdvertiserName // Mock response (for example only) _ = mockResponseData( http.MethodPut, fmt.Sprintf("%s/%s", EnvironmentDevelopment.apiURL, modelAdvertiser), http.StatusOK, profile, ) // Update profile _, err = client.UpdateAdvertiserProfile(profile) if err != nil { fmt.Printf("error updating profile: " + err.Error()) return } fmt.Printf("profile updated: %s", profile.Name)
Output: profile updated: TonicPow Test
func (*Client) UpdateCampaign ¶ added in v0.2.0
func (c *Client) UpdateCampaign(campaign *Campaign) (response *StandardResponse, err error)
UpdateCampaign will update an existing campaign
For more information: https://docs.tonicpow.com/#665eefd6-da42-4ca9-853c-fd8ca1bf66b2
Example ¶
ExampleClient_UpdateCampaign example using UpdateCampaign()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseCampaign := newTestCampaign() responseCampaign.Title = "TonicPow Title" _ = mockResponseData( http.MethodPut, fmt.Sprintf("%s/%s", EnvironmentDevelopment.apiURL, modelCampaign), http.StatusOK, responseCampaign, ) // Update campaign (using mocking response) _, err = client.UpdateCampaign(responseCampaign) if err != nil { fmt.Printf("error updating campaign: " + err.Error()) return } fmt.Printf("campaign: %s", responseCampaign.Title)
Output: campaign: TonicPow Title
func (*Client) UpdateGoal ¶ added in v0.2.0
func (c *Client) UpdateGoal(goal *Goal) (*StandardResponse, error)
UpdateGoal will update an existing goal
For more information: https://docs.tonicpow.com/#395f5b7d-6a5d-49c8-b1ae-abf7f90b42a2
Example ¶
ExampleClient_UpdateGoal example using UpdateGoal()
See more examples in /examples/
// Load the client (using test client for example only) client, err := newTestClient() if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } // Mock response (for example only) responseGoal := newTestGoal() responseGoal.Title = "Updated Title" _ = mockResponseData( http.MethodPut, fmt.Sprintf("%s/%s", EnvironmentDevelopment.apiURL, modelGoal), http.StatusOK, responseGoal, ) // Update goal (using mocking response) _, err = client.UpdateGoal(responseGoal) if err != nil { fmt.Printf("error updating goal: " + err.Error()) return } fmt.Printf("goal: %s", responseGoal.Title)
Output: goal: Updated Title
func (*Client) WithCustomHTTPClient ¶ added in v0.7.4
WithCustomHTTPClient will overwrite the default client with a custom client.
type ClientInterface ¶ added in v0.7.4
type ClientInterface interface { AdvertiserService CampaignService ConversionService GoalService RateService GetEnvironment() Environment GetUserAgent() string Options() *ClientOptions Request(httpMethod string, requestEndpoint string, data interface{}, expectedCode int) (response *StandardResponse, err error) WithCustomHTTPClient(client *resty.Client) *Client }
ClientInterface is the Tonicpow client interface
func NewClient ¶
func NewClient(opts ...ClientOps) (ClientInterface, error)
NewClient creates a new client for all TonicPow requests
If no options are given, it will use the DefaultClientOptions() If there is no client is supplied, it will use a default Resty HTTP client.
Example ¶
ExampleNewClient example using NewClient()
See more examples in /examples/
client, err := NewClient(WithAPIKey(testAPIKey)) if err != nil { fmt.Printf("error loading client: %s", err.Error()) return } fmt.Printf("loaded client: %s", client.Options().userAgent)
Output: loaded client: go-tonicpow: v0.8.0
type ClientOps ¶ added in v0.7.4
type ClientOps func(c *ClientOptions)
ClientOps allow functional options to be supplied that overwrite default client options.
func WithAPIKey ¶ added in v0.7.4
WithAPIKey provides the API key
func WithCustomEnvironment ¶ added in v0.7.4
WithCustomEnvironment will set a custom Environment
func WithCustomHeaders ¶ added in v0.7.4
WithCustomHeaders will add custom headers to outgoing requests Custom headers is empty by default
func WithEnvironment ¶ added in v0.7.4
func WithEnvironment(e Environment) ClientOps
WithEnvironment will change the Environment
func WithEnvironmentString ¶ added in v0.7.4
WithEnvironmentString will change the Environment
func WithHTTPTimeout ¶ added in v0.7.4
WithHTTPTimeout can be supplied to adjust the default http client timeouts. The http client is used when creating requests Default timeout is 10 seconds.
func WithRequestTracing ¶ added in v0.7.4
func WithRequestTracing() ClientOps
WithRequestTracing will enable tracing. Tracing is disabled by default.
func WithRetryCount ¶ added in v0.7.4
WithRetryCount will overwrite the default retry count for http requests. Default retries is 2.
func WithUserAgent ¶ added in v0.7.4
WithUserAgent will overwrite the default useragent. Default is package name + version.
type ClientOptions ¶ added in v0.7.4
type ClientOptions struct {
// contains filtered or unexported fields
}
ClientOptions holds all the configuration for client requests and default resources
type Conversion ¶ added in v0.2.0
type Conversion struct { Amount float64 `json:"amount,omitempty"` CampaignID uint64 `json:"campaign_id"` CustomDimensions string `json:"custom_dimensions"` GoalID uint64 `json:"goal_id"` GoalName string `json:"goal_name,omitempty"` ID uint64 `json:"id,omitempty"` PayoutAfter string `json:"payout_after,omitempty"` Status string `json:"status"` StatusData string `json:"status_data"` TxID string `json:"tx_id"` UserID uint64 `json:"user_id"` }
Conversion is the response of getting a conversion
For more information: https://docs.tonicpow.com/#75c837d5-3336-4d87-a686-d80c6f8938b9
type ConversionOps ¶ added in v0.7.4
type ConversionOps func(c *conversionOptions)
ConversionOps allow functional options to be supplied that overwrite default conversion options.
func WithCustomDimensions ¶ added in v0.7.4
func WithCustomDimensions(dimensions string) ConversionOps
WithCustomDimensions will set custom dimensions (string / json)
func WithDelay ¶ added in v0.7.4
func WithDelay(minutes uint64) ConversionOps
WithDelay will set a delay in minutes
func WithGoalID ¶ added in v0.7.4
func WithGoalID(goalID uint64) ConversionOps
WithGoalID will set a goal ID
func WithGoalName ¶ added in v0.7.4
func WithGoalName(name string) ConversionOps
WithGoalName will set a goal name
func WithPurchaseAmount ¶ added in v0.7.4
func WithPurchaseAmount(amount float64) ConversionOps
WithPurchaseAmount will set purchase amount from e-commerce
func WithShortCode ¶ added in v0.7.4
func WithShortCode(shortCode string) ConversionOps
WithShortCode will set a link short code
func WithTncpwSession ¶ added in v0.7.4
func WithTncpwSession(session string) ConversionOps
WithTncpwSession will set a tncpw_session
func WithTwitterID ¶ added in v0.7.4
func WithTwitterID(twitterID string) ConversionOps
WithTwitterID will set a Twitter user ID
func WithUserID ¶ added in v0.7.4
func WithUserID(userID uint64) ConversionOps
WithUserID will set a tonicpow user ID
type ConversionService ¶ added in v0.7.4
type ConversionService interface { CancelConversion(conversionID uint64, cancelReason string) (conversion *Conversion, response *StandardResponse, err error) CreateConversion(opts ...ConversionOps) (conversion *Conversion, response *StandardResponse, err error) GetConversion(conversionID uint64) (conversion *Conversion, response *StandardResponse, err error) }
ConversionService is the conversion requests
type Environment ¶ added in v0.7.4
type Environment struct {
// contains filtered or unexported fields
}
Environment is used for changing the Environment for running client requests
func (Environment) Alias ¶ added in v0.7.4
func (e Environment) Alias() string
Alias will return the Environment's alias
Example ¶
ExampleEnvironment_Alias example using Alias()
See more examples in /examples/
env := EnvironmentLive fmt.Printf("name: %s alias: %s", env.Name(), env.Alias())
Output: name: live alias: production
func (Environment) Name ¶ added in v0.7.4
func (e Environment) Name() string
Name will return the Environment's name
Example ¶
ExampleEnvironment_Name example using Name()
See more examples in /examples/
env := EnvironmentLive fmt.Printf("name: %s alias: %s", env.Name(), env.Alias())
Output: name: live alias: production
func (Environment) URL ¶ added in v0.7.4
func (e Environment) URL() string
URL will return the Environment's url
Example ¶
ExampleEnvironment_URL example using URL()
See more examples in /examples/
env := EnvironmentLive fmt.Printf("name: %s url: %s", env.Name(), env.URL())
Output: name: live url: https://api.tonicpow.com/v1
type Error ¶
type Error struct { Code int `json:"code"` Data interface{} `json:"data"` IPAddress string `json:"ip_address"` Message string `json:"message"` Method string `json:"method"` RequestGUID string `json:"request_guid"` StatusCode int `json:"status_code"` URL string `json:"url"` }
Error is the universal Error response from the API
For more information: https://docs.tonicpow.com/#d7fe13a3-2b6d-4399-8d0f-1d6b8ad6ebd9
type FeedType ¶ added in v0.7.4
type FeedType string
FeedType is used for the campaign feeds (rss, atom, json)
func GetFeedType ¶ added in v0.7.4
GetFeedType will return the feed type based on the provided string
type Goal ¶ added in v0.2.0
type Goal struct { CampaignID uint64 `json:"campaign_id"` Description string `json:"description"` ID uint64 `json:"id,omitempty"` LastConvertedAt string `json:"last_converted_at"` MaxPerPromoter int16 `json:"max_per_promoter"` MaxPerVisitor int16 `json:"max_per_visitor"` Name string `json:"name"` PayoutInstant bool `json:"payout_instant"` PayoutRate float64 `json:"payout_rate"` Payouts int `json:"payouts"` PayoutType string `json:"payout_type"` Title string `json:"title"` }
Goal is the goal model (child of Campaign)
For more information: https://docs.tonicpow.com/#316b77ab-4900-4f3d-96a7-e67c00af10ca
type GoalService ¶ added in v0.7.4
type GoalService interface { CreateGoal(goal *Goal) (*StandardResponse, error) DeleteGoal(goalID uint64) (bool, *StandardResponse, error) GetGoal(goalID uint64) (goal *Goal, response *StandardResponse, err error) UpdateGoal(goal *Goal) (*StandardResponse, error) }
GoalService is the goal requests
type Rate ¶ added in v0.7.4
type Rate struct { Currency string `json:"currency"` CurrencyAmount float64 `json:"currency_amount"` PriceInSatoshis int64 `json:"price_in_satoshis"` }
Rate is the rate results
For more information: https://docs.tonicpow.com/#fb00736e-61b9-4ec9-acaf-e3f9bb046c89
type RateService ¶ added in v0.7.4
type RateService interface {
GetCurrentRate(currency string, customAmount float64) (rate *Rate, response *StandardResponse, err error)
}
RateService is the rate requests
type StandardResponse ¶ added in v0.7.4
type StandardResponse struct { Body []byte `json:"-"` // Body of the response request Error *Error `json:"-"` // API error response StatusCode int `json:"-"` // Status code returned on the request Tracing resty.TraceInfo `json:"-"` // Trace information if enabled on the request }
StandardResponse is the standard fields returned on all responses