Reference: https://porkbun.com/api/json/v3/documentation
This is currently only a partial implementation to suit my own needs. If you need a specific call to be implemented, let me know, or submit a PR
gem install porkbun
ENV['PORKBUN_API_KEY'] = 'YOUR_API_KEY'
ENV['PORKBUN_SECRET_API_KEY'] = 'YOUR_SECRET_API_KEY'
domain = Porkbun.new('domain.org')
domain.records.each { |record| puts record.to_s }
record = domain.create_record('test',
type: 'A',
content: '1.1.1.1',
ttl: 300
)
record.update(content: '8.8.8.8')
record.deleteMake sure your keys are good.
all- returns an array ofPorkbun::Domainobjects for each domain in the account.create_record(hostname, options)- returns aPorkbun::Recordcreated from a full hostname.get_record(hostname)- returns one unambiguousPorkbun::Record.import(file)- returns an array ofPorkbun::Recordobjects created from a zone file.update_dynamic(hostname, ip)- returns a hash describing the created or updated record.
Porkbun::Domain.all.each { |domain| puts domain }
record = Porkbun::Domain.get_record('www.domain.org')
record.update(content: '8.8.8.8')Porkbun.new('domain.org') returns a Porkbun::Domain object.
records- returns an array ofPorkbun::Recordobjects for the domain.get_record(name)- returns one unambiguousPorkbun::Record;namecan be relative or fully qualified.create_record(name, options)- returns a newPorkbun::Record.delete_all_records- returns an array ofPorkbun::Recordobjects after deleting all non-NS records.zone_file- returns a string that can be passed toimport.
domain = Porkbun.new('domain.org')
record = domain.get_record('www')
record.update(content: '8.8.8.8')
record.delete
domain.delete_all_recordsA Porkbun::Record represents one DNS record and owns its mutations.
update(content:, ttl:)- returns the updatedPorkbun::Record.delete- returns the deletedPorkbun::Record.to_s- returns a string containing the BIND zone entry.
record = domain.get_record('www')
puts record.to_s
record.update(ttl: 700)
record.deleteThe gem also comes with a CLI
$ porkbun
Commands:
porkbun add RECORD --content=CONTENT --type=TYPE # Add a new record
porkbun update RECORD [--content=CONTENT] [--ttl=TTL] # Update a record (alias: up)
porkbun rm_rf DOMAIN # deletes all records for a domain. this is destructive. use with caution
porkbun rm RECORD # Delete one record for a hostname
porkbun dyndns HOSTNAME [IP] # Update a dynamic dns record. example: porkbun dyndns home.example.com
porkbun env # Print environment variables
porkbun help [COMMAND] # Describe available commands or one specific command
porkbun import FILE # Import BIND zone file
porkbun ls [DOMAIN] [ID] # List all domains or records for a domain
be sure to set the environmental variables for it to work
export PORKBUN_API_KEY = YOUR_API_KEY export PORKBUN_SECRET_API_KEY = YOUR_SECRET_API_KEY
After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.
Run the test suite with just test. To publish a release, update the version number, then run just publish. This runs the tests and then calls the supported release task, which creates a git tag, pushes git commits and the tag, and publishes the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/danielb2/porkbun-ruby.