Skip to content

Commit

Permalink
Added create user request
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Dec 30, 2019
1 parent d471d6b commit 56e8c52
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ let apiKey = process.env.TONICPOW_API_KEY || ''
//response = await TonicPow.endSession()
//console.log(response)

//
// Example: Create a new user
//
//response = await TonicPow.createUser({email:"test123@tonicpow.com"})
//console.log(response)

//
// Example: Login (as a user)
//
Expand Down
27 changes: 27 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ async function getUser(t, userId, email) {
return axios.get(url, getOptions())
}

// createUser will create a new user given the attributes
//
// For more information: https://docs.tonicpow.com/#8de84fb5-ba77-42cc-abb0-f3044cc871b6
async function createUser(t, user) {

// Missing email
if (!user || user.email.length < 1) {
throw Error('email is required')
}

return axios.post(t.config.apiUrl + version + '/users', user, getOptions())
}

//
// Export TonicPow JS
// =====================================================================================================================
Expand Down Expand Up @@ -429,4 +442,18 @@ module.exports = {
}
})
},
createUser: async function(user){
return new Promise(async(resolve, reject) => {
try {
blockBrowser(this.initRequired())
let response = await createUser(this, user)
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.5",
"version": "0.1.6",
"description": "TonicPow API Library in JS - https://docs.tonicpow.com",
"main": "lib/api.js",
"repository": {
Expand Down

0 comments on commit 56e8c52

Please sign in to comment.