Skip to content

Commit

Permalink
Added new getUserReferrals request
Browse files Browse the repository at this point in the history
mrz1836 committed Mar 31, 2020
1 parent 1a063e0 commit 9421914
Showing 3 changed files with 38 additions and 4 deletions.
6 changes: 6 additions & 0 deletions examples/examples.js
Original file line number Diff line number Diff line change
@@ -131,6 +131,12 @@ let apiKey = process.env.TONICPOW_API_KEY || ''
user = await TonicPow.getUser(0,user.email)
console.log('user found: '+user.email)

//
// Example: Get all referrals by a certain user
//
//let users = await TonicPow.getUserReferrals(0,user.email)
//console.log('referred users: '+users.length)

//
// Example: Activate a user
//
34 changes: 31 additions & 3 deletions lib/api.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ const internalHeaderKey = 'x-user-session-token'
const visitorSessionKey = 'tncpw_session'

// Current version for requests from the API
const pkgVersion = 'v0.1.68'
const pkgVersion = 'v0.1.69'
const apiVersion = 'v1'

// getOptions is a factory for axios default options
@@ -616,15 +616,32 @@ async function userExists (t, email) {
//
// For more information: https://docs.tonicpow.com/#be82b6cb-7fe8-4f03-9b0c-dbade8f2d40f
async function releaseUserBalance (t, userId, reason = '') {
return tonicAxios.put(t.config.apiUrl + apiVersion + '/users/wallet/release', { id: userId, reason:reason }, getOptions())
return tonicAxios.put(t.config.apiUrl + apiVersion + '/users/wallet/release', { id: userId, reason: reason }, getOptions())
}

// refundUserBalance will send the internal balance back to the corresponding campaigns
// Reason field is required
//
// For more information: https://docs.tonicpow.com/#c373c7ed-189d-4aa6-88da-c4a58955fd28
async function refundUserBalance (t, userId, reason) {
return tonicAxios.put(t.config.apiUrl + apiVersion + '/users/wallet/refund', { id: userId, reason:reason }, getOptions())
return tonicAxios.put(t.config.apiUrl + apiVersion + '/users/wallet/refund', { id: userId, reason: reason }, getOptions())
}

// getUserReferrals will return all the related referrals to the given user
// Use either an ID or email to get an existing user
//
// For more information: https://docs.tonicpow.com/#fa7ee5a6-c87d-4e01-8ad3-ef6bda39533b
async function getUserReferrals (t, userId = 0, email = '') {
let url = t.config.apiUrl + apiVersion + '/users/referred?'

if (userId && userId > 0) {
url += 'id=' + userId
} else {
email = email.split('+').join('%2B')
url += 'email=' + email
}

return tonicAxios.get(url, getOptions())
}

//
@@ -1037,6 +1054,17 @@ module.exports = {
}
})
},
getUserReferrals: async function (userId = 0, email = '') {
return new Promise(async (resolve, reject) => {
try {
initCheck(this.loaded)
let response = await getUserReferrals(this, userId, email)
resolve(response.data)
} catch (e) {
reject(checkError(e))
}
})
},
createUser: async function (user, referredVisitorSession = '', referredUserId = 0) {
return new Promise(async (resolve, reject) => {
try {
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.68",
"version": "0.1.69",
"description": "TonicPow API Library in JS - https://docs.tonicpow.com",
"main": "lib/api.js",
"repository": {

0 comments on commit 9421914

Please sign in to comment.