Skip to content

Instantly share code, notes, and snippets.

@cromwellryan
Created May 8, 2014 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cromwellryan/a23423b8de72813678c4 to your computer and use it in GitHub Desktop.
Save cromwellryan/a23423b8de72813678c4 to your computer and use it in GitHub Desktop.
Generate a CSV of all domain records on Dnsimple
https = require 'https'
p = console.log
email = process.argv[2]
token = process.argv[3]
dnsimple = (relative_url) ->
hostname: 'api.dnsimple.com'
port: 443
path: "/v1#{relative_url}"
headers: {
'X-DNSimple-Token': "#{email}:#{token}"
}
crap = (e) ->
p "Something bad happened calling #{e.api}"
p e.body
get_dnsimple_api = (api, next, err) ->
https.get dnsimple(api), (res) ->
body = ''
res.on 'data', (chunk) -> body += chunk
res.on 'end', ->
json = JSON.parse(body)
err({ body: json, api: api }) if res.statusCode != 200
next(json, err) if res.statusCode == 200
res.on 'error', err
get_domains = (next,err) ->
get_dnsimple_api '/domains', next, err
for_each_domain = (domains, next) ->
domains.forEach (domain) ->
next(domain.domain)
get_domain_records = (domain, next, err) ->
composed_next = (records) ->
next(domain, records)
get_dnsimple_api("/domains/#{domain.id}/records", composed_next, err)
print_domain_records = (domain, records) ->
records.forEach (record) ->
record = record.record
p "#{domain.name},#{record.record_type},#{record.content}"
get_records = (domains, next) ->
for_each_domain(domains, (domain) ->
get_domain_records(domain, print_domain_records, crap))
p "domain.name,record_type,record.content"
get_domains(get_records, crap)
@cromwellryan
Copy link
Author

Generates a CSV with something like:

coffee go.coffee <email> <token> > records.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment