porkbun 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/README.md +29 -0
- data/Rakefile +4 -0
- data/lib/porkbun/version.rb +5 -0
- data/lib/porkbun.rb +93 -0
- data/sig/porkbun.rbs +4 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9bd13fe6078310c98baf9f2090d4ec6221815284f01876a215fb4877ab16f95d
|
4
|
+
data.tar.gz: 8f347c67ccaea31a456dcf9f59b8d8c3dc18e562c45235ff83e2e5abbaaa6cc3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51b566a607c5d51817dc841f5c8e0c19e2a7f231c4091b1b2c6616d6533d624758a1d65ebcc906006c3c026d8b9d7f2e1533d38bfd4becdb286851249f79c8c5
|
7
|
+
data.tar.gz: 44e81bffb25ee956a0b4653c692f10f834e9605d42382b8846648e3de3ba3a252aa4fc18b85a28f69899daf6798841212fd2c60a7eb283231423b59a876f4f6d
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rspec -fd
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in porkbun.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rspec", "~> 3.12", :group => :test
|
11
|
+
|
12
|
+
gem "webmock", "~> 3.19", :group => :test
|
13
|
+
|
14
|
+
gem "pry", "~> 0.14.2", :group => :test
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Porkbun
|
2
|
+
|
3
|
+
Reference: https://porkbun.com/api/json/v3/documentation
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
`gem install porkbun`
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
Porkbun.API_KEY = 'YOUR_API_KEY'
|
13
|
+
Porkbun.SECRET_KEY = 'YOUR_SECRET_KEY'
|
14
|
+
record = Porkbun::DNS.create(name: 'test',
|
15
|
+
type: 'A',
|
16
|
+
content: '1.1.1.1',
|
17
|
+
ttl: 300
|
18
|
+
)
|
19
|
+
```
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
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.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/danielb2/porkbun.
|
data/Rakefile
ADDED
data/lib/porkbun.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
require_relative 'porkbun/version'
|
5
|
+
|
6
|
+
module Porkbun
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
def self.porkbun(path, options = {})
|
10
|
+
pp path
|
11
|
+
res = HTTP.post File.join('https://porkbun.com/api/json/v3', path), json: {
|
12
|
+
secretapikey: ENV.fetch('PORKBUN_SECRET_API_KEY', nil),
|
13
|
+
apikey: ENV.fetch('PORKBUN_API_KEY', nil)
|
14
|
+
}.merge(options)
|
15
|
+
|
16
|
+
JSON.parse(res.body, symbolize_names: true)
|
17
|
+
end
|
18
|
+
|
19
|
+
class Abstract
|
20
|
+
attr_accessor :message, :status
|
21
|
+
|
22
|
+
def success?
|
23
|
+
@status == 'SUCCESS'
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_response(res)
|
27
|
+
@message = res[:message]
|
28
|
+
@status = res[:status]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Domain
|
33
|
+
def self.list_all
|
34
|
+
Porkbun.porkbun('domain/listAll')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.ping
|
39
|
+
porkbun 'ping'
|
40
|
+
end
|
41
|
+
|
42
|
+
class DNS < Abstract
|
43
|
+
attr_accessor :name, :content, :type, :ttl, :prio, :domain, :id, :notes
|
44
|
+
|
45
|
+
def initialize(options)
|
46
|
+
@name = options[:name]
|
47
|
+
@content = options[:content]
|
48
|
+
@type = options[:type]
|
49
|
+
@ttl = options[:ttl] || 600
|
50
|
+
@prio = options[:prio]
|
51
|
+
@domain = options[:domain]
|
52
|
+
@id = options[:id]
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.create(options)
|
56
|
+
record = DNS.new options
|
57
|
+
record.create
|
58
|
+
end
|
59
|
+
|
60
|
+
def edit
|
61
|
+
raise Error, 'need id to edit' unless @id
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.retrieve(domain, id = nil)
|
65
|
+
raise Error, 'need domain' unless domain
|
66
|
+
|
67
|
+
res = Porkbun.porkbun File.join('dns/retrieve', domain, id || '').chomp('/')
|
68
|
+
res[:records].map do |record|
|
69
|
+
DNS.new record.merge(domain:)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete
|
74
|
+
raise Error, 'Need ID to delete record' unless id
|
75
|
+
|
76
|
+
res = Porkbun.porkbun File.join('dns/delete', domain, id)
|
77
|
+
parse_response res
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
def create
|
82
|
+
res = Porkbun.porkbun File.join('dns/create', domain), {
|
83
|
+
name:,
|
84
|
+
content:,
|
85
|
+
type:,
|
86
|
+
ttl:
|
87
|
+
}
|
88
|
+
parse_response res
|
89
|
+
@id = res[:id]
|
90
|
+
self
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/sig/porkbun.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: porkbun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Bretoi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.1
|
27
|
+
description: Porkbun API wrapper for Ruby.
|
28
|
+
email:
|
29
|
+
- daniel@otherware.org
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/porkbun.rb
|
39
|
+
- lib/porkbun/version.rb
|
40
|
+
- sig/porkbun.rbs
|
41
|
+
homepage: https://github.com/danielb2/porkbun
|
42
|
+
licenses: []
|
43
|
+
metadata:
|
44
|
+
homepage_uri: https://github.com/danielb2/porkbun
|
45
|
+
source_code_uri: https://github.com/danielb2/porkbun
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.6.0
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.4.10
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Porkbun API wrapper for Ruby.
|
65
|
+
test_files: []
|