Skip to content

Commit

Permalink
Get campaigns by url
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jan 15, 2020
1 parent 8d22504 commit d74bab2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
7 changes: 7 additions & 0 deletions examples/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ let apiKey = process.env.TONICPOW_API_KEY || ''
//console.log(campaigns)
console.log('campaigns found: '+campaigns.length)

//
// Example: Get of campaigns by Url
//
campaigns = await TonicPow.getCampaignsByUrl(campaigns[0].target_url)
//console.log(campaigns)
console.log('campaigns found by url: '+campaigns.length)

//
// Example: Create a Visitor Session
//
Expand Down
25 changes: 22 additions & 3 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ async function currentUser (t, userSessionToken = '') {
//
// For more information: https://docs.tonicpow.com/#8478765b-95b8-47ad-8b86-2db5bce54924
async function getUserBalance (t, userId, lastBalance = 0) {
return tonicAxios.get(t.config.apiUrl + version + '/users/balance/' + userId+'?last_balance='+lastBalance, getOptions())
return tonicAxios.get(t.config.apiUrl + version + '/users/balance/' + userId + '?last_balance=' + lastBalance, getOptions())
}

// getUser will get a user by ID or email address
Expand Down Expand Up @@ -580,7 +580,7 @@ async function getCampaign (t, campaignId, userSessionToken = '') {
//
// For more information: https://docs.tonicpow.com/#b6c60c63-8ac5-4c74-a4a2-cf3e858e5a8d
async function getCampaignBalance (t, campaignId, lastBalance = 0) {
return tonicAxios.get(t.config.apiUrl + version + '/campaigns/balance/' + campaignId + '?last_balance='+lastBalance, getOptions())
return tonicAxios.get(t.config.apiUrl + version + '/campaigns/balance/' + campaignId + '?last_balance=' + lastBalance, getOptions())
}

// updateCampaign will update an existing campaign
Expand All @@ -599,6 +599,14 @@ async function listCampaigns (t, customSessionToken = '') {
return tonicAxios.get(t.config.apiUrl + version + '/campaigns/list', getOptions(customSessionToken))
}

// getCampaignsByUrl 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
async function getCampaignsByUrl (t, url) {
return tonicAxios.get(t.config.apiUrl + version + '/campaigns/find?target_url=' + url, getOptions())
}

//
// TonicPow API - Goal Requests
// =====================================================================================================================
Expand Down Expand Up @@ -1032,7 +1040,7 @@ module.exports = {
}
})
},
getCampaignBalance: async function (campaignId,lastBalance = 0) {
getCampaignBalance: async function (campaignId, lastBalance = 0) {
return new Promise(async (resolve, reject) => {
try {
initCheck(this.loaded)
Expand Down Expand Up @@ -1067,6 +1075,17 @@ module.exports = {
}
})
},
getCampaignsByUrl: async function (url) {
return new Promise(async (resolve, reject) => {
try {
initCheck(this.loaded)
let response = await getCampaignsByUrl(this, url)
resolve(response.data)
} catch (e) {
reject(checkError(e))
}
})
},
createGoal: async function (goal, userSessionToken = '') {
return new Promise(async (resolve, reject) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tonicpow-js",
"version": "0.1.38",
"version": "0.1.39",
"description": "TonicPow API Library in JS - https://docs.tonicpow.com",
"main": "lib/api.js",
"repository": {
Expand Down

0 comments on commit d74bab2

Please sign in to comment.