Project

porkbun

0.0
The project is in a healthy, maintained state
Porkbun API wrapper for Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 1.5
 Project Readme

Porkbun

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

Installation

gem install porkbun

Usage

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.delete

API

Porkbun.ping

Make sure your keys are good.

Classes

Porkbun::Domain

class methods

  • all - returns an array of Porkbun::Domain objects for each domain in the account.
  • create_record(hostname, options) - returns a Porkbun::Record created from a full hostname.
  • get_record(hostname) - returns one unambiguous Porkbun::Record.
  • import(file) - returns an array of Porkbun::Record objects 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')

instance methods

Porkbun.new('domain.org') returns a Porkbun::Domain object.

  • records - returns an array of Porkbun::Record objects for the domain.
  • get_record(name) - returns one unambiguous Porkbun::Record; name can be relative or fully qualified.
  • create_record(name, options) - returns a new Porkbun::Record.
  • delete_all_records - returns an array of Porkbun::Record objects after deleting all non-NS records.
  • zone_file - returns a string that can be passed to import.
domain = Porkbun.new('domain.org')
record = domain.get_record('www')
record.update(content: '8.8.8.8')
record.delete

domain.delete_all_records

Porkbun::Record

A Porkbun::Record represents one DNS record and owns its mutations.

instance methods

  • update(content:, ttl:) - returns the updated Porkbun::Record.
  • delete - returns the deleted Porkbun::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.delete

CLI

The 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

Development

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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/danielb2/porkbun-ruby.