porkbun 0.2.2 → 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: aebfa2c29ddffffa9cf6d816aa5e17383cb962ee1cc51dbab02ae5df948ce8fc
4
- data.tar.gz: baa74553fa476a321ae3ec62ddc0b5eeab422d69964df7ffccc1a5a073e7a300
3
+ metadata.gz: e1bc8af25400702d71aff036132bde0cefab611e147679bb0dc4ff31f97ade5c
4
+ data.tar.gz: 1cc22fee925bdb64995f0ea92622ef5e37ab05bd7012b6c0d325fb71a0252b3d
5
5
  SHA512:
6
- metadata.gz: 320834d6fca370309e497a28900e109cf8479b3db52787703c006ada5a6f7b3abad57cd7a447cebcd4ffa64123306f1939d6175446adaa4c8e56930337ef5df2
7
- data.tar.gz: 474d25bd930004c43a1ecb3226beb1c26cce76977691d956fa182b7a8480b28b7231a74f4eac1adc0ff0d420d3383f414a94e464ad077cdccbd8725ff815b919
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.2"
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)
@@ -94,17 +103,23 @@ module Porkbun
94
103
  end
95
104
 
96
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
97
115
  options = {
98
116
  name:,
99
117
  content:,
100
118
  type:,
101
119
  ttl:
102
120
  }
103
- options.merge!(prio:) if prio
104
- res = Porkbun.porkbun File.join('dns/create', domain), options
105
- parse_response res
106
- @id = res[:id]
107
- self
121
+ options.merge!(prio:) if prio and prio != '0'
122
+ options
108
123
  end
109
124
  end
110
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.2
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