porkbun 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aebfa2c29ddffffa9cf6d816aa5e17383cb962ee1cc51dbab02ae5df948ce8fc
4
- data.tar.gz: baa74553fa476a321ae3ec62ddc0b5eeab422d69964df7ffccc1a5a073e7a300
3
+ metadata.gz: 183c27cc342e3e3c76f2c3ca1881db37026a6424ebce500460834c88351fccac
4
+ data.tar.gz: 9ffa3f822d9d41acaf1196e797fb229e06d571167b6e5fdae5f1798e20652d9d
5
5
  SHA512:
6
- metadata.gz: 320834d6fca370309e497a28900e109cf8479b3db52787703c006ada5a6f7b3abad57cd7a447cebcd4ffa64123306f1939d6175446adaa4c8e56930337ef5df2
7
- data.tar.gz: 474d25bd930004c43a1ecb3226beb1c26cce76977691d956fa182b7a8480b28b7231a74f4eac1adc0ff0d420d3383f414a94e464ad077cdccbd8725ff815b919
6
+ metadata.gz: 00a2f94d8ab1373ebba48f7c9d4b8e9bea6f706038b9b0b8fd3918c48d5a5620800f7ab00a069d02b58a86d927df7a7532378476875cd3d16bee223f87829ca8
7
+ data.tar.gz: 92ea76964e4cee12abd438c203bff55a6933ff5f6f27a56497d952ee2fea3384fcee9f752e60ae752da80caa70559c4b39051f68b522dbc7c508508941db7608
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in porkbun.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "rake", "~> 13.0", :group => :test
9
9
 
10
10
  gem "rspec", "~> 3.12", :group => :test
11
11
 
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.1"
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.1
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
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
27
41
  description: Porkbun API wrapper for Ruby.
28
42
  email:
29
43
  - daniel@otherware.org