Adding the request models
This commit is contained in:
@@ -1,7 +1,41 @@
|
||||
|
||||
const axios = require('axios')
|
||||
|
||||
class SpotifyController {
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Execute a GET request to the Spotify API
|
||||
function executeGetRequest(url, requestObject, options, responseType){
|
||||
return new Promise(function(resolve, reject){
|
||||
axios.get(url, requestObject.serializeBinary(), options)
|
||||
.then(function(response){
|
||||
if (response.statusText !== 'OK') {
|
||||
reject(`Request error (${response.status}): ${response.statusText}`)
|
||||
} else {
|
||||
resolve(responseType.deserializeBinary(response.data).toObject());
|
||||
}
|
||||
})
|
||||
.catch(function(error){
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Execute a POST request to the Spotify API
|
||||
function executePostRequest(url, requestObject, options, responseType){
|
||||
return new Promise(function(resolve, reject){
|
||||
axios.post(url, requestObject.serializeBinary(), options)
|
||||
.then(function(response){
|
||||
if (response.statusText !== 'OK') {
|
||||
reject(`Request error (${response.status}): ${response.statusText}`)
|
||||
} else {
|
||||
resolve(responseType.deserializeBinary(response.data).toObject());
|
||||
}
|
||||
})
|
||||
.catch(function(error){
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = SpotifyController;
|
||||
Reference in New Issue
Block a user