tonicpow-js
Version:
TonicPow API Library in JS - https://docs.tonicpow.com
456 lines (390 loc) • 10.2 kB
JavaScript
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _browserOrNode=require("browser-or-node"),_config=_interopRequireDefault(require("./config")),_apiClient=require("./api-client");
/**
* TonicPow JavaScript API class
*/
class TonicPow{
constructor(a,b={}){
if(!_browserOrNode.isNode)
throw new Error("This library only works in node");
// Set any defaults
this.config=new _config.default(a,b),
this.apiClient=(0,_apiClient.createApiClient)(this);
}
/**
* 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
*
* @param profileId
* @returns {Promise}
*/
async getAdvertiserProfile(a){
return this.apiClient.get("/advertisers/details/"+a);
}
/**
* updateAdvertiserProfile will update an existing profile
*
* For more information: https://docs.tonicpow.com/#0cebd1ff-b1ce-4111-aff6-9d586f632a84
*
* @param profile
* @returns {Promise}
*/
async updateAdvertiserProfile(a){
return this.apiClient.put("/advertisers",a);
}
/**
* listCampaignsByAdvertiserProfile 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
*
* @param profileId
* @param page
* @param resultsPerPage
* @param sortBy
* @param sortOrder
* @returns {Promise}
*/
async listCampaignsByAdvertiserProfile(
a,
b=1,
c=20,
d="",
e="")
{
return this.apiClient.get(
"/advertisers/campaigns/"+a+
"?current_page="+b+
"&results_per_page="+c+
"&sort_by="+d+
"&sort_order="+e);
}
/**
* listAppsByAdvertiserProfile will return a list of apps
*
* This will return an error if the campaign is not found (404)
*
* For more information: https://docs.tonicpow.com/#9c9fa8dc-3017-402e-8059-136b0eb85c2e
*
* @param profileId
* @param page
* @param resultsPerPage
* @param sortBy
* @param sortOrder
* @returns {Promise}
*/
async listAppsByAdvertiserProfile(
a,
b=1,
c=20,
d="",
e="")
{
return this.apiClient.get(
"/advertisers/apps/"+a+
"?current_page="+b+
"&results_per_page="+c+
"&sort_by="+d+
"&sort_order="+e);
}
/**
* createCampaign will make a new campaign
*
* For more information: https://docs.tonicpow.com/#b67e92bf-a481-44f6-a31d-26e6e0c521b1
*
* @param campaign
* @returns {Promise}
*/
async createCampaign(a){
return this.apiClient.post("/campaigns",a);
}
/**
* getCampaign will get an existing campaign
*
* This will return an error if the campaign is not found (404)
*
* For more information: https://docs.tonicpow.com/#b827446b-be34-4678-b347-33c4f63dbf9e
*
* @param campaignId
* @returns {Promise}
*/
async getCampaign(a){
return this.apiClient.get("/campaigns/details/?id="+a);
}
/**
* getCampaignBySlug will get an existing campaign by it's url 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
*
* @param campaignSlug
* @returns {Promise}
*/
async getCampaignBySlug(a){
return this.apiClient.get("/campaigns/details/?slug="+a);
}
/**
* refreshBalance will update the campaigns balance from the chain
*
* This will return an error if the campaign is not found (404)
*
* For more information: https://docs.tonicpow.com/#b6c60c63-8ac5-4c74-a4a2-cf3e858e5a8d
*
* @param campaignId
* @param lastBalance
* @returns {Promise}
*/
async refreshBalance(a,b=0){
return this.apiClient.get("/campaigns/balance/?id="+a+
"?last_balance="+b);
}
/**
* updateCampaign will update an existing campaign
*
* For more information: https://docs.tonicpow.com/#665eefd6-da42-4ca9-853c-fd8ca1bf66b2
*
* @param campaign
* @returns {Promise}
*/
async updateCampaign(a){
return this.apiClient.put("/campaigns",a);
}
/**
* listCampaigns will return a list of active 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
*
* @param page
* @param resultsPerPage
* @param sortBy
* @param sortOrder
* @returns {Promise}
*/
async listCampaigns(
a=1,
b=20,
c="",
d="")
{
return this.apiClient.get(
"/campaigns/list?current_page="+a+
"&results_per_page="+b+
"&sort_by="+c+
"&sort_order="+
d);
}
/**
* listCampaignsByUrl will return a list of active campaigns
*
* This will return an error if the url is not found (404)
*
* For more information: https://docs.tonicpow.com/#30a15b69-7912-4e25-ba41-212529fba5ff
*
* @param url
* @param page
* @param resultsPerPage
* @param sortBy
* @param sortOrder
* @returns {Promise}
*/
async listCampaignsByUrl(
a,
b=1,
c=20,
d="",
e="")
{
return this.apiClient.get(
"/campaigns/find?target_url="+a+
"¤t_page="+b+
"&results_per_page="+c+
"&sort_by="+d+
"&sort_order="+e);
}
/**
* campaignsFeed will return a feed of active campaigns
*
* This will return an error if no campaigns are found (404)
* Supports: rss, atom, json
*
* For more information: https://docs.tonicpow.com/#b3fe69d3-24ba-4c2a-a485-affbb0a738de
*
* @param feedType
* @returns {Promise}
*/
async campaignsFeed(a="rss"){
return this.apiClient.get("/campaigns/feed?feed_type="+a);
}
/**
* createGoal will make a new goal
*
* For more information: https://docs.tonicpow.com/#29a93e9b-9726-474c-b25e-92586200a803
*
* @param goal
* @returns {Promise}
*/
async createGoal(a){
return this.apiClient.post("/goals",a);
}
/**
* 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
*
* @param goalId
* @returns {Promise}
*/
async getGoal(a){
return this.apiClient.get("/goals/details/"+a);
}
/**
* updateGoal will update an existing goal
*
* For more information: https://docs.tonicpow.com/#395f5b7d-6a5d-49c8-b1ae-abf7f90b42a2
*
* @param goal
* @returns {Promise}
*/
async updateGoal(a){
return this.apiClient.put("/goals",a);
}
/**
* deleteGoal will delete an existing goal
*
* For more information: https://docs.tonicpow.com/#38605b65-72c9-4fc8-87a7-bc644bc89a96
*
* @param goal
* @returns {Promise}
*/
async deleteGoal(a){
return this.apiClient.delete("/goals?id="+a.id);
}
/**
* createConversionByGoalID will fire a conversion for a given goal id, if successful it will make a new Conversion
*
* For more information: https://docs.tonicpow.com/#caeffdd5-eaad-4fc8-ac01-8288b50e8e27
*
* @param goalId
* @param tncpwSession
* @param customDimensions
* @param optionalPurchaseAmount
* @param delayInMinutes
* @returns {Promise}
*/
async createConversionByGoalID(
a,
b,
c="",
d=0,
e=0)
{
return this.apiClient.post("/conversions",{goal_id:a,tncpw_session:b,custom_dimensions:c,delay_in_minutes:e,amount:d});
}
/**
* createConversionByGoalName will fire a conversion for a given goal name, if successful it will make a new Conversion
*
* For more information: https://docs.tonicpow.com/#d19c9850-3832-45b2-b880-3ef2f3b7dc37
*
* @param goalName
* @param tncpwSession
* @param customDimensions
* @param optionalPurchaseAmount
* @param delayInMinutes
* @returns {Promise}
*/
async createConversionByGoalName(
a,
b,
c="",
d=0,
e=0)
{
return this.apiClient.post("/conversions",{name:a,tncpw_session:b,custom_dimensions:c,delay_in_minutes:e,amount:d});
}
/**
* createConversionByUserID will fire a conversion for a given goal and user id, if successful it will make a new Conversion
*
* For more information: https://docs.tonicpow.com/#d724f762-329e-473d-bdc4-aebc19dd9ea8
*
* @param goalId
* @param userId
* @param customDimensions
* @param optionalPurchaseAmount
* @param delayInMinutes
* @returns {Promise}
*/
async createConversionByUserID(
a,
b,
c="",
d=0,
e=0)
{
return this.apiClient.post("/conversions",{goal_id:a,user_id:b,custom_dimensions:c,delay_in_minutes:e,amount:d});
}
/**
* createConversionByShortCode will fire a conversion for a given goal and link short_code, if successful it will make a new Conversion
*
* For more information: https://docs.tonicpow.com/#0017b795-6e0a-429b-8100-1d44b37ad5cd
*
* @param goalId
* @param shortCode
* @param customDimensions
* @param optionalPurchaseAmount
* @param delayInMinutes
* @returns {Promise}
*/
async createConversionByShortCode(
a,
b,
c="",
d=0,
e=0)
{
return this.apiClient.post("/conversions",{goal_id:a,short_code:b,custom_dimensions:c,delay_in_minutes:e,amount:d});
}
/**
* 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
*
* @param conversionId
* @returns {Promise}
*/
async getConversion(a){
return this.apiClient.get("/conversions/details/"+a);
}
/**
* 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
*
* @param conversionId
* @param reason
* @returns {Promise}
*/
async cancelConversion(a,b){
return this.apiClient.put("/conversions/cancel",{id:a,reason:b});
}
/**
* getCurrentRate will get a current rate for the given currency
*
* For more information: https://docs.tonicpow.com/#71b8b7fc-317a-4e68-bd2a-5b0da012361c
*
* @param currency
* @param customAmount
* @returns {Promise}
*/
async getCurrentRate(a,b=0){
return this.apiClient.get("/rates/"+a+"?amount="+b);
}}var _default=
TonicPow;exports.default=_default,module.exports=exports.default;