Skip to content

Commit

Permalink
Added advertiser profile requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Dec 30, 2019
1 parent ff122cd commit 2066d5d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Here as example of session tracking for [goal conversions](front_end.md)
- Coverage for the [TonicPow.com API](https://docs.tonicpow.com/)
- [x] Authentication
- [x] Users
- [ ] Advertiser Profiles
- [x] Advertiser Profiles
- [ ] Campaigns
- [ ] Goals
- [ ] Links
Expand Down
25 changes: 25 additions & 0 deletions examples/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ let apiKey = process.env.TONICPOW_API_KEY || ''
user = await TonicPow.getUser(0,user.email)
console.log('user found: '+user.email)

//
// Example: Create an advertiser profile
//
let newAdvertiser = {
user_id: user.id,
name: 'Acme User Advertising',
homepage_url:'https://tonicpow.com',
icon_url: 'https://tonicpow.com/images/logos/apple-touch-icon.png',
}
let advertiser = await TonicPow.createAdvertiserProfile(newAdvertiser)
console.log('advertiser created', advertiser)

//
// Example: Get an advertiser profile
//
advertiser = await TonicPow.getAdvertiserProfile(advertiser.id)
console.log('advertiser found: '+advertiser.name)

//
// Example: Update an advertiser profile
//
advertiser.name = 'Acme Advertising'
advertiser = await TonicPow.updateAdvertiserProfile(advertiser)
console.log('updated name: '+advertiser.name)


} catch(e){
console.error(e)
Expand Down
74 changes: 73 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function wrapAxios(t) {
}

//
// TonicPow API Requests
// TonicPow API - User Requests
// =====================================================================================================================
//

Expand Down Expand Up @@ -339,6 +339,36 @@ async function completePhoneVerification(t, phone, phoneCode) {
return axios.put(t.config.apiUrl + version + '/users/verify/phone', {phone: phone, phone_code: phoneCode}, getOptions())
}

//
// TonicPow API - Advertiser Profile Requests
// =====================================================================================================================
//

// createAdvertiserProfile will make a new advertiser profile
// Use the userSessionToken if making request on behalf of another user
//
// For more information: https://docs.tonicpow.com/#153c0b65-2d4c-4972-9aab-f791db05b37b
async function createAdvertiserProfile(t, profile, userSessionToken) {
return axios.post(t.config.apiUrl + version + '/advertisers', profile, getOptions(userSessionToken))
}

// getAdvertiserProfile will get an existing advertiser profile
// This will return an error if the profile is not found (404)
// Use the userSessionToken if making request on behalf of another user
//
// For more information: https://docs.tonicpow.com/#b3a62d35-7778-4314-9321-01f5266c3b51
async function getAdvertiserProfile(t, profileId, userSessionToken) {
return axios.get(t.config.apiUrl + version + '/advertisers/details/'+profileId, getOptions(userSessionToken))
}

// updateAdvertiserProfile will update an existing profile
// Use the userSessionToken if making request on behalf of another user
//
// For more information: https://docs.tonicpow.com/#0cebd1ff-b1ce-4111-aff6-9d586f632a84
async function updateAdvertiserProfile(t, profile, userSessionToken) {
return axios.put(t.config.apiUrl + version + '/advertisers', profile, getOptions(userSessionToken))
}


//
// Export TonicPow JS
Expand Down Expand Up @@ -562,4 +592,46 @@ module.exports = {
}
})
},
createAdvertiserProfile: async function(profile, userSessionToken){
return new Promise(async(resolve, reject) => {
try {
blockBrowser(this.initRequired())
let response = await createAdvertiserProfile(this, profile, userSessionToken)
resolve(response.data)
} catch(e){
if (typeof e.response !== 'undefined') {
reject(e.response.data)
}
reject(e.message)
}
})
},
getAdvertiserProfile: async function(profileId, userSessionToken){
return new Promise(async(resolve, reject) => {
try {
blockBrowser(this.initRequired())
let response = await getAdvertiserProfile(this, profileId, userSessionToken)
resolve(response.data)
} catch(e){
if (typeof e.response !== 'undefined') {
reject(e.response.data)
}
reject(e.message)
}
})
},
updateAdvertiserProfile: async function(profile, userSessionToken){
return new Promise(async(resolve, reject) => {
try {
blockBrowser(this.initRequired())
let response = await updateAdvertiserProfile(this, profile, userSessionToken)
resolve(response.data)
} catch(e){
if (typeof e.response !== 'undefined') {
reject(e.response.data)
}
reject(e.message)
}
})
},
}
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.7",
"version": "0.1.8",
"description": "TonicPow API Library in JS - https://docs.tonicpow.com",
"main": "lib/api.js",
"repository": {
Expand Down

0 comments on commit 2066d5d

Please sign in to comment.