Skip to content

Commit

Permalink
Merge pull request #436 from devhun/vultr/issue-434
Browse files Browse the repository at this point in the history
Bug fixes #434
  • Loading branch information
ddymko authored Feb 24, 2021
2 parents 5d9874e + 792fd5f commit 6f05fe8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/api/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ exports.createRecord = {
requestType: 'POST',
apiKeyRequired: true,
parameters: {
'dns-domain': {
type: 'string',
path: true,
required: true
},
name: {
type: 'string',
required: true
Expand Down
24 changes: 12 additions & 12 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ exports.makeApiRequest = (config, endpoint, userParameters) => {
if (userParameters !== undefined) {
const { requestType, parameters } = endpoint

// All methods may have path parameters
const pathParams = Object.keys(userParameters).filter(
(key) => parameters[key].path
)

if (pathParams.length) {
pathParams.forEach((param) => {
// Ex. '/bare-metals/{baremetal-id}/ipv4' becomes '/bare-metals/123456/ipv4'
fetchUrl = fetchUrl.replace(`{${param}}`, userParameters[param])
})
}

if (requestType === 'POST') {
// POST requests will just send all data as JSON to the endpoint
options.body = JSON.stringify(userParameters)
options.headers['Content-Type'] = 'application/json'
} else {
// GET, DELETE, PATCH, and PUT may have path parameters
const pathParams = Object.keys(userParameters).filter(
(key) => parameters[key].path
)

if (pathParams.length) {
pathParams.forEach((param) => {
// Ex. '/bare-metals/{baremetal-id}/ipv4' becomes '/bare-metals/123456/ipv4'
fetchUrl = fetchUrl.replace(`{${param}}`, userParameters[param])
})
}

if (requestType === 'GET' || requestType === 'DELETE') {
// GET and DELETE requests may have path parameters as well as query parameters
const queryParams = Object.keys(userParameters)
Expand Down

0 comments on commit 6f05fe8

Please sign in to comment.