diff --git a/lib/cloudflare/certificates.rb b/lib/cloudflare/certificates.rb new file mode 100644 index 0000000..7096ebd --- /dev/null +++ b/lib/cloudflare/certificates.rb @@ -0,0 +1,25 @@ +require_relative 'representation' +require_relative 'paginate' + +module Cloudflare + + class Certificate < Representation + def certificate + value[:certificate] + end + end + + class Certificates < Representation + include Paginate + + def representation + Certificate + end + + def create(csr_pem, hostnames, request_type = 'origin-rsa', requested_validity = 5475) + attrs = + {csr: csr_pem, request_type: request_type, hostnames: hostnames, requested_validity: requested_validity} + represent_message(self.post(attrs)) + end + end +end diff --git a/lib/cloudflare/connection.rb b/lib/cloudflare/connection.rb index 86e9ad2..6f1cf2a 100644 --- a/lib/cloudflare/connection.rb +++ b/lib/cloudflare/connection.rb @@ -22,9 +22,11 @@ require_relative 'representation' +require_relative 'i_ps' require_relative 'zones' require_relative 'accounts' require_relative 'user' +require_relative 'certificates' module Cloudflare class Connection < Representation @@ -44,6 +46,10 @@ def authenticated(token: nil, key: nil, email: nil) self.with(headers: headers) end + + def cidrs(ipv: nil) + with(IPs, path: 'ips').cidrs(ipv: ipv) + end def zones self.with(Zones, path: 'zones') @@ -56,5 +62,9 @@ def accounts def user self.with(User, path: 'user') end + + def certificates + with(Certificates, path: 'certificates') + end end end diff --git a/lib/cloudflare/i_ps.rb b/lib/cloudflare/i_ps.rb new file mode 100644 index 0000000..4587c47 --- /dev/null +++ b/lib/cloudflare/i_ps.rb @@ -0,0 +1,13 @@ +require_relative 'representation' + +module Cloudflare + class IPs < Representation + def cidrs(ipv: nil) + if ipv + value[:"ipv#{ipv}_cidrs"] + else + value[:ipv4_cidrs].to_a + value[:ipv6_cidrs].to_a + end + end + end +end