porkbun 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfab2dd7301e980ef4e44f2db8579b6797cf18371863b295d904ba1129720b31
4
- data.tar.gz: 18c9df86bbbf47ad1a7cf4d9c2805a63195f17ee87edb79abb95492ca82023af
3
+ metadata.gz: e1bc8af25400702d71aff036132bde0cefab611e147679bb0dc4ff31f97ade5c
4
+ data.tar.gz: 1cc22fee925bdb64995f0ea92622ef5e37ab05bd7012b6c0d325fb71a0252b3d
5
5
  SHA512:
6
- metadata.gz: 9fd355b2102b8ad2352e6e389c103877e3b4cea191d4d88420be4f6460755b30541ee67def037bed4b9f0192b5e6afa8b84bc5fd3df3e77059e37ec67ee8cd45
7
- data.tar.gz: 1f1b61ce3edb87a0d846c8f7e5089d4d02619e9bf07334c8b9da93903a424650eed89416e057199a4250a72fa88590262d354b79069b7086ca3a10bebe9d1f2d
6
+ metadata.gz: 6fbccae6ef832a475b7881596062d996fd7af233ec0147c9204d1b5485c0cf16cca271500087ead18deca66f716b18a35c6fd7842371d3f6699e3b1ddb022f2a
7
+ data.tar.gz: 27193856fbd647966b2d39186fa83b4407051fd0774c1b57a711233a14a7a580d833799a7943e2343fde1e05456173e47212572f4b87dbd752aa70f80f08ded8
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Reference: https://porkbun.com/api/json/v3/documentation
4
4
 
5
+ This is currently only a partial implementation to suit my own needs. If you
6
+ need a specific call to be implemented, let me know, or submit a PR
7
+
5
8
  ## Installation
6
9
 
7
10
  `gem install porkbun`
@@ -20,7 +23,7 @@ record = Porkbun::DNS.create(name: 'test',
20
23
 
21
24
  ## API
22
25
 
23
- ### `Porkbun::Domain.ping`
26
+ ### `Porkbun.ping`
24
27
 
25
28
  Make sure your keys are good.
26
29
 
@@ -47,11 +50,14 @@ The gem also comes with a CLI
47
50
 
48
51
  $ porkbun
49
52
  Commands:
50
- porkbun delete_all <domain> # deletes all records for a domain. this is destructive. use with caution
51
- porkbun help [COMMAND] # Describe available commands or one specific command
52
- porkbun import <file> # Import BIND zone file
53
- porkbun list # List all domains
54
- porkbun retrieve <domain> [<id>] # List all records for a domain
53
+ porkbun delete_all <domain> # deletes all records for a domain. this is destructive. use with caution
54
+ porkbun dyndns <hostname.domain> [<ip>] # Update a dynamic dns record. example: porkbun dyndns home.example.com
55
+ porkbun help [COMMAND] # Describe available commands or one specific command
56
+ porkbun import <file> # Import BIND zone file
57
+ porkbun list # List all domains
58
+ porkbun retrieve <domain> [<id>] # List all records for a domain
59
+
60
+
55
61
 
56
62
  ## Development
57
63
 
data/bin/porkbun CHANGED
@@ -47,6 +47,28 @@ class CLI < Thor
47
47
  end
48
48
  end
49
49
 
50
+ desc 'dyndns <hostname.domain> [<ip>]', 'Update a dynamic dns record. example: porkbun dyndns home.example.com'
51
+ long_desc 'If no IP is provided, the current public IP is used.'
52
+ def dyndns(hostname, ip = nil)
53
+ ip ||= HTTP.get('https://canhazip.com').to_s.chomp
54
+ domain = hostname.split('.')[-2..].join('.').chomp '.'
55
+ name = hostname.split('.')[0..-3].join('.')
56
+ records = get_all(domain)
57
+ record = records.find { |r| r.name == hostname }
58
+ if record
59
+ record.content = ip
60
+ record.name = name
61
+ puts "UPDATE #{record}"
62
+ record.save
63
+ puts record.message
64
+ else
65
+ print 'CREATE '
66
+ record = Porkbun::DNS.create(domain:, name:, type: 'A', content: ip)
67
+ puts record
68
+ puts record.message
69
+ end
70
+ end
71
+
50
72
  desc 'retrieve <domain> [<id>]', 'List all records for a domain'
51
73
  def retrieve(domain, id = '')
52
74
  records = get_all(domain, id)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Porkbun
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/porkbun.rb CHANGED
@@ -57,7 +57,16 @@ module Porkbun
57
57
  end
58
58
 
59
59
  def edit
60
- raise Error, 'need id to edit' unless @id
60
+ raise Error, 'Need ID to id record' unless id
61
+
62
+ res = Porkbun.porkbun File.join('dns/edit', domain, id), get_options
63
+ parse_response res
64
+ @id = res[:id]
65
+ self
66
+ end
67
+
68
+ def save
69
+ edit
61
70
  end
62
71
 
63
72
  def self.retrieve(domain, id = nil)
@@ -79,7 +88,6 @@ module Porkbun
79
88
  self
80
89
  end
81
90
 
82
- require 'pry'
83
91
  def to_s
84
92
  content_str = case type
85
93
  when /TXT|SPF/
@@ -95,17 +103,23 @@ module Porkbun
95
103
  end
96
104
 
97
105
  def create
106
+ res = Porkbun.porkbun File.join('dns/create', domain), get_options
107
+ parse_response res
108
+ @id = res[:id]
109
+ self
110
+ end
111
+
112
+ private
113
+
114
+ def get_options
98
115
  options = {
99
116
  name:,
100
117
  content:,
101
118
  type:,
102
119
  ttl:
103
120
  }
104
- options.merge!(prio:) if prio
105
- res = Porkbun.porkbun File.join('dns/create', domain), options
106
- parse_response res
107
- @id = res[:id]
108
- self
121
+ options.merge!(prio:) if prio and prio != '0'
122
+ options
109
123
  end
110
124
  end
111
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: porkbun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bretoi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-21 00:00:00.000000000 Z
11
+ date: 2023-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -39,7 +39,6 @@ files:
39
39
  - bin/porkbun
40
40
  - lib/porkbun.rb
41
41
  - lib/porkbun/version.rb
42
- - sig/porkbun.rbs
43
42
  homepage: https://github.com/danielb2/porkbun-ruby
44
43
  licenses: []
45
44
  metadata:
data/sig/porkbun.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Porkbun
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end