Skip to content

Commit

Permalink
Fixes missing array in body request and exposes programmatic usage (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmammino authored Apr 22, 2018
1 parent 2dd0f77 commit 2f4ca23
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,40 @@ Usage: godaddy-dns [options]
-i, --ipfile [file] specify which file to use to store the last found ip (default "<user temp folder>/.lastip")
```


## Programmatic usage

If you want to use the features of this module in a Node.js project:

```javascript
const dns = require("godaddy-dns");

dns.getCurrentIp().then((currentIp)=>{
console.log("Current ip",currentIp);

dns.updateRecords(currentIp,{
"apiKey": "",
"secret": "",
"domain": "example.com",
"records": [
{"type": "A", "name": "@", "ttl": 600}
]
})
.then(() => {
console.log(`[${new Date()}] Successfully updated DNS records to ip ${currentIp}`)
})
.catch((err) => {
if (err && err.message !== 'Nothing to update') {
console.error(`[${new Date()}] ${err}`)
process.exit(1)
}
});
});
```

Thanks [@aandrulis](https://github.com/aandrulis) for suggesting to expose this.


## Bugs and improvements

If you find a bug or have an idea about how to improve this script you can [open an issue](https://github.com/lmammino/godaddy-dns/issues) or [submit a pull request](https://github.com/lmammino/godaddy-dns/pulls), it will definitely make you a better person! 😝
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "godaddy-dns",
"version": "1.2.1",
"version": "1.3.0",
"description": "A Node.js script to programmatically update GoDaddy DNS records",
"repository": {
"type": "git",
Expand All @@ -10,6 +10,7 @@
"type": "MIT",
"url": "https://raw.githubusercontent.com/lmammino/godaddy-dns/master/LICENSE"
},
"main": "src/godaddy-dns.js",
"bin": {
"godaddy-dns": "src/cli.js"
},
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/updateRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('It should update a set of records', endTest => {
'authorization': `sso-key someKey:someSecret`,
'content-type': 'application/json'
},
body: {data: ip, type: 'A', name: '@', ttl: 600},
body: [ {data: ip, type: 'A', name: '@', ttl: 600} ],
json: true
},
{
Expand All @@ -33,7 +33,7 @@ test('It should update a set of records', endTest => {
'authorization': `sso-key someKey:someSecret`,
'content-type': 'application/json'
},
body: {data: ip, type: 'A', name: 'subdomain2', ttl: 700},
body: [ {data: ip, type: 'A', name: 'subdomain2', ttl: 700} ],
json: true
}
]
Expand Down Expand Up @@ -69,7 +69,7 @@ test('It should update a single record', endTest => {
'authorization': `sso-key someKey:someSecret`,
'content-type': 'application/json'
},
body: {data: ip, type: 'A', name: '@', ttl: 600},
body: [ {data: ip, type: 'A', name: '@', ttl: 600} ],
json: true
}

Expand Down
7 changes: 7 additions & 0 deletions src/godaddy-dns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const getCurrentIp = require('./getCurrentIp')
const updateRecords = require('./updateRecords')

module.exports = {
getCurrentIp,
updateRecords
}
3 changes: 2 additions & 1 deletion src/updateRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = function updateRecords (ip, config) {
}
records = records.map((record) => {
// if current record is a single string
// wrap it in array
if (typeof record === 'string') {
record = {name: record}
}
Expand All @@ -34,7 +35,7 @@ module.exports = function updateRecords (ip, config) {
'authorization': `sso-key ${config.apiKey}:${config.secret}`,
'content-type': 'application/json'
},
body: record,
body: [ record ],
json: true
}
return request(options)
Expand Down

0 comments on commit 2f4ca23

Please sign in to comment.